实时对象检测没有名为“tensorflow.compat.v1”的模块

问题描述

我正在跟踪 https://automaticaddison.com/real-time-object-recognition-using-a-webcam-and-deep-learning/#top 上的实时对象检测,但遇到了障碍 我按照所有说明进行操作并检查是否有任何错误,但仍然出现此错误 (我用的是windows)

 Traceback (most recent call last):   File "object_detection_test.py",line 15,in <module>
     from utils import label_map_util   File "C:\Users\1rock\Documents\TensorFlow\models\research\object_detection\utils\label_map_util.py",line 27,in <module>
     import tensorflow.compat.v1 as tf ModuleNotFoundError: No module named 'tensorflow.compat.v1'

我使用了上面链接所说的 pip install --ignore-installed --upgrade tensorflow==1.9 并且在运行时我得到了这些包及其版本和一个错误,希望它与问题相关

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behavIoUr is the source of the following dependency conflicts.

ipywidgets 7.6.0 requires jupyterlab-widgets>=1.0.0,which is not installed.

Successfully installed absl-py-0.11.0 astor-0.8.1 gast-0.4.0 grpcio-1.34.0 importlib-Metadata-3.3.0 markdown-3.3.3 numpy-1.19.4 protobuf-3.14.0 setuptools-51.0.0.post20201207 six-1.15.0 tensorboard-1.9.0 tensorflow-1.9.0 termcolor-1.1.0 typing-extensions-3.7.4.3 werkzeug-1.0.1 wheel-0.36.2 zipp-3.4.0

解决方法

我使用了 pip install --ignore-installed --upgrade tensorflow==1.9

第 27 行,在 将 tensorflow.compat.v1 导入为 tf ModuleNotFoundError:没有名为“tensorflow.compat.v1”的模块

TF 1.9 及更早版本没有 compat 模块。要使用它,您需要 TF 1.10+。最好在 conda 虚拟环境中尽可能使用 conda install。

此外,由于您使用的是 tensorflow models,请确保您拥有相应版本的存储库,例如位于 here 的最新 TF1.x 版本