Keras 的 ImagePreprocessing
类提供了一系列用于图像数据预处理的方法,这些方法可以用于数据增强、标准化等。
主要功能
- 数据增强:通过旋转、缩放、翻转等方式增加数据多样性。
- 标准化:将图像数据转换为 [0, 1] 或 [-1, 1] 的范围。
使用方法
from tensorflow.keras.preprocessing.image import ImagePreprocessing
preprocessor = ImagePreprocessing(
rotation_range=20,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
fill_mode='nearest'
)
# 应用预处理
img = preprocessor.fit_transform(img)
更多关于 Keras 预处理图像的详细使用说明,请参阅官方文档。
扩展阅读
图像预处理示例
的中心图像
ImagePreprocessing 示例
请注意,以上代码示例仅供参考,实际应用时请根据具体需求进行调整。