您可以在编码之前调整大小。
def int64_feature(value): return tf.train.Feature(int64_list=tf.train.Int64List(value=[value])) def bytes_feature(value): return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
从字符串转换并调整大小
image = numpy.fromstring(byte_arr).reshape((height, width, channels)) image_raw = image.tostring()
然后序列化为tfrecords文件
writer = tf.python_io.TFRecordWriter(tfr_name) example = tf.train.Example(features=tf.train.Features(feature{'height':int64_feature(height), 'width': int64_feature(width), 'channels': int64_feature(channels), 'image_raw': bytes_feature(image_raw), writer.write(example.SerializeToString()) writer.close()