python - Create an int list feature to save as tfrecord in tensorflow? -


how can create tensorflow record list?

from documentation here seems possible. there's example convert numpy array byte array using .tostring() numpy. when try 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 error:

typeerror: array([1, 2, 3]) has type type 'numpy.ndarray', expected 1 of: (type 'int', type 'long') 

which doesn't me figure out how store list of integers tfrecord. i've tried looking through docs.

after while of messing around , looking further in documentation found own answer. in above function using example code base:

def _int64_feature(value):   return tf.train.feature(int64_list=tf.train.int64list(value=[value])) ... 'label': _int64_feature(labels[index]), 

labels[index] being cast list [value] have [np.array([1,2,3])] causes error.

the above cast necessary in example because tf.train.int64list() expects either list or numpy array , example passing in single integer typecasted list so.
in example this

label = [1,2,3,4] ... 'label': _int64_feature(label[index])   tf.train.feature(int64_list=tf.train.int64list(value=[value])) #where value = [1] in case 

if want pass in list this

labels = np.asarray([[1,2,3],[4,5,6]]) ... def _int64_feature(value):   return tf.train.feature(int64_list=tf.train.int64list(value=value)) ... 'label': _int64_feature(labels[index]), 

i'll pull request because found original documentation tf.train.feature non-existent.

tl;dr

pass either list or numpy array tf.train.int64list() not list of lists or list of numpy arrays.