Python 如何使用ImageDataGenerator进行固定转换?

Python 如何使用ImageDataGenerator进行固定转换?,python,tensorflow,image-processing,neural-network,conv-neural-network,Python,Tensorflow,Image Processing,Neural Network,Conv Neural Network,我正在尝试使用来自\u目录的ImageDataGenerator.flow\u执行10次裁剪测试时间扩展。基函数中的参数执行随机增强,而不是固定增强 因此,我研究了使用ImageDataGenerator中的apply_transform方法。但是,它需要x和转换参数。如何将其与来自目录的流连接?使用此方法,我们可以对图像应用任何所需的转换 apply_transform(x, transform_parameters) 根据变换参数将变换应用于x(三维张量,单个图像) transform\u

我正在尝试使用来自\u目录的ImageDataGenerator.flow\u执行10次裁剪测试时间扩展。基函数中的参数执行随机增强,而不是固定增强

因此,我研究了使用ImageDataGenerator中的apply_transform方法。但是,它需要x和转换参数。如何将其与来自目录的流连接?

使用此方法,我们可以对图像应用任何所需的转换

apply_transform(x, transform_parameters)
根据变换参数将变换应用于x(三维张量,单个图像)

transform\u参数
是一个字典,指定要应用的转换集。目前,以下转换可用

- `'theta'`: Float. Rotation angle in degrees.
- `'tx'`: Float. Shift in the x direction.
- `'ty'`: Float. Shift in the y direction.
- `'shear'`: Float. Shear angle in degrees.
- `'zx'`: Float. Zoom in the x direction.
- `'zy'`: Float. Zoom in the y direction.
- `'flip_horizontal'`: Boolean. Horizontal flip.
- `'flip_vertical'`: Boolean. Vertical flip.
- `'channel_shift_intensity'`: Float. Channel shift intensity.
- `'brightness'`: Float. Brightness shift intensity.
因为
apply\u transform
ImageDataGenerator
类中的一个方法。因此,首先我们必须创建这个类的实例,然后应用这个方法,如下所示

from tf.keras.preprocessing.image import ImageDataGenerator, load_img, img_to_array
img = load_img('/content/bird.jpg')
img = img_to_array(img)
datagen = ImageDataGenerator()
rotate = datagen.apply_transform(x=img, transform_parameters={'theta':30, 'brightness':0.6, 'zx':0.9, 'zy':0.8})
有关更多信息,请参阅此。

使用方法,我们可以对图像应用任何所需的变换

apply_transform(x, transform_parameters)
根据变换参数将变换应用于x(三维张量,单个图像)

transform\u参数
是一个字典,指定要应用的转换集。目前,以下转换可用

- `'theta'`: Float. Rotation angle in degrees.
- `'tx'`: Float. Shift in the x direction.
- `'ty'`: Float. Shift in the y direction.
- `'shear'`: Float. Shear angle in degrees.
- `'zx'`: Float. Zoom in the x direction.
- `'zy'`: Float. Zoom in the y direction.
- `'flip_horizontal'`: Boolean. Horizontal flip.
- `'flip_vertical'`: Boolean. Vertical flip.
- `'channel_shift_intensity'`: Float. Channel shift intensity.
- `'brightness'`: Float. Brightness shift intensity.
因为
apply\u transform
ImageDataGenerator
类中的一个方法。因此,首先我们必须创建这个类的实例,然后应用这个方法,如下所示

from tf.keras.preprocessing.image import ImageDataGenerator, load_img, img_to_array
img = load_img('/content/bird.jpg')
img = img_to_array(img)
datagen = ImageDataGenerator()
rotate = datagen.apply_transform(x=img, transform_parameters={'theta':30, 'brightness':0.6, 'zx':0.9, 'zy':0.8})
有关更多信息,请参阅此