【发布时间】:2020-09-10 23:33:18
【问题描述】:
这是我的 sobel 过滤器代码:
def init_f(shape, dtype=None):
sobel_x = tf.constant([[-5, -4, 0, 4, 5], [-8, -10, 0, 10, 8], [-10, -20, 0, 20, 10], [-8, -10, 0, 10, 8], [-5, -4, 0, 4, 5]])
ker = np.zeros(shape, dtype)
ker_shape = tf.shape(ker)
kernel = tf.tile(sobel_x, ker_shape)//*Is this correct?*
return kernel
model.add(Conv2D(filters=30, kernel_size=(5,5), kernel_initializer=init_f, strides=(1,1), activation='relu'))
到目前为止,我已经成功地做到了这一点。 但是,这给了我错误:
Shape must be rank 2 but is rank 4 for 'conv2d_17/Tile' (op: 'Tile') with input shapes: [5,5], [4].
张量流版本:2.1.0
【问题讨论】:
-
请包含您的 tensorflow 版本,以便人们可以更轻松地查找 api。你为什么要使用 tf.tile 呢?从文档中,它用于创建一堆重复的元素。您已经创建了 5x5 内核,还需要重复什么?
-
您的 Conv2D 有 30 个过滤器,您似乎只需要 1 个过滤器?
-
我在这个问题上提到了 vijay m 的答案:stackoverflow.com/a/50913430/13368020
-
那30个过滤器应该怎么做呢?
标签: tf.keras conv-neural-network sobel