python - 我是否获得了 tf.nn.depthwise_conv2d() 的正确输出?
问题描述
我正在尝试创建自己的深度可分离卷积,并且我想针对 tensorflow 实现对其进行测试,但我不知道我是否让它正常工作。这是我的代码
首先,我创建图像和深度过滤器。图像是 2 个通道,每个通道是 3x3。过滤器也是 2 个通道,3x3。两个过滤器上的过滤器具有相同的值,而图像通道的值略有不同。
depth_filter = np.array([ [[0,-1,0],[-1,5,-1],[0,-1,0]],
[[0,-1,0],[-1,5,-1],[0,-1,0]]],
np.float32)
image = np.array([ [[102,109,124],[99,98,98],[103,103,98]],
[[101,108,123],[98,97,97],[102,102,97]]],
np.float32)
然后我设置了一些变量来让我自己轻松一点。
C = image.shape[0]
H = image.shape[1]
W = image.shape[2]
R_H = depth_filter.shape[1]
R_W = depth_filter.shape[2]
然后我重塑我的矩阵,以便它们可以用于 tensorflow 的实现。
kernel = tf.reshape(depth_filter, [R_H,R_W,C,1], name='kernel')
imageconv = tf.reshape(image, [1,H,W,C], name='imageconv')
dout = tf.nn.depthwise_conv2d(imageconv, kernel, [1,1,1,1], padding='SAME')
问题是我得到了这个输出
[[[-325. 0.]
[-407. 406.]
[-206. 406.]]
[[ 327. -208.]
[ 85. 76.]
[-199. 212.]]
[[ 393. -204.]
[ 438. -424.]
[ 0. -326.]]]
我期望得到 2 个 3x3 矩阵,其中内核上的通道 1 将过滤通道 1 图像,内核上的通道 2 将过滤通道 2 图像。当每个通道只有 1 个通道时,我会得到 1 个 3x3 图像。我是不了解深度卷积的工作原理还是我做错了什么。
解决方案
推荐阅读
- python - SPARK 2.4.4 中的 log4j.properties
- vue.js - Vuetify:在我的 v-data-table 顶部以及页脚中显示分页控件
- twitter-bootstrap - 侧边栏导航栏 twitter 引导程序仅在 xs 屏幕上切换
- java - 使用 glide 空指针异常选择图像从画廊到 imageview
- php - 如何有效地检索 Mysql 表的前 20 个引用值以及 PHP
- perl - 在 Linux 的 Windows 子系统上安装 Bio::Grep 失败
- go - Go 接口在方法之间强制执行相同的参数类型(但可以是任何类型)
- c# - 如何检查是否在 Sharepoint 团队网站中使用 CSOM 检查了“允许访问请求”
- html - 需要帮助使按钮的左侧向左流动
- sql - 是否可以在 SQL 查询中将 24 小时时间戳转换为秒?