models icon indicating copy to clipboard operation
models copied to clipboard

What is the difference between two tensorflow inception models 'inception_v3_2016_08_28.tar.gz' and 'classify_image_graph_def.pb'

Open ghost opened this issue 9 years ago • 33 comments

Tensorflow version 1.0 Python 2.7 My dataset has got two classes. For transfer learning i tried two inceptionV3 models.

  1. inception_v3_2016_08_28.tar.gz
  2. classify_image_graph_def.pb - comes along with tensorflow image_retraining code.

But the results i am getting are totally different. Where the second models performs way better than the first. Is it expected ? First model gives accuracy of 57% where the second model gives 80% accuracy.

The first model is checkpoint file. For transfer learning, i have converted the checkpoint file to protobuf file. Then the python code retrain.py which comes along with tensorflow is used to do the retraining. Following code is used to convert checkpoint file to a protobuf file inceptionv3.pb.

checkpoint_file = '../check_points/inception_v3.ckpt'
decode_jpeg_data = tf.placeholder(tf.string)
decode_jpeg = tf.image.decode_jpeg(decode_jpeg_data, channels=3, dct_method="INTEGER_ACCURATE")
if decode_jpeg.dtype != tf.float32:
  decode_jpeg = tf.image.convert_image_dtype(decode_jpeg, dtype=tf.float32)
image_ = tf.expand_dims(decode_jpeg, 0)
image = tf.image.resize_bicubic(image_, [299, 299], align_corners=True)
scaled_input_tensor = tf.scalar_mul((1.0/255), image)
scaled_input_tensor = tf.subtract(scaled_input_tensor, 0.5)
scaled_input_tensor = tf.multiply(scaled_input_tensor, 2.0)

# loading the inception graph
arg_scope = inception_v3_arg_scope()
with slim.arg_scope(arg_scope):
  logits, end_points = inception_v3(inputs=scaled_input_tensor, is_training=False, num_classes=1001)
saver = tf.train.Saver()
sess = tf.Session()
saver.restore(sess, checkpoint_file)
with gfile.FastGFile('./models/inceptionv3.pb', 'wb') as f:
    f.write(output_graph_def.SerializeToString())

Am I missing something while converting checkpoint files to graph ? Can i use the retrain.py code to do the tranfer learning of the graph obtained using above code?

Also asked the same question in stackoverflow as well, but no luck http://stackoverflow.com/questions/43246387/what-is-the-difference-between-two-tensorflow-inception-models-inception-v3-201

ghost avatar Apr 07 '17 10:04 ghost

Re-assigning to the slim/inception maintainers: @sguada @nathansilberman

nealwu avatar Apr 08 '17 00:04 nealwu

@sguada @nathansilberman any update on this issue

ghost avatar Apr 20 '17 05:04 ghost

Hi, I too have the exact same problem. I tried with other models (resnet, inception-resnet) but are all ~50% of accuracy whereas I get ~90% with classify_image_graph_def.pb.

freud14 avatar Apr 23 '17 18:04 freud14

Any news on that?

freud14 avatar May 05 '17 12:05 freud14

@nealwu @sguada @nathansilberman , guys any update on this. It will be of great help at-least if you mention the difference between the two models.

ghost avatar Jun 07 '17 11:06 ghost

@nirmaljith @freud14 What was the code you used for retraining? Do you mean this retrain.py? If so, have you tried changing model-specific parameters such as BOTTLENECK_TENSOR_NAME?

