为COCO数据集生成TFRecord

时间:2019-01-16 11:20:30

标签: python json tensorflow

我正在使用TensorFlow库构建对象检测器。我正在尝试将COCO 2017数据集转换为TFRecord,但出现此错误消息。

Traceback (most recent call last):
  File "/Volumes/EXTERNAL/Models/models-master/research/object_detection/Obj_Det/create_coco_tf_record.py", line 283, in <module>
    tf.app.run()
  File "/usr/local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 125, in run
    _sys.exit(main(argv))
  File "/Volumes/EXTERNAL/Models/models-master/research/object_detection/Obj_Det/create_coco_tf_record.py", line 267, in main
    num_shards=100)
  File "/Volumes/EXTERNAL/Models/models-master/research/object_detection/Obj_Det/create_coco_tf_record.py", line 211, in _create_tf_record_from_coco_annotations
    groundtruth_data = json.load(fid,('utf-8'))
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 291, in load
    **kw)
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 352, in loads
    return cls(encoding=encoding, **kw).decode(s)
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

您知道如何解决此错误吗?

我在jupyter笔记本中键入了以下代码:

!python /Volumes/EXTERNAL/Models/models-master/research/object_detection/Obj_Det/create_coco_tf_record.py --logtostderr \
      --train_image_dir=/Volumes/EXTERNAL/Models/models-master/research/object_detection/Obj_Det/images \
      --val_image_dir=/Volumes/EXTERNAL/Models/models-master/research/object_detection/Obj_Det/images \
      --test_image_dir=/Volumes/EXTERNAL/Models/models-master/research/object_detection/Obj_Det/images \
      --train_annotations_file=/Volumes/EXTERNAL/Models/models-master/research/object_detection/Obj_Det/images \
      --val_annotations_file=/Volumes/EXTERNAL/Models/models-master/research/object_detection/Obj_Det/images \
      --testdev_annotations_file=/Volumes/EXTERNAL/Models/models-master/research/object_detection/Obj_Det/images \
      --output_dir=/Volumes/EXTERNAL/Models/models-master/research/object_detection/Obj_Det/images/train.record

1 个答案:

答案 0 :(得分:-1)

您是否从可可官方网站上下载了数据集和标签 如果这样做,请按照py文件中的注释

"""
Example usage:
    python create_coco_tf_record.py --logtostderr \
      --train_image_dir="${TRAIN_IMAGE_DIR}" \
      --val_image_dir="${VAL_IMAGE_DIR}" \
      --test_image_dir="${TEST_IMAGE_DIR}" \
      --train_annotations_file="${TRAIN_ANNOTATIONS_FILE}" \
      --val_annotations_file="${VAL_ANNOTATIONS_FILE}" \
      --testdev_annotations_file="${TESTDEV_ANNOTATIONS_FILE}" \
      --output_dir="${OUTPUT_DIR}"
"""