cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
401 Views
Registered: ‎12-04-2019

Vitis AI - advanced API - dpuGetOutputTensor()

Jump to solution

hi,

I'm working on image to image deep learning model.

Using DPU-TRD application ,i found the function that inputs an image to resnet50 architecture.

I am using Residual Dense Network architecture and using the same input image function . the model takes 40x40x3 image and outputs 80x80x3 image and after compiling with VAI_C, the output tensor is of size 80x80x3.

now my doubt is whether the output tensor represents the image or do i need to write an inverse function as that of input image function.

 

input image function:

int dpuSetInputImageWithScale(DPUTask *task, const char* nodeName, const cv::Mat &image, float *mean, float scale, int idx)
{
    int value;
    int8_t *inputAddr;
    unsigned char *resized_data;
    cv::Mat newImage;
    float scaleFix;
    int height, width, channel;

    height = dpuGetInputTensorHeight(task, nodeName, idx);
    width = dpuGetInputTensorWidth(task, nodeName, idx);
    channel = dpuGetInputTensorChannel(task, nodeName, idx);

    if (height == image.rows && width == image.cols) {
        newImage = image;
    } else {
        newImage = cv::Mat (height, width, CV_8SC3,
                    (void*)dpuGetInputTensorAddress(task, nodeName, idx));
        cv::resize(image, newImage, newImage.size(), 0, 0, cv::INTER_LINEAR);
    }
    resized_data = newImage.data;

    inputAddr = dpuGetInputTensorAddress(task, nodeName, idx);
    scaleFix = dpuGetInputTensorScale(task, nodeName, idx);

    scaleFix = scaleFix*scale;

    if (newImage.channels() == 1) {
        for (int idx_h=0; idx_h<height; idx_h++) {
            for (int idx_w=0; idx_w<width; idx_w++) {
                for (int idx_c=0; idx_c<channel; idx_c++) {
                    value = *(resized_data+idx_h*width*channel+idx_w*channel+idx_c);
                    value = (int)((value - *(mean+idx_c)) * scaleFix);
                    inputAddr[idx_h*newImage.cols+idx_w] = (char)value;
                }
            }
        }
    } else {
#ifdef USE_NEON_OPT
        dpuProcessNormalizion(inputAddr, newImage.data, newImage.rows, newImage.cols, mean, scaleFix, newImage.step1());
#else
        for (int idx_h=0; idx_h<newImage.rows; idx_h++) {
            for (int idx_w=0; idx_w<newImage.cols; idx_w++) {
                for (int idx_c=0; idx_c<3; idx_c++) {
                    value = (int)((newImage.at<Vec3b>(idx_h, idx_w)[idx_c] - mean[idx_c]) * scaleFix);
                    inputAddr[idx_h*newImage.cols*3+idx_w*3+idx_c] = (char)value;
                }
            }
        }
#endif
    }

    return N2CUBE_SUCCESS;
}

Any sort of suggestions are welcome!    

0 Kudos
Reply
1 Solution

Accepted Solutions
325 Views
Registered: ‎12-04-2019

the output tensor returned an normalized image in RGB order

View solution in original post

0 Kudos
Reply
1 Reply
326 Views
Registered: ‎12-04-2019

the output tensor returned an normalized image in RGB order

View solution in original post

0 Kudos
Reply