[英]Tensorflow dataset.from_generator(): how do I check which data is loaded?
I am creating a tensorflow dataset (in tensorflow 1.15) using a generator that loads images from a folder.我正在使用从文件夹加载图像的生成器创建一个 tensorflow 数据集(在 tensorflow 1.15 中)。
I want to know what images I am using, so I print their filename when I load one.我想知道我使用的是什么图像,所以我在加载图像时打印它们的文件名。
A simplified version of the generator that I use is the following:我使用的生成器的简化版本如下:
def gen():
for i in itertools.count(0):
data = np.load(list_of_file_names[i])
print(f'image_name[{i}]: {list_of_file_names[i]}')
yield tf.convert_to_tensor(data)
Where list_of_file_names
is the sorted list of .npy
files in a certain folder: image0.npy, image1.npy, image2.npy, image3.npy, image4.npy, image5.npy, image6.npy, image7.npy
...其中list_of_file_names
是某个文件夹中.npy
文件的排序列表: image0.npy, image1.npy, image2.npy, image3.npy, image4.npy, image5.npy, image6.npy, image7.npy
...
This is a simplified version of the input_fn
function that I use for my estimator.predict()
:这是我用于estimator.predict()
的input_fn
function 的简化版本:
def input_fn():
dataset = tf.data.Dataset.from_generator(gen, (tf.float32))
dataset = dataset.batch(batch_size, drop_remainder=True)
return dataset.make_one_shot_iterator().get_next()
This is the result from the print statement inside the generator:这是生成器中打印语句的结果:
image_name[0]: image0.npy
image_name[1]: image1.npy
image_name[2]: image2.npy
image_name[3]: image3.npy
2022-12-12 15:48:10.276336: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.8
image_name[4]: image4.npy
image_name[5]: image5.npy
I apply a batch size of 3 to my dataset.我将批量大小为 3 应用于我的数据集。
When I process a batch of data, the result is computed on a batch made of the files relative to image4.npy
, image5.npy
and image6.npy
(also contained in the folder).当我处理一批数据时,结果是根据与image4.npy
、 image5.npy
和image6.npy
(也包含在文件夹中)相关的文件组成的批次计算的。
Why is the name of image6.npy
not printed?为什么没有打印image6.npy
的名称?
Why are the names of the other (previous) files printed?为什么打印其他(先前)文件的名称?
image4,image5, image6 correspond to image3.npy,image4.npy, image5.npy respectively as the index starts from 0. image4、image5、image6分别对应image3.npy、image4.npy、image5.npy,索引从0开始。
Your image6
file name is image5.npy
你的image6
文件名是image5.npy
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.