dmlc / dmlc/mxnet-model-gallery

Inception-v3, I use C++ to achieve preprocess, but all predict false

Open
#14 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
266
Forks
71
PR merge metrics
No merged PRs in 30d

Description

My code as follows:

> 122 cv::Mat im_ori = cv::imread(image_file, 1);
> 123 /*
> 124 \* preprocess image as Inception_v3 required
> 125 \* crop -> resize -> normlize (-mean)/std
> 126 _/
> 127 int short_edge;
> 128 if(im_ori.rows > im_ori.cols)
> 129 {
> 130 short_edge = im_ori.cols;
> 131 }
> 132 else
> 133 {
> 134 short_edge = im_ori.rows;
> 135 }
> 136 //printf("image size, row = %d, col = %d, short_edge = %d\n", im_ori.rows, im_ori.cols, short_edge);
> 137 int yMin = (im_ori.rows - short_edge) / 2;
> 138 int xMin = (im_ori.cols - short_edge) / 2;
> 139 int xMax = xMin + short_edge;
> 140 int yMax = yMin + short_edge;
> 141 cv::Mat croppedImg;
> 142 im_ori(cv::Rect(xMin,yMin,xMax,yMax)).copyTo(croppedImg);
> 143 //cv::imwrite("ori.jpg", im_ori);
> 144 //cv::imwrite("crop.jpg", croppedImg);
> 145
> 146 cv::Mat im;
> 147 resize(croppedImg, im, resize_size);
> 148 //cv::imwrite("resize.jpg", im);
> 149 int size = im.rows \* im.cols;
> 150 mx_float_ ptr_image_r = image_data;
> 151 for(int i = 0; i < im.rows; i++)
> 152 {
> 153 uchar\* data = im.ptr(i);
> 154 for(int j = 0; j < im.cols; j++)
> 155 {
> 156 mx_float r = (data[j] \* 256 - 128) / 128.0;
> 157 *ptr_image_r++ = r;
> 158 }
> 159 }

I read preprocessing.py, it first crop, then resize, at last normalization.

Are my codes wrong?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by comparing the posted C++ preprocessing code with preprocessing.py, focusing on the crop, resize, and normalization steps for Inception-v3. Check the resulting image data and prediction behavior against the Python preprocessing path; done means identifying whether the C++ preprocessing differs in a way that explains the false predictions.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-vision, machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.