Ton*_*hen 9 python deep-learning tensorflow
我创建了一个数据集并将其保存到TFRecord文件中.事情是图片有不同的大小,所以我想保存大小以及图像.所以我使用了TFRecordWriter并定义了以下功能:
example = tf.train.Example(features=tf.train.Features(feature={
'rows': _int64_feature(image.shape[0]),
'cols': _int64_feature(image.shape[1]),
'image_raw': _bytes_feature(image_raw)}))
Run Code Online (Sandbox Code Playgroud)
我希望我可以使用TFRecordReader读取和解码图像,但问题是我无法从文件中获取行和列的值,因为它们是张量.那么我该如何动态地读取大小并相应地重塑图像.多谢你们
您可以tf.reshape使用动态shape参数进行调用.
image_rows = tf.cast(features['rows'], tf.int32)
image_cols = tf.cast(features['cols'], tf.int32)
image_data = tf.decode_raw(features['image_raw'], tf.uint8)
image = tf.reshape(image_data, tf.pack([image_rows, image_cols, 3]))
Run Code Online (Sandbox Code Playgroud)