【发布时间】:2020-08-07 17:10:31
【问题描述】:
我想转换这个 keras 数据增强工作流程:
datagen = ImageDataGenerator(
rescale=1./255,
rotation_range = 10,
horizontal_flip = True,
width_shift_range=0.1,
height_shift_range=0.1,
fill_mode = 'nearest')
这是一个代码 sn-p 但两个函数都不起作用,因为它不支持批量维度!
import numpy as np
def augment(x, y):
x = tf.keras.preprocessing.image.random_shift(x, 0.1, 0.1)
x = tf.keras.preprocessing.image.random_rotation(
x, 10, row_axis=1, col_axis=2, channel_axis=0, fill_mode='nearest', cval=0.0,
interpolation_order=1)
return x, y
X = np.random.random(size=(256, 48, 48, 1))
y = np.random.randint(0, 7, size=(256,))
dataset = tf.data.Dataset.from_tensor_slices((X, y))
dataset = dataset.map(augment)
dataset = dataset.batch(16, drop_remainder=False)
dataset = dataset.prefetch(buffer_size=1)
【问题讨论】:
标签: keras tensorflow2.0 tensorflow-datasets data-augmentation