tensorflow / models

Models and examples built with TensorFlow
Other
77k stars 45.79k forks source link

[object_detection] Unit tests failing for /dataset_tools/oid_tfrecord_creation.py #7997

Open KieranLitschel opened 4 years ago

KieranLitschel commented 4 years ago

System information

Describe the problem

Unit tests are failing for /object_detection/dataset_tools/oid_tfrecord_creation.py . I also encounter the the same error again originating from oid_tfrecord_creation when trying to run /object_detection/dataset_tools/create_oid_tf_record.py with the label map /object_detection/data/oid_v4_label_map.pbtxt .

Source code / logs

Running tests under Python 3.7.5: /afs/inf.ed.ac.uk/user/s16/s1614973/miniconda3/envs/hp/bin/python
[ RUN      ] TfExampleFromAnnotationsDataFrameTests.test_label_filtering
/dev/shm/models/research/object_detection/dataset_tools/oid_tfrecord_creation.py:53: FutureWarning: Method .as_matrix will be removed in a future version. Use .values instead.
  filtered_data_frame_boxes.YMin.as_matrix()),
/dev/shm/models/research/object_detection/dataset_tools/oid_tfrecord_creation.py:56: FutureWarning: Method .as_matrix will be removed in a future version. Use .values instead.
  filtered_data_frame_boxes.XMin.as_matrix()),
/dev/shm/models/research/object_detection/dataset_tools/oid_tfrecord_creation.py:59: FutureWarning: Method .as_matrix will be removed in a future version. Use .values instead.
  filtered_data_frame_boxes.YMax.as_matrix()),
/dev/shm/models/research/object_detection/dataset_tools/oid_tfrecord_creation.py:62: FutureWarning: Method .as_matrix will be removed in a future version. Use .values instead.
  filtered_data_frame_boxes.XMax.as_matrix()),
/dev/shm/models/research/object_detection/dataset_tools/oid_tfrecord_creation.py:65: FutureWarning: Method .as_matrix will be removed in a future version. Use .values instead.
  filtered_data_frame_boxes.LabelName.as_matrix()),
[  FAILED  ] TfExampleFromAnnotationsDataFrameTests.test_label_filtering
[ RUN      ] TfExampleFromAnnotationsDataFrameTests.test_no_attributes
[  FAILED  ] TfExampleFromAnnotationsDataFrameTests.test_no_attributes
[ RUN      ] TfExampleFromAnnotationsDataFrameTests.test_session
[  SKIPPED ] TfExampleFromAnnotationsDataFrameTests.test_session
[ RUN      ] TfExampleFromAnnotationsDataFrameTests.test_simple
[  FAILED  ] TfExampleFromAnnotationsDataFrameTests.test_simple
======================================================================
ERROR: test_label_filtering (__main__.TfExampleFromAnnotationsDataFrameTests)
test_label_filtering (__main__.TfExampleFromAnnotationsDataFrameTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "object_detection/dataset_tools/oid_tfrecord_creation_test.py", line 147, in test_label_filtering
    df[df.ImageID == 'i1'], label_map, 'encoded_image_test')
  File "/dev/shm/models/research/object_detection/dataset_tools/oid_tfrecord_creation.py", line 65, in tf_example_from_annotations_data_frame
    filtered_data_frame_boxes.LabelName.as_matrix()),
  File "/dev/shm/models/research/object_detection/utils/dataset_util.py", line 38, in bytes_list_feature
    return tf.train.Feature(bytes_list=tf.train.BytesList(value=value))
TypeError: 'a' has type str, but expected one of: bytes

======================================================================
ERROR: test_no_attributes (__main__.TfExampleFromAnnotationsDataFrameTests)
test_no_attributes (__main__.TfExampleFromAnnotationsDataFrameTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "object_detection/dataset_tools/oid_tfrecord_creation_test.py", line 109, in test_no_attributes
    df[df.ImageID == 'i2'], label_map, 'encoded_image_test')
  File "/dev/shm/models/research/object_detection/dataset_tools/oid_tfrecord_creation.py", line 65, in tf_example_from_annotations_data_frame
    filtered_data_frame_boxes.LabelName.as_matrix()),
  File "/dev/shm/models/research/object_detection/utils/dataset_util.py", line 38, in bytes_list_feature
    return tf.train.Feature(bytes_list=tf.train.BytesList(value=value))
TypeError: 'b' has type str, but expected one of: bytes

======================================================================
ERROR: test_simple (__main__.TfExampleFromAnnotationsDataFrameTests)
test_simple (__main__.TfExampleFromAnnotationsDataFrameTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "object_detection/dataset_tools/oid_tfrecord_creation_test.py", line 48, in test_simple
    df[df.ImageID == 'i1'], label_map, 'encoded_image_test')
  File "/dev/shm/models/research/object_detection/dataset_tools/oid_tfrecord_creation.py", line 65, in tf_example_from_annotations_data_frame
    filtered_data_frame_boxes.LabelName.as_matrix()),
  File "/dev/shm/models/research/object_detection/utils/dataset_util.py", line 38, in bytes_list_feature
    return tf.train.Feature(bytes_list=tf.train.BytesList(value=value))
TypeError: 'a' has type str, but expected one of: bytes

----------------------------------------------------------------------
Ran 4 tests in 0.034s

FAILED (errors=3, skipped=1)
KieranLitschel commented 4 years ago

I've partially managed to fix it on my end, it seems like the methods bytes_feature and bytes_list_feature in /object_detection/utils/dataset_util.py must have used to be able to accept strings as types, presumably casting them to bytes at some point, but that seems to be no longer the case. I managed to fix the bytes_list_feature method by casting the Panda DataFrames values to bytes using the .astype("bytes") method, and similarly for bytes_feature by calling .encode("utf-8") for passed strings. I made this change in oid_tfrecord_creation.py though, so there probably could be a more elegant solution

javadan commented 4 years ago

Still occurring Sept 2020. Looks like this or similar might fix it though: https://github.com/tensorflow/models/pull/4771/files