tensorflow / models

Models and examples built with TensorFlow
Other
77.21k stars 45.75k forks source link

VGG Inference not producing the same accuracy #8645

Open HossamAmer12 opened 4 years ago

HossamAmer12 commented 4 years ago

I converted the checkpoint of VGG16 and VGG19 checkpoints into pb files. Afterward, I ran inference using the vgg_preprocessing on ORG imageNet images. The top-1 accuracy results do not match the given table by around (2-5%)

Can you please advise? Am I missing something when running inference for VGG? An example of running inference on VGG for a given input image would be appreciated.

PS: Please note that I also used the rest of the DNNs and they are fine.

HossamAmer12 commented 4 years ago

I would like to follow up on my issue - Could you please let me know if anyone can help?

shaterian commented 4 years ago

Hi All, I work with Hossam on the same project, I just want to add some information about the issue related to vgg16 and vgg19

  1. We are using the model from the following link https://github.com/tensorflow/models/tree/master/research/slim

  2. Please note that I use vgg_preprocessing to input the picture, the code that we use to prepare the image and send to the network is as follows img_size = 224
    image_data = tf.read_file(current_jpeg_image) image_data = tf.image.decode_jpeg(image_data, channels=3) image_data = vgg_preprocessing.preprocess_image(image_data, img_size, img_size, is_training=False)

  3. For converting the checkpoints to frozen graphs we first exported the graph using export_inference_graph.py form the aforementioned link and then we used

    python3-tf export_inference_graph.py --python export_inference_graph.py --model_name=vgg_16 --output_file=/tmp/ vgg_16_graph.pb freeze_graph to freeze the graph. The input arguments for freeze_graph for freezing Vgg model is as follows Python freeze_graph.py --input_graph=/tmp/vgg_16_inf_graph.pb --input_checkpoint=/tmp/checkpoints/Vgg_16.ckpt --input_binary=true --output_graph=/tmp/vgg_16.pb. --output_node_names=vgg_16/fc8/squeezed --labels_offset=1 We used both cased with --labels_offset=1 and without it but in either cased we got the same results as the table.

  4. We are using tf version 1.4

  5. Our results in terms of top1 and top5 accuracy are as follows top1: 64.588 Top5: 86.196

It worth mentioning that the last tensor in the model is vgg_16/fc8/squeezed and its shape is 1000 but this does not give us the prediction vector because of that we add a tf.nn.softmax after vgg_16/fc8/squeezed and got the predictions from this new tensor.

Could you please advise on what is missing to generate the accuracy results given by TF table? Am I using the wrong final tensor?

PS: It is worth noting that I followed the same procedure for all other models and the produced accuracy results were matching the table.

HossamAmer12 commented 4 years ago

Any updates on this issue?