Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Created February 12, 2020 07:00
Show Gist options
  • Save cocodrips/6a7e4b3e10061572a45f23aaae857c34 to your computer and use it in GitHub Desktop.
Save cocodrips/6a7e4b3e10061572a45f23aaae857c34 to your computer and use it in GitHub Desktop.
fix create_oid_tf_record.py 2020/02
diff --git a/research/object_detection/dataset_tools/create_oid_tf_record.py b/research/object_detection/dataset_tools/create_oid_tf_record.py
index 26d9699c..458037a1 100644
--- a/research/object_detection/dataset_tools/create_oid_tf_record.py
+++ b/research/object_detection/dataset_tools/create_oid_tf_record.py
@@ -103,7 +103,7 @@ def main(_):
image_id, image_annotations = image_data
# In OID image file names are formed by appending ".jpg" to the image ID.
image_path = os.path.join(FLAGS.input_images_directory, image_id + '.jpg')
- with tf.gfile.Open(image_path) as image_file:
+ with tf.gfile.Open(image_path, 'rb') as image_file:
encoded_image = image_file.read()
tf_example = oid_tfrecord_creation.tf_example_from_annotations_data_frame(
diff --git a/research/object_detection/utils/dataset_util.py b/research/object_detection/utils/dataset_util.py
index e8403eae..1dd1e990 100644
--- a/research/object_detection/utils/dataset_util.py
+++ b/research/object_detection/utils/dataset_util.py
@@ -27,14 +27,18 @@ def int64_feature(value):
def int64_list_feature(value):
+ value = [v.encode() if isinstance(v, str) else v for v in value]
return tf.train.Feature(int64_list=tf.train.Int64List(value=value))
def bytes_feature(value):
+ if isinstance(value, str):
+ value = value.encode()
return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
def bytes_list_feature(value):
+ value = [v.encode() if isinstance(v, str) else v for v in value]
return tf.train.Feature(bytes_list=tf.train.BytesList(value=value))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment