写入:
ima = img_array[index][1].tobytes() example = tf.train.Example( features=tf.train.Features( feature={ 'label': _int64_feature( int(img_array[index][0])), # label 'data': _bytes_feature(ima) # 图像的数据 }))
img_array[index][1].shape -- (1764,)
读取:
features = tf.parse_single_example( serialized_example, features={ 'data':tf.FixedLenFeature([],tf.string), 'label':tf.FixedLenFeature([],tf.int64) })
images = tf.decode_raw(features['data'],tf.uint8)
images --- shape -- (7056,0)
原因:
因为img_array 数据类型为 float32 转化为字节的时候 被分成7056
解决: 把 img_array数据类型转化为unit8: img_array[index][1].astype(np.uint8)