" UnicodeDecodeError错误"运行infer_detections脚本

时间:2018-04-06 12:58:33

标签: tensorflow

使用我的冻结图和测试集以下列方式运行infer_detections script

python -m infer_detections --input_tfrecord_paths=../data/coco_testdev.record --output_tfrecord_path=../data/inference --inference_graph=../model/fine_tuned_model/frozen_inference_graph.pb --discard_image_pixels

抛出错误UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 394: invalid start byte

完整的堆栈跟踪是:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\ProgramData\Anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\me\Documents\GitHub\TransferLearningWithTensorflowAPI\scripts\infer_detections.py", line 96, in <module>
    tf.app.run()
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\platform\app.py", line 124, in run
    _sys.exit(main(argv))
  File "C:\Users\me\Documents\GitHub\TransferLearningWithTensorflowAPI\scripts\infer_detections.py", line 74, in main
    image_tensor, FLAGS.inference_graph)
  File "C:\ProgramData\Anaconda3\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\inference\detection_inference.py", line 69, in build_inference_graph
    graph_content = graph_def_file.read()
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 126, in read
    pywrap_tensorflow.ReadFromStream(self._read_buf, length, status))
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 94, in _prepare_value
    return compat.as_str_any(val)
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\util\compat.py", line 106, in as_str_any
    return as_str(value)
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\util\compat.py", line 84, in as_text
    return bytes_or_text.decode(encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 394: invalid start byte

可能是什么问题?

1 个答案:

答案 0 :(得分:1)

更改(object_detection / inference / detection_inference.py下的第68-69行)

with tf.gfile.Open(inference_graph_path, 'r') as graph_def_file:
    graph_content = graph_def_file.read()

with tf.gfile.Open(inference_graph_path, 'rb') as graph_def_file:
    graph_content = graph_def_file.read()