我正在尝试最近的一项名为" 分解CNN "的arxiv作品,
主要认为空间分离卷积(深度卷积)与信道方向线性投影(1x1conv)一起可以加速卷积运算.
我发现我可以用tf.nn.depthwise_conv2d和1x1卷积,或者用tf.nn.separable_conv2d来实现这个架构.
以下是我的实施:
#conv filter for depthwise convolution
depthwise_filter = tf.get_variable("depth_conv_w", [3,3,64,1], initializer=tf.random_normal_initializer(stddev=np.sqrt(2.0/9/32)))
#conv filter for linear channel projection
pointwise_filter = tf.get_variable("point_conv_w", [1,1,64,64], initializer=tf.random_normal_initializer(stddev=np.sqrt(2.0/1/64)))
conv_b = tf.get_variable("conv_b", [64], initializer=tf.constant_initializer(0))
#depthwise convolution, with multiplier 1
conv_tensor = tf.nn.relu(tf.nn.depthwise_conv2d(tensor, depthwise_filter, [1,1,1,1], padding='SAME'))
#linear channel projection with 1x1 convolution
conv_tensor = tf.nn.bias_add(tf.nn.conv2d(conv_tensor, pointwise_filter, [1,1,1,1], padding='VALID'), conv_b)
#residual
tensor = tf.add(tensor, conv_tensor)Run Code Online (Sandbox Code Playgroud)
这应该比原始的3x3x64 - > 64通道卷积快9倍左右.
但是,我无法体验任何性能提升.
我必须假设我做错了,或者说tensorflow的实现有问题.
由于使用depthwise_conv2d的例子很少,我在这里留下这个问题.
这种慢速是否正常?或者有任何错误吗?