【问题标题】:Applying Inception but get the Attribute Error:应用 Inception 但得到属性错误:
【发布时间】:2021-04-09 09:30:15
【问题描述】:

我在这里尝试运行 Inception 方法,但随后收到错误消息 ---

我的代码如下---

from IPython.display import Image, display
Image('images/07_inception_flowchart.png')
         
# Classes and functions for loading and using the Inception model
import inception
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import os
import tensorflow as tf

tf.__version__

# Download the Inception model
inception.data_dir = 'inception/'

def maybe_download():
    """
    Download the Inception model from the internet if it does not already
    exist in the data_dir. The file is about 85 MB.
    """

    print("Downloading Inception v3 Model ...")
    download.maybe_download_and_extract(url=data_url, download_dir=data_dir)

inception.maybe_download()

但收到错误消息---

    AttributeError                            Traceback (most recent call last)
<ipython-input-23-a941731aed67> in <module>()
----> 1 inception.maybe_download()

AttributeError: module 'inception' has no attribute 'maybe_download'

请尽快帮助我

非常感谢

【问题讨论】:

    标签: python-3.x machine-learning artificial-intelligence


    【解决方案1】:

    我假设您想从 Tensorflow 运行初始模型,对吗? inception 模型就像你在 Python 中使用的 import 一样,已经很老了。 一般来说,您的 AttributeError: module ... has not attribute ... 声明您要在对象/模块上调用的方法不存在。在您的特定情况下,这意味着 maybe_download() 不是初始对象/模块的方法。但是,由于我假设您想使用 tensorflows 的 inception 方法,请查看 this repo。它详细解释了如何将maybe_download方法用于inception模型以及如何开始。

    编辑:

    好的,现在我明白了你的问题(至少我希望如此)。在你的第一行代码中你pip install inception。正如我假设您正在尝试执行Tensorflow-Tutorials。在这种情况下,inception 不是指可以通过pip 安装的包,而是指给定存储库中的module。从这个意义上讲,module 是另一个 .py 脚本。如果您转到引用的GitHub Repo,您可以搜索名为inception.py 的文件。在该文件中,您还可以找到 maybe_download() 函数。

    在代码方面: 首先转到一个文件夹并执行:

    git clone https://github.com/Hvass-Labs/TensorFlow-Tutorials.git

    完成后,您可以在与 repo 相同的文件夹中使用您的初始模型创建自己的 .py。然后你可以在你的.py 文件中轻松地import inception,它应该可以工作。如需更详细的代码示例,请查看this notebook。请记住,为了在本地运行它以克隆存储库,如上所述使用git clone

    【讨论】:

    • 我知道你的评论,但我不明白如何解决这个问题---请写一些代码来解决上述错误
    • 我重写了我的代码,但仍然得到同样的错误---我可以使用另一个代码来下载初始模型,因为我在谷歌 colab 中使用它时无法成功
    猜你喜欢
    • 1970-01-01
    • 2018-08-21
    • 1970-01-01
    • 1970-01-01
    • 2021-05-23
    • 1970-01-01
    • 2020-10-26
    • 1970-01-01
    • 2021-12-23
    相关资源
    最近更新 更多