Python 为每个图像创建TFR记录
目前,我有一个程序,它创建一个TFRecord,其中包含来自目录的所有图像(作为数组字符串)。如何在单个TFRecord文件中包含每个图像阵列数据,而不是将所有图像阵列数据包含在一个TFRecord中?E.X.我有30个图像,我将它们转换为数组(numpy)-->我得到30个TFRecord文件 这是我的密码:Python 为每个图像创建TFR记录,python,arrays,numpy,tensorflow,Python,Arrays,Numpy,Tensorflow,目前,我有一个程序,它创建一个TFRecord,其中包含来自目录的所有图像(作为数组字符串)。如何在单个TFRecord文件中包含每个图像阵列数据,而不是将所有图像阵列数据包含在一个TFRecord中?E.X.我有30个图像,我将它们转换为数组(numpy)-->我得到30个TFRecord文件 这是我的密码: from PIL import Image import numpy as np import tensorflow as tf from tqdm import tqdm import
from PIL import Image
import numpy as np
import tensorflow as tf
from tqdm import tqdm
import os
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]))
tfrecords_filename = 'image001.tfrecords'
writer = tf.python_io.TFRecordWriter(tfrecords_filename)
path_to_images = 'images_animation'
#List of images - method of accessing images
filenum = len([name for name in os.listdir(path_to_images) if os.path.isfile(os.path.join(path_to_images, name))])
#Collect the real images to later on compare
#to the reconstructed ones
original_images = []
for p in range(1, filenum):
fname = "images_animation/image%03d.png" % p
img = np.array(Image.open(fname))
# Put in the original images into array
# Just for future check for correctness
original_images.append((img))
img_raw = img.tostring()
example = tf.train.Example(features=tf.train.Features(feature={
'image_raw': _bytes_feature(img_raw)}))
writer.write(example.SerializeToString())
writer.close()
为每个图像创建具有不同文件名的单个读取器为每个图像创建具有不同文件名的单个读取器