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.)
Inception-v4 is a convolutional neural network architecture that builds on previous iterations of the Inception family by simplifying the architecture and using more inception modules than Inception-v3. Source: Inception-v4, Inception-ResNet and the Impact of Residual Connections on Learning.
The default input image size of Inception-v3 is 299×299; however, the image size in the dataset was 224×224.
I'm working through the same thing currently.
Try to add :0
to the end of your bottleneck_tensor_name
and your resized_input_tensor_name
.
If you'll notice in retrain.py
, Google also uses this :0
nomenclature.
My suspicion is that, for you, InceptionV4/Logits/Logits/MatMul
is just an operation, which you're not trying to get for this script, while InceptionV4/Logits/Logits/MatMul:0
is the first tensor instantiated from that operation, which you are trying to get for this script.
Add this modification to your script then InputImage is viewed as a Tensor:
resized_input_tensor_name = 'InputImage:0'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With