问题描述
我试图在 tensorflow 的帮助下构建一个对象检测模型,但一次又一次地出现这个错误.我也试过 tf.io.Gfile ,但它没有帮助.我也在使用 tensorflow 2.2.0 版本和 tensorflow-GPU 2.2.0.这是代码,
!python {SCRIPTS_PATH + '/generate_tfrecord.py'} -x {IMAGE_PATH + '/train'} -l {ANNOTATION_PATH + '/label_map.pbtxt'} -o {ANNOTATION_PATH + '/train.record'}
!python {SCRIPTS_PATH + '/generate_tfrecord.py'} -x {IMAGE_PATH + '/train'} -l {ANNOTATION_PATH + '/label_map.pbtxt'} -o {ANNOTATION_PATH + '/train.record'}
!python {SCRIPTS_PATH + '/generate_tfrecord.py'} -x{IMAGE_PATH + '/test'} -l {ANNOTATION_PATH + '/label_map.pbtxt'} -o {ANNOTATION_PATH + '/test.record'}
!python {SCRIPTS_PATH + '/generate_tfrecord.py'} -x{IMAGE_PATH + '/test'} -l {ANNOTATION_PATH + '/label_map.pbtxt'} -o {ANNOTATION_PATH + '/test.record'}
当我将 tf.gfile 更改为 tf.io.gfile 时,出现了新错误....
我尝试过,现在面临这个......
I tried and now facing this....
回溯(最近一次调用最后一次):
Traceback (most recent call last):
文件Tensorflow/scripts/generate_tfrecord.py",第 62 行,
File "Tensorflow/scripts/generate_tfrecord.py", line 62, in
label_map_dict = label_map_util.get_label_map_dict(label_map)
文件 "C:\Users\91880\AppData\Roaming\Python\Python37\site-packages\object_detection\utils\label_map_util.py",第 164 行,在 get_label_map_dict 中label_map = load_labelmap(label_map_path)
File "C:\Users\91880\AppData\Roaming\Python\Python37\site-packages\object_detection\utils\label_map_util.py", line 164, in get_label_map_dictlabel_map = load_labelmap(label_map_path)
文件C:\Users\91880\AppData\Roaming\Python\Python37\site-packages\object_detection\utils\label_map_util.py",第 133 行,在 load_labelmap 中label_map_string = fid.read()
File "C:\Users\91880\AppData\Roaming\Python\Python37\site-packages\object_detection\utils\label_map_util.py", line 133, in load_labelmaplabel_map_string = fid.read()
文件C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_core\python\lib\io\file_io.py",第 122 行,读取self._preread_check()
File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_core\python\lib\io\file_io.py", line 122, in readself._preread_check()
文件C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_core\python\lib\io\file_io.py",第 84 行,在 _preread_checkcompat.as_bytes(self.__name), 1024 * 512)
File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_core\python\lib\io\file_io.py", line 84, in _preread_checkcompat.as_bytes(self.__name), 1024 * 512)
文件C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_core\python\util\compat.py",第 71 行,as_bytes(bytes_or_text,))
File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow_core\python\util\compat.py", line 71, in as_bytes(bytes_or_text,))
TypeError: 预期的二进制或 unicode 字符串,得到项目 {
TypeError: Expected binary or unicode string, got item {
名称:Namaste"编号:1}
name: "Namaste"id: 1}
项目{名称:谢谢"编号:2}
item {name: "Thanks"id: 2}
项目{姓名:是"编号:3}
item {name: "Yes"id: 3}
项目{名称:否"编号:4}
item {name: "No"id: 4}
项目{名称:好"编号:5}
item {name: "Good"id: 5}
推荐答案
将 TensorFlow 版本降级到 1.15,看看是否能解决问题
Downgrade the TensorFlow version to 1.15 and see if that solves the problem
这篇关于带有 AttributeError: 模块 'tensorflow' 没有属性 'gfile'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!