How can I create a tensorflow record from a list?
From the documentation here it seems possible. There's also this example where they convert a numpy array into a byte array using the .tostring()
from numpy. However when I try to pass in:
labels = np.asarray([[1,2,3],[4,5,6]])
...
example = tf.train.Example(features=tf.train.Features(feature={
'height': _int64_feature(rows),
'width': _int64_feature(cols),
'depth': _int64_feature(depth),
'label': _int64_feature(labels[index]),
'image_raw': _bytes_feature(image_raw)}))
writer.write(example.SerializeToString())
I get the error:
TypeError: array([1, 2, 3]) has type type 'numpy.ndarray', but expected one of: (type 'int', type 'long')
Which doesn't help me to figure out how to store a list of integers into the tfrecord. I've tried looking through the docs.
Creating TFRecord Files with Code Most often we have labeled data in PASCAL VOC XML or COCO JSON. Creating a TFRecord file from this data requires following a multistep process: (1) creating a TensorFlow Object Detection CSV (2) Using that TensorFlow Object Detection CSV to create TFRecord files.
The TFRecord format is a simple format for storing a sequence of binary records. Protocol buffers are a cross-platform, cross-language library for efficient serialization of structured data. Protocol messages are defined by . proto files, these are often the easiest way to understand a message type.
Int64List
, BytesList
and FloatList
expect an iterator of the underlying elements (repeated
field). In the case of your function _int64_feature
you use a list as an iterator.
When you pass a scalar, your _int64_feature
creates an array of one int64 element in it (exactly as expected). But when you pass an ndarray you create a list of one ndarray and pass it to a function which expects a list of int64.
So just remove construction of the array from your function: int64_list=tf.train.Int64List(value=value)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With