【发布时间】:2020-10-04 04:09:54
【问题描述】:
我在驱动器中上传模型并将其安装在 Colab 模块中时遇到问题,因为我提供了根路径和 sys.append() 它,导入在以前的单元格中工作正常,我正在使用 (tf.compat. v1) 你可以在 ouptut 中看到它,但也尝试过(tensorflow v2)并使用 tf.io.gfile 但仍然出现同样的错误。请帮帮我
<module 'tensorflow_core.compat.v1.version' from '/usr/local/lib/python3.6/dist-packages/tensorflow_core/_api/v2/compat/v1/version/__init__.py'>
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-7-e851eb463895> in <module>()
1 print(tf.version)
----> 2 category_index = label_map_util.create_category_index_from_labelmap(PATH_TO_LABELS, use_display_name=True)
2 frames
/content/drive/My Drive/models/research/object_detection/utils/label_map_util.py in load_labelmap(path)
136 a StringIntLabelMapProto
137 """
--> 138 with tf.gfile.GFile(path, 'r') as fid:
139 label_map_string = fid.read()
140 label_map = string_int_label_map_pb2.StringIntLabelMap()
AttributeError: module 'tensorflow' has no attribute 'gfile'
【问题讨论】:
-
您能否尝试从
TF2.x降级到TF1.15,看看您的问题是否已在本地计算机中解决。如果您正在为 Colab 寻找简单的解决方案,请使用%tensorflow_version 1.x魔术命令,无需卸载即可为您解决问题。 -
感谢您的帮助,我也做了同样的事情。它在 v1.15 上运行良好。我只是在 label_map_util 中导入 tensorflow.compat.v1,它默认使用 v1.15。
-
很高兴它对您有所帮助。如果您要导入
import tensorflow as tf,它也会开始使用TF 1.15。为了社区的利益,我会将其发布为答案。
标签: python-3.x tensorflow google-colaboratory