首页 > 解决方案 > 如何查看自定义层中的图像如何更改

问题描述

嗨,我想问一下如何在自定义 Keras 层中查看我的图像发生了什么。我的图层是图层类的子类。我在图层中的调用函数看起来像这样。

    def call(self, inputs, **kwargs):
    if self.horizontal is True and self.vertical is True:
        flipped = tf.image.flip_left_right(image=inputs)
        flipped = tf.image.flip_up_down(image=flipped)
    elif self.horizontal is True:
        flipped = tf.image.flip_left_right(image=inputs)
    elif self.vertical is True:
        flipped = tf.image.flip_up_down(image=inputs)
    else:
        flipped = inputs

    flipped = tf.reshape(flipped, shape=[-1, 64, 64, 1])
    return flipped

我发现了一些用于在模型中可视化图像的代码,但它似乎什么也没做。我的意思是如果我使用看起来像这样的旋转层

    def call(self, inputs, **kwargs):
    if self.lower_bound is not None and self.upper_bound is not None:
        angle = (random.randint(self.lower_bound,self.upper_bound))*math.pi/180
        rotated = tfa.image.rotate(inputs, angles=round(angle),fill_mode='wrap')
    elif self.lower_bound is not None:
        angle = (random.randint(self.lower_bound,360))*math.pi/180
        rotated = tfa.image.rotate(inputs, angles=round(angle),fill_mode='wrap')
    elif self.upper_bound is not None:
        angle = (random.randint(-360,self.upper_bound))*math.pi/180
        rotated = tfa.image.rotate(inputs, angles=round(angle),fill_mode='wrap')
    else:
        angle = (random.randint(-360,360))*math.pi/180
        rotated = tfa.image.rotate(inputs, angles=round(angle),fill_mode='wrap')
    rotated = tf.reshape(rotated, shape=[-1, 64, 64, 1])
    return rotated

我可以看到图像被旋转但如果我使用翻转我看不到图像的变化。

flipLayer = VargaFlipLayer(None, vertical=True, horizontal=True ,input_shape=(64, 64, 1))
rotatioLayer = VargaRotationLayer(None,input_shape=(64, 64, 1), upper_bound=10, lower_bound=-10)
model = Sequential()
model.add(flipLayer)
model.add(rotatioLayer)

标签: pythonkerasdeep-learningkeras-layer

解决方案


推荐阅读