Simd Library Documentation.

Home | Release Notes | Download | Documentation | Issues | GitHub
Conversion functions

Functions to acceleratŠµ conversion in Synet Framework. More...

Functions

SIMD_API void SimdSynetConvert32fTo8u (const float *src, size_t batch, size_t channels, size_t height, size_t width, SimdTensorFormatType format, const float *scale, const float *shift, uint8_t *dst, SimdSynetCompatibilityType compatibility)
 Converts 32-bit float point image to 8-bit unsigned integer image. More...
 
SIMD_API void SimdSynetConvert8uTo32f (const uint8_t *src, size_t batch, size_t channels, size_t height, size_t width, SimdTensorFormatType format, const float *scale, const float *shift, float *dst, SimdSynetCompatibilityType compatibility)
 Converts 8-bit unsigned integer image to 32-bit float point image. More...
 
SIMD_API void SimdSynetSetInput (const uint8_t *src, size_t width, size_t height, size_t stride, SimdPixelFormatType srcFormat, const float *lower, const float *upper, float *dst, size_t channels, SimdTensorFormatType dstFormat)
 Sets image to the input of neural network of Synet Framework. More...
 
template<template< class > class A>
SIMD_INLINE void SynetSetInput (const View< A > &src, const float *lower, const float *upper, float *dst, size_t channels, SimdTensorFormatType format, bool isRgb=false)
 Sets image to the input of neural network of Synet Framework. More...
 

Detailed Description

Functions to acceleratŠµ conversion in Synet Framework.

Function Documentation

◆ SimdSynetConvert32fTo8u()

void SimdSynetConvert32fTo8u ( const float *  src,
size_t  batch,
size_t  channels,
size_t  height,
size_t  width,
SimdTensorFormatType  format,
const float *  scale,
const float *  shift,
uint8_t *  dst,
SimdSynetCompatibilityType  compatibility 
)

Converts 32-bit float point image to 8-bit unsigned integer image.

Note
This function is used in Synet Framework.
Parameters
[in]src- a pointer to the 32-bit float array with input image tensor.
[in]batch- a number of images in the batch of (input/output) image tensor.
[in]channels- a number of channels in the (input/output) image tensor.
[in]height- a height of (input/output) image tensor.
[in]width- a width of (input/output) image tensor.
[in]format- a format of (input/output) image tensor.
[in]scale- a pointer to the 32-bit float array with scale coefficients.
[in]shift- a pointer to the 32-bit float array with shift coefficients.
[out]dst- a pointer to the 8-bit unsigned integer array with output image tensor.
[in]compatibility- a flags of calculation compatibility.

◆ SimdSynetConvert8uTo32f()

void SimdSynetConvert8uTo32f ( const uint8_t *  src,
size_t  batch,
size_t  channels,
size_t  height,
size_t  width,
SimdTensorFormatType  format,
const float *  scale,
const float *  shift,
float *  dst,
SimdSynetCompatibilityType  compatibility 
)

Converts 8-bit unsigned integer image to 32-bit float point image.

Note
This function is used in Synet Framework.
Parameters
[in]src- a pointer to the 8-bit unsigned integer array with input image tensor.
[in]batch- a number of images in the batch of (input/output) image tensor.
[in]channels- a number of channels in the (input/output) image tensor.
[in]height- a height of (input/output) image tensor.
[in]width- a width of (input/output) image tensor.
[in]format- a format of (input/output) image tensor.
[in]scale- a pointer to the 32-bit float array with scale coefficients.
[in]shift- a pointer to the 32-bit float array with shift coefficients.
[out]dst- a pointer to the array with 32-bit float output image tensor.
[in]compatibility- a flags of calculation compatibility.

◆ SimdSynetSetInput()

void void SimdSynetSetInput ( const uint8_t *  src,
size_t  width,
size_t  height,
size_t  stride,
SimdPixelFormatType  srcFormat,
const float *  lower,
const float *  upper,
float *  dst,
size_t  channels,
SimdTensorFormatType  dstFormat 
)

Sets image to the input of neural network of Synet Framework.

Algorithm's details (example for BGRA pixel format and NCHW tensor format):

for(c = 0; c < channels; ++c)
    for(y = 0; y < height; ++y)
        for(x = 0; x < width; ++x)
            dst[(c*height + y)*width + x] = src[stride*y + width*4 + c]*(upper[c] - lower[c])/255 + lower[c];

Note that there are following relationships:

upper[c] = (1 - mean[c]) / std[c];
lower[c] = - mean[c] / std[c];

Also this algorithm assumes that channel order of output tensor is BGR. In case of RGB channel order you need to change parameter srcFormat: SimdPixelFormatBgr24 <-> SimdPixelFormatRgb24, SimdPixelFormatBgra32 <-> SimdPixelFormatRgba32. Note that real format of pixel data of input image is not need to change.

Note
This function has a C++ wrappers: Simd::SynetSetInput(const View & src, const float * lower, const float * upper, float * dst, size_t channels, SimdTensorFormatType format, bool isRgb = false).
Parameters
[in]src- a pointer to pixels data of input image.
[in]width- a width of input image and output image tensor.
[in]height- a height of input image and output image tensor.
[in]stride- a row size of input image.
[in]srcFormat- a pixel format of input image. There are supported following pixel formats: SimdPixelFormatGray8, SimdPixelFormatBgr24, SimdPixelFormatBgra32, SimdPixelFormatRgb24, SimdPixelFormatRgba32.
[in]lower- a pointer to the array with lower bound of values of the output tensor. The size of the array have to correspond number of channels in the output image tensor.
[in]upper- a pointer to the array with upper bound of values of the output tensor. The size of the array have to correspond number of channels in the output image tensor.
[out]dst- a pointer to the output 32-bit float image tensor.
[in]channels- a number of channels in the output image tensor. It can be 1 or 3.
[in]dstFormat- a format of output image tensor. There are supported following tensor formats: SimdTensorFormatNchw, SimdTensorFormatNhwc.

◆ SynetSetInput()

void SynetSetInput ( const View< A > &  src,
const float *  lower,
const float *  upper,
float *  dst,
size_t  channels,
SimdTensorFormatType  format,
bool  isRgb = false 
)

Sets image to the input of neural network of Synet Framework.

Algorithm's details (example for BGRA pixel format and NCHW tensor format):

for(c = 0; c < channels; ++c)
    for(y = 0; y < src.height; ++y)
        for(x = 0; x < src.width; ++x)
            dst[(c*height + y)*width + x] = src.data[src.stride*y + src.width*4 + c]*(upper[c] - lower[c])/255 + lower[c];

Note that there are following relationships:

upper[c] = (1 - mean[c]) / std[c];
lower[c] = - mean[c] / std[c];
Note
This function is a C++ wrapper for function SimdSynetSetInput.
Parameters
[in]src- an input image.There are supported following image formats: View<A>::Gray8, View<A>::Bgr24, View<A>::Bgra32, View<A>::Rgb24, View<A>::Rgba32.
[in]lower- a pointer to the array with lower bound of values of the output tensor. The size of the array have to correspond number of channels in the output image tensor.
[in]upper- a pointer to the array with upper bound of values of the output tensor. The size of the array have to correspond number of channels in the output image tensor.
[out]dst- a pointer to the output 32-bit float image tensor.
[in]channels- a number of channels in the output image tensor. It can be 1 or 3.
[in]format- a format of output image tensor. There are supported following tensor formats: SimdTensorFormatNchw, SimdTensorFormatNhwc.
[in]isRgb- is channel order of output tensor is RGB or BGR. Its default value is false.