简体   繁体   English

Tensorflow dataset.from_generator():如何检查加载了哪些数据?

[英]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.npyimage5.npyimage6.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.

相关问题 Tensorflow Dataset.from_generator块输入? - Tensorflow Dataset.from_generator blocks input? 调用TensorFlow的Dataset.from_generator方法 - Calling TensorFlow's Dataset.from_generator method Tensorflow Dataset.from_generator因pyfunc异常而失败 - Tensorflow Dataset.from_generator fails with pyfunc exception Tensorflow 2.0中不推荐使用Tensorflow Dataset.from_generator吗? 抛出tf.py_func弃用错误 - Is Tensorflow Dataset.from_generator deprecated in tensorflow 2.0 ? It throws tf.py_func deprecation error 我无法使用使用 Pandas Dataframes 作为参数的生成器创建 Dataset.from_generator() - I can't create a Dataset.from_generator() with generator that uses pandas Dataframes as arguments Dataset.from_generator:TypeError:`generator` 必须是可调用的 - Dataset.from_generator: TypeError: `generator` must be callable 如何从生成器编写数据集以替换 tensorflow 中切片中的数据集,以获取具有 X_train 和 y_train 的表格数据集 - How do I write a Dataset from generator to replace Dataset from slices in tensorflow for a tabular data set with X_train and y_train Tensorflow 数据集如何获取数据生成器的形状? - Tensorflow dataset how to get the shape of the generator of data? TF-Keras - Dataset.from_generator 用于多输入功能 API model - TF-Keras - Dataset.from_generator for multi-input functional API model 来自生成器的张量流数据集 - tensorflow dataset from generator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM