我目前正在使用数据增强功能构建自己的自定义生成器。我必须对两个图像(火车一幅和目标一张)应用相同的变换,但是功能只能一张一张地工作。有什么想法如何在两个图像中应用确切的变换? 这是我正在尝试的功能:
tf.keras.preprocessing.image.random_zoom
生成器的代码:
def generator(data, batch_size = 32, data_augmentation = False):
batch_number = 0
while True:
original_train = []
original_target = []
train = []
target = []
if batch_number * batch_size >= data.shape[0]:
batch_number = 0
for x in train_pd.values[batch_number * batch_size: (batch_number + 1) * batch_size ]:
train_image = load_image_as_array(train_path+'images/'+x[0]+'.png').reshape(101,101,1)
target_image = load_image_as_array(train_path+'masks/'+x[0]+'.png').reshape(101,101,1)
original_train.append(train_image)
original_target.append(target_image)
if data_augmentation:
train_image = random_zoom(train_image, (.25,.25))
target_image = random_zoom(target_image, (.25,.25))
train.append(train_image)
target.append(target_image)
batch_number += 1
yield np.array(train), np.array(target), np.array(original_train), np.array(original_target)
答案 0 :(得分:0)
好的。除了您两次调用该函数外,它似乎还应用了精确的转换。