简体   繁体   English

如何在TensorFlow中使用模型Inception.tgz?

[英]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 . 我刚刚从tensorflow.org下载了inception.tgz文件,网址为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. 此外,当我使用models / image / imagenet / classify_image.py脚本获取模型时,重新启动后模型未保存,因此我必须通过相同的脚本再次下载它。 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? 另外,我如何使用.tgz初始模型?

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: 您提到的inception-2015-12-05.tgz文件包含两个您需要的文件:

    a) imagenet_comp_graph_label_strings.txt a)imagenet_comp_graph_label_strings.txt

    b) tensorflow_inception_graph.pb 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. 你提到the model was not saved after a reboot, so I had to download it again via the same script的部分在the model was not saved after a reboot, so I had to download it again via the same script引起我的兴趣。 I have never come across such an issue. 我从未遇到过这样的问题。 Try this now: 立即尝试:

    • Create a folder in a location of your choice. 在您选择的位置创建一个文件夹。 Say ~/Documents . ~/Documents
    • When you run the python script classify_image.py use the --model_dir flag to redirect the model file directory to ~/Documents . 运行python脚本classify_image.py使用--model_dir标志将模型文件目录重定向到~/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. 这将基本上下载并提取必要的文件到指定的位置,从那以后你可以在--model_dir标志中使用相同的位置。

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. 希望这可以帮助。

默认情况下,映像模型会下载到/ tmp / imagenet,但您可以通过将--model_dir命令行参数传递给--model_dir来设置自己的文件夹: https//github.com/tensorflow/tensorflow/blob/master /tensorflow/models/image/imagenet/classify_image.py#L56

because it is saved in a temp directory, everytime you shut the machine down, it is removed. 因为它保存在临时目录中,所以每次关闭机器时都会将其删除。 try saving the file to a directory using the --model_dir parameter. 尝试使用--model_dir参数将文件保存到目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM