如何使用 Keras 预处理层创建额外的训练图像?
How to create additional training images with Keras preprocessing layers?
我正在关注有关图像分类的官方 Tensorflow/Keras 文档,尤其是 the section on image augmentation。上面写着:
Data augmentation takes the approach of generating additional training data from your existing examples by augmenting then using random transformations that yield believable-looking images. This helps expose the model to more aspects of the data and generalize better.
所以我对此的理解是——例如,如果我没有很多训练图像——我想通过在现有训练图像之外创建新的增强图像来生成额外的训练数据。
然后在上面链接的 Keras 文档中显示了如何将来自 layers.experimental.preprocessing
模块的一些预处理层作为第一层添加到示例的 Sequential
模型中。因此,从理论上讲,这些新的预处理层在“输入”真实 TF 模型之前会增加输入数据(=图像)。
但是,如上所述,我想我们要做的是创建 额外的 图像,即为现有训练图像创建更多新图像。但是模型中的这样一组预处理层如何创建额外的图像呢?他们不会在输入模型之前简单地(随机地)扩充现有的训练图像,但不创建新的附加图像吗?
它正在创建额外的图像,但这并不一定意味着它会创建新的 jpg
文件。
如果这是你想要做的,ImageDataGenerator
可以用 save_to_dir
参数做到这一点。
Wouldn't they simple (randomly) augment the existing training images before the enter the model, but not create new, additional images?
是的,它会创建新图像。但它不会在您的机器上创建新文件。你可以使用这个:
ImageDataGenerator.flow_from_directory(directory, target_size=(256, 256), save_to_dir=None, save_prefix='', save_format='png'
)
我正在关注有关图像分类的官方 Tensorflow/Keras 文档,尤其是 the section on image augmentation。上面写着:
Data augmentation takes the approach of generating additional training data from your existing examples by augmenting then using random transformations that yield believable-looking images. This helps expose the model to more aspects of the data and generalize better.
所以我对此的理解是——例如,如果我没有很多训练图像——我想通过在现有训练图像之外创建新的增强图像来生成额外的训练数据。
然后在上面链接的 Keras 文档中显示了如何将来自 layers.experimental.preprocessing
模块的一些预处理层作为第一层添加到示例的 Sequential
模型中。因此,从理论上讲,这些新的预处理层在“输入”真实 TF 模型之前会增加输入数据(=图像)。
但是,如上所述,我想我们要做的是创建 额外的 图像,即为现有训练图像创建更多新图像。但是模型中的这样一组预处理层如何创建额外的图像呢?他们不会在输入模型之前简单地(随机地)扩充现有的训练图像,但不创建新的附加图像吗?
它正在创建额外的图像,但这并不一定意味着它会创建新的 jpg
文件。
如果这是你想要做的,ImageDataGenerator
可以用 save_to_dir
参数做到这一点。
Wouldn't they simple (randomly) augment the existing training images before the enter the model, but not create new, additional images?
是的,它会创建新图像。但它不会在您的机器上创建新文件。你可以使用这个:
ImageDataGenerator.flow_from_directory(directory, target_size=(256, 256), save_to_dir=None, save_prefix='', save_format='png' )