Skip to content

Instantly share code, notes, and snippets.

@MITsVision
Created June 18, 2020 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MITsVision/cc5debb87d223e613cd81ebc541738ec to your computer and use it in GitHub Desktop.
Save MITsVision/cc5debb87d223e613cd81ebc541738ec to your computer and use it in GitHub Desktop.
import tensorflow as tf
train_record = 'tf-records/coco_train.record-00000-of-00001'
for i, record in enumerate(tf.python_io.tf_record_iterator(train_record)):
#print("######################### Record", i, "#########################")
example = tf.train.Example()
example.ParseFromString(record)
feature = example.features.feature
imgHeight = feature['image/height'].int64_list.value[0]
imgWidth = feature['image/width'].int64_list.value[0]
imgFileName = feature['image/filename'].bytes_list .value[0].decode('utf-8')
print(imgWidth,imgHeight,imgFileName)
#print(feature)
bboxes = []
for ibbox, label in enumerate (feature["image/object/class/text"].bytes_list.value):
textLabel = label.decode("utf-8")
bboxes.append( (textLabel,
feature["image/object/bbox/xmin"].float_list.value[ibbox],
feature["image/object/bbox/xmax"].float_list.value[ibbox],
feature["image/object/bbox/ymin"].float_list.value[ibbox],
feature["image/object/bbox/ymax"].float_list.value[ibbox]
))
print(bboxes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment