本文介绍了在ImageDataGenerator中添加自定义预处理功能以实现高斯模糊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Image Data Generator扩展我的数据集.
I am using Image Data Generator to extend my dataset.
train_generator = train_datagen.flow_from_directory(
path_to_train,
target_size=(150, 150),
batch_size=32,
class_mode = "sparse",
color_mode="grayscale")
然后
history = model.fit(
train_generator,
steps_per_epoch=20,
epochs=100
)
问题是我想对输入图像应用某些方法.我想使用高斯模糊等.但是,当我直接加载它并使用模型拟合时,如何应用它.
The problem is that I want to apply some methods to the input images.I want to use Gaussian bluring and etc.But how can I apply it when I directly load it and use model fit.
能帮我吗?谢谢您的建议.
Can you help me please? Thanks for you advices.
推荐答案
您可以通过 tfa.image.gaussian_filter2d
:
You can do this with tfa.image.gaussian_filter2d
:
@tf.function
tfa.image.gaussian_filter2d(
image: tfa.types.TensorLike,
filter_shape: Union[List[int], Tuple[int], int] = [3, 3],
sigma: Union[List[float], Tuple[float], float] = 1.0,
padding: str = 'REFLECT',
constant_values: tfa.types.TensorLike = 0,
name: Optional[str] = None
) -> tfa.types.TensorLike
您可以在 ImageDataGenerator
中传递此函数:
You can pass this function in ImageDataGenerator
:
img_gen = ImageDataGenerator(
proprocessing_function=tfa.image.gaussian_filter2d
)
这篇关于在ImageDataGenerator中添加自定义预处理功能以实现高斯模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!