方法1:tf.keras.preprocessing.image_dataset_from_directory
train = tf.keras.preprocessing.image_dataset_from_directory(
directory= './data/', # 数据路径
label_mode = 'categorical', # int-0124 cat-[0001] bin - [01]
color_mode = 'rgb', # 颜色模式rgba通道,gray单通道
image_size = (28,28), # 图片大小
shuffle = True, # 是否打乱数据,训练集-数据打乱
seed = 123,
validation_split = 0.2,
subset = 'training') # 选择划分后的训练集
对测试集的划分只用修改subset为validation
方法2:tf.keras.preprocessing.image.ImageDataGenerator
gen = tf.keras.preprocessing.image.ImageDataGenerator(
rotation_range = 45, # 旋转范围
zoom_range = 0.3, # 随机放大缩小的范围
horizontal_flip = True, # 水平方向翻转
vertical_flip = True, # 垂直方向翻转
rescale = 1./