8
votes

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.)

2
data_url = 'http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz' does make a difference, retrain.py would interpret the filename of your model to inception-2015-12-05.tgz, so it would still use inception_v3 rather than inception_v4. - Jay Wong
the download link is for inception v3, you need to find the download link for inception v4. - Infinite Loops

2 Answers

5
votes

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.

1
votes

Add this modification to your script then InputImage is viewed as a Tensor:

resized_input_tensor_name = 'InputImage:0'