这里我想将增强的图片保存到一个目录。但使用下面的代码不会发生这种情况。我是初学者,请帮忙。提前谢谢。
import tensorflow as tf
import matplotlib.pyplot as plt
import os
import cv2
import numpy as np
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.preprocessing import image
train_datagen = ImageDataGenerator(
rescale=1./255,
shear_range=0.2,
validation_split=0.2,
zoom_range=0.2,
horizontal_flip=True,
brightness_range=[0.2,1.0],
)
train_generator = train_datagen.flow_from_directory(
r'C:UsersMahmudul HasanDesktoppractice',
target_size=(150, 150),
batch_size=32,
class_mode='categorical',
seed=42,
subset="training",
save_to_dir=r"C:UsersMahmudul HasanDesktopAugmented data" )
train_datagen.flow_from_directory
给出了一个生成器。要真正生成图像,请使用以下示例代码:
i = 0
for batch in train_datagen.flow_from_directory(input_dir, target_size=(150, 150),
class_mode='binary', shuffle=False,
save_to_dir=output_dir, save_prefix='aug'):
i += 1
if i > 20:
break