cathy-kim / Pelee-TensorRT

Pelee(NeurIPS'18)-TensorRT Implementation (Caffe Parser)
86 stars 29 forks source link

What should I do if I want to test with BATCH_SIZE=n #12

Closed nvnnghia closed 9 months ago

nvnnghia commented 5 years ago

First of all, thanks for sharing awesome project. your project help me a lot. In the main.cpp I saw that there is BACH_SIZE parameter and this parameter is set to 1. I wonder can I do inference for 2 or 3 images at the same time? If that is possible, which parts should I change to do make it working?

Thanks

cathy-kim commented 5 years ago

@nvnnghia Hi.

At first, you should change main.cpp and change BATCH_SIZE to the number you want. After, you should edit https://github.com/ginn24/Pelee-TensorRT/blob/master/model/pelee/pelee_deploy_iplugin.prototxt, input shape's batch_size to the number.

If you encounter a new error after these actions, let me know it.

nvnnghia commented 5 years ago

Hi @ginn24 Thanks for your reply. Basically, I am trying to do inference for 2 images (original frame and flipped frame). So I set batch_size=2 in main and pelee_deploy_iplugin.prototxt, After the changes, It only do detection for the original frame. I guess there is something wrong in my code. I change main.cpp like this: https://gist.github.com/nvnnghia/5ccd29ea8198d241f98211638e13f97d

In short, the loadImg function look like this: ` void loadImg( cv::Mat &input1, cv::Mat &input2, int re_width, int re_height, float *data_unifrom,const float3 mean,const float scale ) {

int i;
int j;
int line_offset;
int offset_g;
int offset_r;
cv::Mat dst1;
cv::Mat dst2;
unsigned char *line1 = NULL;
unsigned char *line2 = NULL;
float *unifrom_data = data_unifrom;

cv::resize( input1, dst1, cv::Size( re_width, re_height ), (0.0), (0.0), cv::INTER_LINEAR );
cv::resize( input2, dst2, cv::Size( re_width, re_height ), (0.0), (0.0), cv::INTER_LINEAR );
offset_g = re_width * re_height;
offset_r = re_width * re_height * 2;
for( i = 0; i < re_height; ++i )
{
    line1 = dst1.ptr< unsigned char >( i );
    line2 = dst2.ptr< unsigned char >( i );
    line_offset = i * re_width;
    for( j = 0; j < re_width; ++j )
    {
        //first image
        // b
        unifrom_data[ line_offset + j  ] = (( float )(line1[ j * 3 ] - mean.x) * scale);
        // g
        unifrom_data[ offset_g + line_offset + j ] = (( float )(line1[ j * 3 + 1 ] - mean.y) * scale);
        // r
        unifrom_data[ offset_r + line_offset + j ] = (( float )(line1[ j * 3 + 2 ] - mean.z) * scale);

        //second image
        // b
        unifrom_data[ line_offset + j  + re_width * re_height * 3] = (( float )(line2[ j * 3 ] - mean.x) * scale);
        // g
        unifrom_data[ offset_g + line_offset + j + re_width * re_height * 3] = (( float )(line2[ j * 3 + 1 ] - mean.y) * scale);
        // r
        unifrom_data[ offset_r + line_offset + j + re_width * re_height * 3] = (( float )(line2[ j * 3 + 2 ] - mean.z) * scale);
    }
}

}`

Thanks for your help.