【问题标题】:How do I use the model Inception.tgz in TensorFlow?如何在 TensorFlow 中使用模型 Inception.tgz?
【发布时间】:2016-09-24 11:02:10
【问题描述】:

我刚刚从 tensorflow.org http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz 下载了 inception.tgz 文件。但是,我不知道我应该在哪里提取这个。

另外,当我使用 models/image/imagenet/classify_image.py 脚本获取模型时,模型在重启后没有保存,所以我不得不通过相同的脚本再次下载它。我有时需要使用它,我没有连接到互联网,所以每次我需要分类时下载模型对我来说并不理想。我怎样才能一劳永逸地保留模型?

另外,如何使用 .tgz 初始模型?

【问题讨论】:

    标签: python tensorflow


    【解决方案1】:

    我无法对您的问题发表评论,因为我还没有足够的积分。所以让我给你一个笼统的答案。

    1. 您提到的inception-2015-12-05.tgz 文件包含您需要的两个文件:

      a) imagenet_comp_graph_label_strings.txt

      b) tensorflow_inception_graph.pb

    还有一个您不需要的许可证文件。这两个文件可让您对图像进行预测。

    1. 你提到the model was not saved after a reboot, so I had to download it again via the same script 的那部分让我很感兴趣。我从来没有遇到过这样的问题。现在试试这个:

      • 在您选择的位置创建一个文件夹。说~/Documents
      • 当您运行 python 脚本classify_image.py 时,使用--model_dir 标志将模型文件目录重定向到~/Documents。这实际上会将必要的文件下载并解压缩到指定位置,此后您可以在--model_dir 标志中使用相同的位置。

    看看这个:

    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)
    

    模型没有第二次下载。 希望这会有所帮助。

    【讨论】:

    • 谢谢!第二次下载可能是因为我忘记停用我所在的 virtualenv。但是我可以直接从存档中将两个所需的文件保存到 /tmp/imagenet 吗?
    • 是的,您可以使用 --model_dir 标志使用文件。
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      因为它保存在一个临时目录中,所以每次你关闭机器时,它都会被删除。尝试使用--model_dir 参数将文件保存到目录。

      【讨论】:

        猜你喜欢
        • 2022-07-11
        • 1970-01-01
        • 2021-08-14
        • 2018-02-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多