python - 如何查看自定义层中的图像如何更改
问题描述
嗨,我想问一下如何在自定义 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)
解决方案
推荐阅读
- python - 如何使用正则表达式和 python 在文本文件中用 bar 替换 foo?
- python-3.x - 如何在 Python 中通过 API 调用下载 JSON?
- sql - 由于多组如何设置标志
- c# - 使用 WASD 和 Look to Mouse 制作角色动画的最佳方法
- sockets - 如何在 Windows 上手动安装 Octave 包 socket-1.2.0?
- r - 如何将表格从列布局传递到 R 中的行布局?
- python - 泊松分布后的随机数生成
- c - 无法在 Linux 上的 VSCode 中打开源文件 (ms-vscode.cpptools)
- matlab - MOSEK:prob.a 未指定
- r - 在 `pivot_wider()` 之后从数据框中删除冗余/重复的列