深度学习面试题25:分离卷积(separable卷积)

Posted mfryf

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了深度学习面试题25:分离卷积(separable卷积)相关的知识,希望对你有一定的参考价值。

目录

  举例

  单个张量与多个卷积核的分离卷积

  参考资料


 

举例

技术图片

分离卷积就是先在深度上分别卷积,然后再进行卷积,对应代码为:

技术图片
import tensorflow as tf

# [batch, in_height, in_width, in_channels]
input =tf.reshape(tf.constant([2,5,3,3,8,2,6,1,1,2,5,4,7,9,2,3,-1,3], tf.float32),[1,3,3,2])

# [filter_height, filter_width, in_channels, out_channels]
depthwise_filter = tf.reshape(tf.constant([3,1,-2,2,-1,-3,4,5], tf.float32),[2,2,2,1])
pointwise_filter = tf.reshape(tf.constant([-1,1], tf.float32),[1,1,2,1])

print(tf.Session().run(tf.nn.separable_conv2d(input,depthwise_filter,pointwise_filter,[1,1,1,1],"VALID")))
[[[[ 20.]
   [  9.]]

  [[-24.]
   [ 29.]]]]
View Code

 返回目录

 

单个张量与多个卷积核的分离卷积

 技术图片

对应代码为:

技术图片
import tensorflow as tf

# [batch, in_height, in_width, in_channels]
input =tf.reshape(tf.constant([2,5,3,3,8,2,6,1,1,2,5,4,7,9,2,3,-1,3], tf.float32),[1,3,3,2])

# [filter_height, filter_width, in_channels, out_channels]
depthwise_filter = tf.reshape(tf.constant([3,1,-3,1,-1,7,-2,2,-5,2,7,3,-1,3,1,-3,-8,6,4,6,8,5,9,-5], tf.float32),[2,2,2,3])
pointwise_filter = tf.reshape(tf.constant([0,0,1,0,0,1,0,0,0,0,0,0], tf.float32),[1,1,6,2])

print(tf.Session().run(tf.nn.separable_conv2d(input,depthwise_filter,pointwise_filter,[1,1,1,1],"VALID")))
[[[[ 32.  -7.]
   [ 52.  -8.]]

  [[ 41.   0.]
   [ 11. -34.]]]]
View Code

 返回目录

 

参考资料

《图解深度学习与神经网络:从张量到TensorFlow实现》_张平

 返回目录

 

以上是关于深度学习面试题25:分离卷积(separable卷积)的主要内容,如果未能解决你的问题,请参考以下文章

深度可分离卷积(depthwise separable convolution)参数计算

深度学习面试题24:在每个深度上分别卷积(depthwise卷积)

深度学习面试题27:非对称卷积(Asymmetric Convolutions)

深度学习面试题09:一维卷积(Full卷积Same卷积Valid卷积带深度的一维卷积)

深度学习面试题15:卷积核需要旋转180度

深度学习面试题19:1*1卷积核的作用