我正在尝试在 Keras 中创建图像去噪 ConvNet,并且我想创建自己的损失函数。我希望它将噪声图像作为输入并将噪声作为输出。这个损失函数很像 MSE 损失,但它会让我的网络学会从输入噪声图像中移除干净的图像而不是噪声。
我想用 y 噪声图像、x 干净图像和 R(y) 预测图像来实现的损失函数:
我试着自己做,但我不知道如何让我的嘈杂图像丢失,因为它一直在变化。
def residual_loss(noisy_img):
def loss(y_true, y_pred):
return np.mean(np.square(y_pred - (noisy_img - y_true), axis=-1)
return loss
基本上,我需要做的是这样的:
input_img = Input(shape=(None,None,3))
c1 = Convolution2D(64, (3, 3))(input_img)
a1 = Activation('relu')(c1)
c2 = Convolution2D(64, (3, 3))(a1)
a2 = Activation('relu')(c2)
c3 = Convolution2D(64, (3, 3))(a2)
a3 = Activation('relu')(c3)
c4 = Convolution2D(64, (3, 3))(a3)
a4 = Activation('relu')(c4)
c5 = Convolution2D(3, (3, 3))(a4)
out = Activation('relu')(c5)
model = Model(input_img, out)
model.compile(optimizer='adam', loss=residual_loss(input_img))
但是如果我尝试这个,我会得到:
IndexError: tuple index out of range
我能做些什么 ?