frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Some problems with half float in ncGraphQueueInferenceWithFifoElem()

I use opencv resize a pic, then use a function 'float2half' convert float to half , when I use the processed tensor as input in ncGraphQueueInferenceWithFifoElem(), error occur 'ncFifoWriteElem:2570 input tensor length (540000) doesn't match expected value (1080000)'.
Give some help and advice pls and thanks!
The code as follows.

Mat preprocessed_image_mat;
preprocess_image(inputMat,preprocessed_image_mat);

//three values for each pixel in the image.
float_t tensor32[3];
unsigned short tensor16[NETWORK_IMAGE_HEIGHT* NETWORK_IMAGE_WIDTH* 3];

uint8_t* image_data_ptr = (uint8_t*)preprocessed_image_mat.data;
int chan = preprocessed_image_mat.channels();

int tensor_index = 0;
for (int row = 0; row < preprocessed_image_mat.rows; row++) {
    for (int col = 0; col < preprocessed_image_mat.cols; col++) {

        int pixel_start_index = row * (preprocessed_image_mat.cols + 0) * chan + col * chan; // TODO: don't hard code

        // assuming the image is in BGR format here
        uint8_t blue = image_data_ptr[pixel_start_index + 0];
        uint8_t green = image_data_ptr[pixel_start_index + 1];
        uint8_t red = image_data_ptr[pixel_start_index + 2];

        tensor32[0] = (float_t)blue;
        tensor32[1] = (float_t)green;
        tensor32[2] = (float_t)red;

        tensor16[tensor_index++] =  float2half(*((unsigned*)(&(tensor32[0]))));
        tensor16[tensor_index++] =  float2half(*((unsigned*)(&(tensor32[1]))));
        tensor16[tensor_index++] =  float2half(*((unsigned*)(&(tensor32[2]))));
  }
}      

unsigned int inputTensorLength = NETWORK_IMAGE_HEIGHT* NETWORK_IMAGE_WIDTH* 3 * sizeof(unsigned short);
// queue the inference to start, when its done the result will be placed on the output fifo             
retCode = ncGraphQueueInferenceWithFifoElem(graphHandlePtr, inFifoHandlePtr, outFifoHandlePtr, tensor16, &inputTensorLength, NULL);

Comments

Sign In or Register to comment.