' tensorflow._api.v1.compat.v2.compat'没有属性' v2'

发布于 2025-02-06 16:43:33 字数 2075 浏览 0 评论 0原文

我运行这个:

!python models/research/object_detection/model_main_tf2.py
 --model_dir=Tensorflow/workspace/models/my_ssd_mobnet --pipeline_config_path=Tensorflow/workspace/models/my_ssd_mobnet/pipeline.config --num_training_steps=200

并获取此错误:tensorflow._api.v1.compat.v2.compat'没有属性'v2

 Traceback (most recent call last):   File "models/research/object_detection/model_main_tf2.py", line 113, in <module>
        tf.compat.v1.app.run()   File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/platform/app.py", line 40, in run
        _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)   File "/usr/local/lib/python3.7/dist-packages/absl/app.py", line 312, in run
        _run_main(main, args)   File "/usr/local/lib/python3.7/dist-packages/absl/app.py", line 258, in
    _run_main
        sys.exit(main(argv))   File "models/research/object_detection/model_main_tf2.py", line 101, in main
        strategy = tf.compat.v2.distribute.MirroredStrategy()   File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/util/module_wrapper.py", line 193, in __getattr__
        attr = getattr(self._tfmw_wrapped_module, name) AttributeError: module '**tensorflow._api.v1.compat.v2.compat' has no attribute 'v2**'

我也将其用于API:

 %tensorflow_version 1.x
import os
import pathlib

# Clone the tensorflow models repository if it doesn't already exist
if "models" in pathlib.Path.cwd().parts:
  while "models" in pathlib.Path.cwd().parts:
    os.chdir('..')
elif not pathlib.Path('models').exists():
  !git clone --depth 1 https://github.com/cloud-annotations/models

!pip install cloud-annotations==0.0.4
!pip install tf_slim
!pip install lvis
!pip install --no-deps tensorflowjs==1.4.0

%cd /content/drive/MyDrive/Object_Detecation/models/research
!protoc object_detection/protos/*.proto --python_out=.

pwd = os.getcwd()
os.environ['PYTHONPATH'] += f':{pwd}:{pwd}/slim'

!python object_detection/builders/model_builder_tf2_test.py

有人可以帮忙吗?

I run this:

!python models/research/object_detection/model_main_tf2.py
 --model_dir=Tensorflow/workspace/models/my_ssd_mobnet --pipeline_config_path=Tensorflow/workspace/models/my_ssd_mobnet/pipeline.config --num_training_steps=200

and get this error: tensorflow._api.v1.compat.v2.compat' has no attribute 'v2

 Traceback (most recent call last):   File "models/research/object_detection/model_main_tf2.py", line 113, in <module>
        tf.compat.v1.app.run()   File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/platform/app.py", line 40, in run
        _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)   File "/usr/local/lib/python3.7/dist-packages/absl/app.py", line 312, in run
        _run_main(main, args)   File "/usr/local/lib/python3.7/dist-packages/absl/app.py", line 258, in
    _run_main
        sys.exit(main(argv))   File "models/research/object_detection/model_main_tf2.py", line 101, in main
        strategy = tf.compat.v2.distribute.MirroredStrategy()   File "/tensorflow-1.15.2/python3.7/tensorflow_core/python/util/module_wrapper.py", line 193, in __getattr__
        attr = getattr(self._tfmw_wrapped_module, name) AttributeError: module '**tensorflow._api.v1.compat.v2.compat' has no attribute 'v2**'

I also use this for API:

 %tensorflow_version 1.x
import os
import pathlib

# Clone the tensorflow models repository if it doesn't already exist
if "models" in pathlib.Path.cwd().parts:
  while "models" in pathlib.Path.cwd().parts:
    os.chdir('..')
elif not pathlib.Path('models').exists():
  !git clone --depth 1 https://github.com/cloud-annotations/models

!pip install cloud-annotations==0.0.4
!pip install tf_slim
!pip install lvis
!pip install --no-deps tensorflowjs==1.4.0

%cd /content/drive/MyDrive/Object_Detecation/models/research
!protoc object_detection/protos/*.proto --python_out=.

pwd = os.getcwd()
os.environ['PYTHONPATH'] += f':{pwd}:{pwd}/slim'

!python object_detection/builders/model_builder_tf2_test.py

Can anyone help about it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱花细雨 2025-02-13 16:43:33

在您的代码中,您使用的是compat.v2 api,但是您正在尝试在tensorflowv 1.x 1.x中运行代码。

替换

strategy = tf.compat.v2.distribute.MirroredStrategy()

tf.compat.v1.distribute.MirroredStrategy()

In your code you are using compat.v2 API, but you are trying to run code in Tensorflowv 1.x.

Replace

strategy = tf.compat.v2.distribute.MirroredStrategy()

With

tf.compat.v1.distribute.MirroredStrategy()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文