Python 3.x 加SaltandPepper和高斯噪声的Keras实时增强

Python 3.x 加SaltandPepper和高斯噪声的Keras实时增强,python-3.x,image-processing,keras,deep-learning,Python 3.x,Image Processing,Keras,Deep Learning,我在用自定义方式修改Keras的ImageDataGenerator时遇到了麻烦,这样我就可以执行SaltAndPepper噪声和高斯模糊(他们不提供)。我知道这类问题以前被问过很多次,我已经阅读了下面几乎所有可能的链接: 但由于我无法理解完整的源代码或缺乏python知识;我正在努力在ImageDataGenerator中实现这两种额外的扩展类型,作为一种自定义扩展。我非常希望有人能为我指明正确的方向,告诉我如何修改源代码,或者其他任何方式 SaltAndPeppernoise

我在用自定义方式修改Keras的ImageDataGenerator时遇到了麻烦,这样我就可以执行SaltAndPepper噪声和高斯模糊(他们不提供)。我知道这类问题以前被问过很多次,我已经阅读了下面几乎所有可能的链接:

但由于我无法理解完整的源代码或缺乏python知识;我正在努力在ImageDataGenerator中实现这两种额外的扩展类型,作为一种自定义扩展。我非常希望有人能为我指明正确的方向,告诉我如何修改源代码,或者其他任何方式

SaltAndPepper
noise的示例如下,我希望在ImageDataGenerator中添加更多类型的增强:

class SaltAndPepperNoise:
    def __init__(self, replace_probs=0.1, pepper=0, salt=255, noise_type="RGB"):
        """
        It is important to know that the replace_probs here is the
        Probability of replacing a "pixel" to salt and pepper noise.
        """

        self.replace_probs = replace_probs
        self.pepper = pepper
        self.salt = salt
        self.noise_type = noise_type


    def get_aug(self, img, bboxes):
        if self.noise_type == "SnP":
            random_matrix = np.random.rand(img.shape[0], img.shape[1])
            img[random_matrix >= (1 - self.replace_probs)] = self.salt
            img[random_matrix <= self.replace_probs] = self.pepper
        elif self.noise_type == "RGB":
            random_matrix = np.random.rand(img.shape[0], img.shape[1], img.shape[2])
            img[random_matrix >= (1 - self.replace_probs)] = self.salt
            img[random_matrix <= self.replace_probs] = self.pepper
        return img, bboxes
class SaltAndPepperNoise:
def uuu init(self,replace_probs=0.1,pepper=0,salt=255,noise_type=“RGB”):
"""
重要的是要知道这里的替换问题是
将“像素”替换为椒盐噪声的概率。
"""
self.replace_probs=replace_probs
胡椒粉
self.salt=盐
self.noise\u type=noise\u type
def get_aug(自我、img、bboxes):
如果self.noise_type==“SnP”:
random_matrix=np.random.rand(img.shape[0],img.shape[1])
img[随机矩阵>=(1-自替换问题)]=自替换问题
img[随机矩阵=(1-自替换问题)]=自
随机矩阵