如何使用ImageDataGenerator进行固定转换? [英] How do I use ImageDataGenerator to do fixed transformations?

查看:83
本文介绍了如何使用ImageDataGenerator进行固定转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ImageDataGenerator.flow_from_directory执行10个测试的时间增加.基本函数中的参数执行随机扩充,而不是固定的扩充.

I am trying perform 10-crop test time augmentation with ImageDataGenerator.flow_from_directory. The arguments in the base function performs random augmentations not fixed ones.

因此,我研究了使用ImageDataGenerator中的apply_transform方法.但是,它需要x和转换参数.如何将它与flow_from_directory连接?

So I looked into using the apply_transform method from ImageDataGenerator. However, it takes x, and the transformation arguments. How do I connect this with flow_from_directory?

推荐答案

使用 apply_transform 方法,我们可以将任何所需的变换应用于图像.

Using apply_transform method, we can apply any desired transformations to an image.

apply_transform(x, transform_parameters)

根据变换参数将变换应用于x(3D张量,单个图像).

Applies a transformation to x (3D tensor, single image) according to the transform parameters.

transform_parameters 是一个字典,用于指定要应用的一组转换.当前,可以进行以下转换

The transform_parameters is a dictionary specifying the set of transformations to be applied. Currently, the following transformations are available

- `'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_transform ImageDataGenerator 类中的一种方法.因此,首先我们必须创建此类的实例,然后按如下所示应用此方法

Because apply_transform is a method inside the ImageDataGenerator class. so, first we have to create the instance of this class and then apply this method as below

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})

有关更多信息,请参阅此博客.

For more information please refer this blog.

这篇关于如何使用ImageDataGenerator进行固定转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