为fit_generator创建自定义生成器

时间:2019-08-16 15:41:29

标签: tensorflow keras

我正在尝试为美学图像分类器创建自定义生成器函数。我在generator函数中的实际代码是:

with tf.compat.v1.Session() as sess:            
            if (train):       
                dataset_paths_placeholder = tf.compat.v1.placeholder(train_image_paths.dtype, train_image_paths.shape)
                dataset_scores_placeholder = tf.compat.v1.placeholder(train_scores.dtype, train_scores.shape)
            else:
                dataset_paths_placeholder = tf.compat.v1.placeholder(val_image_paths.dtype, val_image_paths.shape)
                dataset_scores_placeholder = tf.compat.v1.placeholder(val_scores.dtype, val_scores.shape)

            dataset = tf.compat.v1.data.Dataset.from_tensor_slices((dataset_paths_placeholder, dataset_scores_placeholder))

            #Here I parse the dataset, basically the path is substituted with the actual image
            if(train):
                dataset = dataset.map(parse_with_augmentation, num_parallel_calls = tf.data.experimental.AUTOTUNE)
            else:
                dataset = dataset.map(parse_without_augmentation, num_parallel_calls = tf.data.experimental.AUTOTUNE)
            dataset = dataset.batch(batchsize)
            dataset = dataset.repeat(count = -1)
            if (shuffle):
                dataset = dataset.shuffle(buffer_size=10)  

我最初的计划是在数据集上创建一个迭代器,然后在循环中检索X,y批次并产生它们。 问题在于在数据集上使用make_initializable_iterator()的信号已被弃用,建议使用for循环来检索元素。

是否有一种简单的方法可以从我的数据集中检索所有批次并像这样产生它们?

0 个答案:

没有答案