I am trying to adapt the example retrain script ( https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/image_retraining/retrain.py ) to use the Inception V4 model.
The script already supports the retraining of Inception V3 (2015) as well as different versions of Mobilenets.
What I've done so far:
Since the script uses protobuf (.pb) files and not checkpoints (.ckpt), I downloaded the inception_v4.pb from here: https://deepdetect.com/models/tf/inception_v4.pb. As far as I understand, one could also have loaded the checkpoint and used the freeze graph tool to obtain the same file.
Then, I viewed the graph in tensorboard using the tensorflow python tool import_pb_to_tensorboard.py which can be found in the tensorflow github repository.
From there (correct me if I am not wrong) I found that the resized_input_tensor_name is called InputImage whereas the bottleneck_tensor_name is InceptionV4/Logits/Logits/MatMul with bottleneck_tensor_size is 1001.
Having this information I tried to adapt the create_model_info(architecture) function of the retrain script by adding:
elif architecture == 'inception_v4':
data_url = 'http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz' #this won't make any difference
bottleneck_tensor_name = 'InceptionV4/Logits/Logits/MatMul'
bottleneck_tensor_size = 1001
input_width = 299
input_height = 299
input_depth = 3
resized_input_tensor_name = 'InputImage'
model_file_name = 'inception_v4.pb'
input_mean = 128
input_std = 128
I run the script using the following command:
python retrain.py --architecture=inception_v4 --bottleneck_dir=test2/bottlenecks --model_dir=inception_v4 --summaries_dir=test2/summaries/basic --output_graph=test2/graph_flowers.pb --output_labels=test2/labels_flowers.txt --image_dir=datasets/flowers/flower_photos --how_many_training_steps 100
and I am getting the following error:
File "retrain.py", line 373, in create_bottleneck_file str(e))) RuntimeError: Error during processing file datasets/flowers/flower_photos/tulips/4546299243_23cd58eb43.jpg (Cannot interpret feed_dict key as Tensor: Can not convert a Operation into a Tensor.)
data_url = 'http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz'does make a difference,retrain.pywould interpret the filename of your model toinception-2015-12-05.tgz, so it would still use inception_v3 rather than inception_v4. - Jay Wong