See also: I just filed an issue on the main tensorflow repo about the two models. (As you can see from that post, I'm still confused with the differences, but I hope it helps.)

korrawat avatar Jul 03 '17 03:07 korrawat

Do you mean this retrain.py? If so, have you tried changing model-specific parameters such as BOTTLENECK_TENSOR_NAME?

Yes, this retrain. Yes, I've changed model-specific parameters.

freud14 avatar Jul 03 '17 13:07 freud14

I have the same issue about this 2 models. When I trained my own datasets with retrain.py(version 2015.12 of inception v3), my final accuracy was about 88%, then with the checkpoint inception v3 (version 2016.8), accuracy went down to 70%. I noticed that in the checkpoint version, two scopes are excluded : InceptionV3/AuxLogits, InceptionV3/Logits, then we retrained these two scopes. Though in the retrain.py, it seems like to just retrain the bottleneck(ArgPool) layer...

chenyuZha avatar Jul 06 '17 21:07 chenyuZha

I noticed that in the checkpoint version, two scopes are excluded : InceptionV3/AuxLogits, InceptionV3/Logits, then we retrained these two scopes.

Do you mean that you got 70% of accuracy when retraining these two scopes or that you got the initial 88% as with the version 2015.12 of inception v3?

freud14 avatar Jul 06 '17 22:07 freud14

I have been experiencing strange issues with inception_v3_2016_08_28.tar.gz as well. I was performing simple transfer learning on a flowers dataset to train a new output layer. I was able to achieve 99% accuracy on the training set. However, when I would restore my model and it was evaluated on the random batches of the training set, the accuracy dropped to about 70%. What I noticed was that when I set is_training back to True when I was performing inference, the accuracy jumped back up to 99% for training and around 95% for the test set.

I made modifications to tensorflow/contrib/slim/python/slim/nets/inception_v3.py to see if removing the parts that use is_training changed anything. I found that removing the dropout layer did not decrease the accuracy during inference, but setting is_training to False for all calls to layers_lib.batch_norm during inference caused the accuracy to drop significantly to between 70%~80%.

I guess to make things more concise, the model performs significantly better, after training has stopped, when is_training=True ONLY for the batch norm layers which makes no sense. Whether is_training was true or false for the dropout layer made no difference in the accuracy on both the training and test sets when not training, which also makes no sense.

Not sure if this should be a separate issue because the problems I am having dont't seem to be related to the checkpoint file but more the inceptionV3 slim implementation in the file i referenced above.

oneTimePad avatar Jul 19 '17 00:07 oneTimePad

How do you find the three tensors defined for version 2015.12 in version 2016? I have difficulty in finding and loading the correct tensors.

JasonHJG avatar Jul 20 '17 01:07 JasonHJG

@JasonHJG Try the following:

korrawat avatar Jul 20 '17 02:07 korrawat

@freud14 The 70% accuracy is obtained with the checkpoint version of InceptionV3, I didn't change the option --checkpoint_exclude_scopes of file train_image_classifier.py , so by default, two scopes are excluded: InceptionV3/AuxLogits, InceptionV3/Logits and we do fine-tuning with 2 scopes. While the 88% is obtained with retrain.py, where we calculate the bottlenecks_values for new datasets, then these values are considered like the feature extractors for the classification layer.

chenyuZha avatar Jul 20 '17 11:07 chenyuZha

@chenyuZha It seems normal. In the case where you are using train_image_classifier.py, it retrains the whole model so it will take a longer time to get the same accuracy as retrain.py. Try to convert the 2016 checkpoint into a .pb file and then to retrain it with retrain.py.

freud14 avatar Jul 20 '17 12:07 freud14

@freud14 I'm not sure if retrain.py will work with 2016 checkpoint even though I convert it into a .pb file, since the checkpoint version has modified the name of nodes. So, we may not find the same input_tensor and final_result , even the layer which store the bottleneck values. Also, the 2016 checkpoint took longer time to train than version 2015 because the weights are also recalculated ( not from beginning but just 2 scopes InceptionV3/AuxLogits,InceptionV3/Logits in my opinion ), so normally these weights should adapt well to your own datasets, and the accuracy should be higher than version 2015, that's why I'm confused.

chenyuZha avatar Jul 20 '17 14:07 chenyuZha

I'm not sure if retrain.py will work with 2016 checkpoint even though I convert it into a .pb file, since the checkpoint version has modified the name of nodes. So, we may not find the same input_tensor and final_result , even the layer which store the bottleneck values.

Yeah, you have to change the values of the constants for it to work. Here are the scripts I used in my case.

Also, the 2016 checkpoint took longer time to train than version 2015 because the weights are also recalculated ( not from beginning but just 2 scopes InceptionV3/AuxLogits,InceptionV3/Logits in my opinion ), so normally these weights should adapt well to your own datasets, and the accuracy should be higher than version 2015, that's why I'm confused.

The script train_image_classifier.py takes your checkpoint and initializes your model with it. It removes the last layers (InceptionV3/AuxLogits,InceptionV3/Logits; dunno what really is InceptionV3/AuxLogits) and replace them with new layers with the number of classes you specified. These new layers are initialized randomly as in retrain.py. Then, all the weights of your new model are retrain. So, instead of just retraining the last layers, train_image_classifier.py retrains the whole model. To get a better accuracy with this model, you would need to retrain it for much much longer than with retrain.py since you have to forward-backward propagate through the whole network for each image.

freud14 avatar Jul 20 '17 15:07 freud14

Anyway, I suspect that inception-v3-2016 was not trained as much as the 2015 model.

freud14 avatar Jul 20 '17 15:07 freud14

@freud14 Thanks for your file and explication. So I see that you change the BOTTLENECK_TENSOR_NAME to the 2016 checkpoint version. So in this case the bottlenecks values are calculated just once and then you can use it to train many times as you can to save time. I wonder that the bottlenecks values are not the same with 2015 version for the same datasets..? So how much accuracy do you get ?

chenyuZha avatar Jul 20 '17 16:07 chenyuZha

That's my problem. I get ~90% for the 2015 version and ~50% for 2016 version.

freud14 avatar Jul 20 '17 16:07 freud14

Alright, after reading @oneTimePad's comment (which I actually didn't understand completely), I decided to check whether the is_training boolean was set to true in my code or not and it was set to true. So I put it to false and did the training and testing again and now I get similar results as with the 2015 model. It must have been something to do with the moving average but I don't understand really what.

Anyway, I will try the other models (resnet, resnet-inception and other versions of inception) soon to see if it was really only that (at least for me).

freud14 avatar Jul 21 '17 04:07 freud14