googlecodelabs / tensorflow-for-poets-2

Apache License 2.0
508 stars 463 forks source link

Highly incorrect predictions by any architecture retrained on any new classes of images #64

Closed sumanth-culli closed 6 years ago

sumanth-culli commented 6 years ago

I'm using this tfhub script for retraining on flower images available here. My terminal output after retraining is

INFO:tensorflow:Restoring parameters from /tmp/_retrain_checkpoint
INFO:tensorflow:Final test accuracy = 92.5% (N=362)
INFO:tensorflow:Save final result to : tf_files/retrained_graph.pb

So, 92.5% accuracy with Inception V3 and the URL is
https://tfhub.dev/google/imagenet/inception_v3/feature_vector/1.
But when I'm predicting the image with label_image script available here:

python -m scripts.label_image \
    --graph=tf_files/retrained_graph.pb  \
    --image=tf_files/flower_photos/roses/568715474_bdb64ccc32.jpg \
    --input_height=299 \
    --input_width=299 \
    --input_layer='Placeholder' 

My output is

Evaluation time (1-image): 3.639s         
daisy (score=0.54625)  
tulips (score=0.18089)  
roses (score=0.17955)  
dandelion (score=0.06436)  
sunflowers (score=0.02894)  

For a perfect rose, the generated .pb model is predicting as daisy. This is happening for many images in the flower dataset. I've observed the misprediction for another dataset as well. There's another retraining script by Google Codelabs here. When I'm using the same flower dataset for retraining using this script, my terminal output is

INFO:tensorflow:Final test accuracy = 86.3% (N=4006)
INFO:tensorflow:Froze 2 variables.
Converted 2 variables to const ops.

So, 86.3% (92.5% earlier) accuracy with Inception V3 and the label_image script output is:

Evaluation time (1-image): 1.857s
roses (score=0.99969)
tulips (score=0.00030)
sunflowers (score=0.00001)
daisy (score=0.00000)
dandelion (score=0.00000)

The script at Google Codelabs is also predicting correctly that too with very high confidence. So, what's the difference between these two scripts and why is the 1st script predicting the images incorrectly despite showing very high final test accuracy in the teminal output?

sumanth-culli commented 6 years ago

The discussion is here.