在使用Keras做图像分类时,我们构建数据集一般是使用flow from directory而不是直接加载整个数据集。
而使用flow from directory一般有两个办法。
tf.keras.preprocessing.image_dataset_from_directory(
directory,
labels="inferred",
label_mode="int",
class_names=None,
color_mode="rgb",
batch_size=32,
image_size=(256, 256),
shuffle=True,
seed=None,
validation_split=None,
subset=None,
interpolation="bilinear",
follow_links=False,
)
ImageDataGenerator.flow_from_directory
在构造完一个generator后从directory提取数据集。 有一个需要注意的问题是这两个方法都会rescale图片。而其中使用的默认方法是bilinear。所以当测试时rescale图片时应使用相同的方法。