嗨,我正在尝试构建一个图像输入管道。我的预处理训练数据存储在我使用以下代码行创建的 tfrecords 文件中:
def _bytes_feature(value):
return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
def _int64_feature(value):
return tf.train.Feature(int64_list=tf.train.Int64List(value=[value]))
Run Code Online (Sandbox Code Playgroud)
..
img_raw = img.tostring() # typeof(img) = np.Array with shape (50, 80) dtype float64
img_label_text_raw = str.encode(img_lable)
example = tf.train.Example(features=tf.train.Features(feature={
'height': _int64_feature(height), #heigth (integer)
'width': _int64_feature(width), #width (integer)
'depth': _int64_feature(depth), #num of rgb channels (integer)
'image_data': _bytes_feature(img_raw), #raw image data (byte string)
'label_text': _bytes_feature(img_label_text_raw), #raw image_lable_text (byte string)
'lable': _int64_feature(lable_txt_to_int[img_lable])})) #label index (integer)
writer.write(example.SerializeToString())
Run Code Online (Sandbox Code Playgroud)
现在我尝试读取二进制数据以从中重建张量:
def read_and_decode(filename_queue):
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
features = tf.parse_single_example(
serialized_example,
# …Run Code Online (Sandbox Code Playgroud)