I trained a classifier network and I valid it on the test data set, accuracy is 90%. But I found if I invoke predict_classifier() to get the inference result, result is often wrong.
So I compare the code between predict_classifier() and validate_classifier_single. The conclusion is that letterbox_image function in predict_classifier() result in the difference.
image r = letterbox_image(im, net.w, net.h);
So, if substute this line of code with
image resized = resize_min(im, net.w);
image crop = crop_image(resized, (resized.w - net.w)/2, (resized.h - net.h)/2, net.w, net.h);
Then, the result will be correct.
I use the command
./darknet classifier valid data/TTKLightClassify.data cfg/apolloLightRecog.cfg backup/apolloLightRecog_last.weights
to validate the training result and the accuracy is high.
And I output the detail log including classify result of every single image .
For example, the inference result of xx.jpg is correct.
Then I tested a single image file by using the command
./darknet classifier predict data/TTKLightClassify.data cfg/apolloLightRecog.cfg backup/apolloLightRecog_last.weights xx.jpg
Then I found the inference result is not same as the earlier result and not correct.
Then I compare the code in predict_classifier() and validate_classifier_single(), the difference is letterbox_image.
The cfg file is
`[net]
batch=128
subdivisions=1
height=64
width=64
channels=3
momentum=0.9
decay=0.0005
hue=.1
saturation=.75
exposure=.75
angle=7
aspect=.75
learning_rate=0.03
policy=poly
power=4
max_batches=500000`
the input image size is : 28 * 64, width is 28.
I can repro the same issue.
In some cases, blobFromImage() is a better choice, which behaves similar with resize_min + crop_image
@haithink @vinjn Hi,
Feel free to do Pull Request with these changes.
What's your recommendation with these different resize operations?
Most helpful comment
In some cases,
blobFromImage()is a better choice, which behaves similar withresize_min + crop_image