遵循Tensorflow Codelabs教程图像分类的ImportError

时间:2019-11-15 21:34:23

标签: python tensorflow importerror

我正在阅读代码实验室https://codelabs.developers.google.com/codelabs/tensorflow-for-poets/#5的教程

我有tensorflow 1.14和python 3.7

当我运行以下代码时:

python -m scripts.label_image \
    --graph=tf_files/retrained_graph.pb  \
    --image=tf_files/flower_photos/daisy/21652746_cc379e0eea_m.jpg

我收到以下错误:

C:\Users\FATIMA\Anaconda3\lib\site-packages\tensorflow\python\framework\dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
C:\Users\FATIMA\Anaconda3\lib\site-packages\tensorflow\python\framework\dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
C:\Users\FATIMA\Anaconda3\lib\site-packages\tensorflow\python\framework\dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
C:\Users\FATIMA\Anaconda3\lib\site-packages\tensorflow\python\framework\dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
C:\Users\FATIMA\Anaconda3\lib\site-packages\tensorflow\python\framework\dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
C:\Users\FATIMA\Anaconda3\lib\site-packages\tensorflow\python\framework\dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
Traceback (most recent call last):
  File "C:\Users\FATIMA\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\FATIMA\Anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\FATIMA\Desktop\tensorflow-for-poets-2\scripts\label_image.py", line 25, in <module>
    import tensorflow as tf
  File "C:\Users\FATIMA\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 28, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "C:\Users\FATIMA\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 70, in <module>
    from tensorflow.python.client.client_lib import *
  File "C:\Users\FATIMA\Anaconda3\lib\site-packages\tensorflow\python\client\client_lib.py", line 26, in <module>
    from tensorflow.python.client.session import InteractiveSession
  File "C:\Users\FATIMA\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 45, in <module>
    from tensorflow.python.util.compat import collections_abc
ImportError: cannot import name 'collections_abc' from 'tensorflow.python.util.compat' (C:\Users\FATIMA\Anaconda3\lib\site-packages\tensorflow\python\util\compat.py)

我该如何解决:(?

1 个答案:

答案 0 :(得分:0)

我通过使用此路径手动删除tensorflow文件来解决了这个问题

Anaconda3\lib\site-packages\tensorflow

然后通过pip卸载

pip uninstall tensorflow

然后重新安装tensorflow

pip install tensorflow-gpu