我该如何解决键盘错误

时间:2019-06-15 10:41:27

标签: keyerror tfrecord

我正在研究colab中的对象检测。 我从GitHub获得了代码。 这里的链接https://medium.com/@moshe.livne/training-tensorflow-for-free-pet-object-detection-api-sample-trained-on-google-collab-c2e65f4a9949

当我使用create_pet_tf_record.py时,出现错误。 是KeyError。 我只有一堂课,而且不是同一类。 现在,我的班级是Shin,但是KeyError是'drop'。 实际上,很久以前我就使用“掉落”类别。

您能解决这些错误吗

代码正在google colab上运行。 我的班只是“申” 我修改了这些代码,并确认要为其他图像运行代码。

这是可以创建tfrecord文件的代码。

%cd ~/datalab

!python ~/models/research/object_detection/dataset_tools/create_pet_tf_record.py --label_map_path=label_map.pbtxt --data_dir=. --output_dir=. --num_shards=1

这是我的错误

/root/datalab
WARNING: Logging before flag parsing goes to stderr.
W0615 10:23:11.859250 139781813761920 deprecation_wrapper.py:119] From /root/models/research/object_detection/dataset_tools/create_pet_tf_record.py:318: The name tf.app.run is deprecated. Please use tf.compat.v1.app.run instead.

W0615 10:23:11.859874 139781813761920 deprecation_wrapper.py:119] From /usr/local/lib/python2.7/dist-packages/object_detection-0.1-py2.7.egg/object_detection/utils/label_map_util.py:132: The name tf.gfile.GFile is deprecated. Please use tf.io.gfile.GFile instead.

I0615 10:23:11.861181 139781813761920 create_pet_tf_record.py:273] Reading from Pet dataset.
I0615 10:23:11.861639 139781813761920 create_pet_tf_record.py:288] 21 training and 9 validation examples.
W0615 10:23:11.861834 139781813761920 deprecation_wrapper.py:119] From /usr/local/lib/python2.7/dist-packages/object_detection-0.1-py2.7.egg/object_detection/dataset_tools/tf_record_creation_util.py:43: The name tf.python_io.TFRecordWriter is deprecated. Please use tf.io.TFRecordWriter instead.

I0615 10:23:11.862046 139781813761920 create_pet_tf_record.py:241] On image 0 of 21
/usr/local/lib/python2.7/dist-packages/object_detection-0.1-py2.7.egg/object_detection/utils/dataset_util.py:75: FutureWarning: The behavior of this method will change in future versions. Use specific 'len(elem)' or 'elem is not None' test instead.
  if not xml:
Traceback (most recent call last):
  File "/root/models/research/object_detection/dataset_tools/create_pet_tf_record.py", line 318, in <module>
    tf.app.run()
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 40, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "/usr/local/lib/python2.7/dist-packages/absl/app.py", line 300, in run
    _run_main(main, args)
  File "/usr/local/lib/python2.7/dist-packages/absl/app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "/root/models/research/object_detection/dataset_tools/create_pet_tf_record.py", line 305, in main
    mask_type=FLAGS.mask_type)
  File "/root/models/research/object_detection/dataset_tools/create_pet_tf_record.py", line 260, in create_tf_record
    mask_type=mask_type)
  File "/root/models/research/object_detection/dataset_tools/create_pet_tf_record.py", line 167, in dict_to_tf_example
    classes.append(label_map_dict[class_name])
KeyError: 'drop'

我已经检查了我的label_map。我只能看到一个班级的“申”

你知道我该怎么解决吗?

1 个答案:

答案 0 :(得分:0)

这是一个未定义的类,您必须更改为:

    classes.append(label_map_dict[class_name])
文件“ /root/models/research/object_detection/dataset_tools/create_pet_tf_record.py”的

到:

    classes.append(label_map_dict[x])

为x文件编号。pbtxt的类(在本例中为“ drop”)。 除非您将代码用于1个以上的类,否则它将解决该问题。 我希望它能工作,好湖。