Woppa Woppa - 2 months ago 79
Python Question

How do I use the model Inception.tgz in TensorFlow?

I just downloaded the inception.tgz file from tensorflow.org at http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz. But, I do not know where I should extract this.

Also, when I used the models/image/imagenet/classify_image.py script to get the model, the model was not saved after a reboot, so I had to download it again via the same script. I need to use it at times I am not connected to the Internet, so downloading the model everytime I need to classify is not ideal for me. How can I persist the model once and for all?

Also, how can I use the .tgz inception model?

Answer

I cannot make a comment to your Question since I do not have enough credits yet. So let me give you a generic answer.

  1. The inception-2015-12-05.tgz file you mentioned contains two files which you require:

    a) imagenet_comp_graph_label_strings.txt

    b) tensorflow_inception_graph.pb

There is a license file that you won't require as well. These two files will let you make predictions on images.

  1. The part where you mentioned the model was not saved after a reboot, so I had to download it again via the same script intrigues me. I have never come across such an issue. Try this now:

    • Create a folder in a location of your choice. Say ~/Documents.
    • When you run the python script classify_image.py use the --model_dir flag to redirect the model file directory to ~/Documents. This will essentially download and extract the necessary files to the specified location and you can use the same location in --model_dir flag ever since.

Take a look at this:

Aruns-MacBook-Pro:imagenet arundas$ python classify_image.py --model_dir ~/Documents/
>> Downloading inception-2015-12-05.tgz 100.0%
Succesfully downloaded inception-2015-12-05.tgz 88931400 bytes.
W tensorflow/core/framework/op_def_util.cc:332] Op BatchNormWithGlobalNormalization is deprecated. It will cease to work in GraphDef version 9. Use tf.nn.batch_normalization().
giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca (score = 0.89233)
indri, indris, Indri indri, Indri brevicaudatus (score = 0.00859)
lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens (score = 0.00264)
custard apple (score = 0.00141)
earthstar (score = 0.00107)

Aruns-MacBook-Pro:imagenet arundas$ python classify_image.py --model_dir ~/Documents/
W tensorflow/core/framework/op_def_util.cc:332] Op BatchNormWithGlobalNormalization is deprecated. It will cease to work in GraphDef version 9. Use tf.nn.batch_normalization().
giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca (score = 0.89233)
indri, indris, Indri indri, Indri brevicaudatus (score = 0.00859)
lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens (score = 0.00264)
custard apple (score = 0.00141)
earthstar (score = 0.00107)

The model was not downloaded the second time. Hope this helps.

Comments