ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2019-07-26 15:00:07  阅读:1160  来源: 互联网

标签:24 kernel 面试题 depthwise 卷积 channels 深度 tf conv2d


目录

  举例

  单个张量与多个卷积核在深度上分别卷积

  参考资料


 

举例

如下张量x和卷积核K进行depthwise_conv2d卷积

 

结果为:

depthwise_conv2d和conv2d的不同之处在于conv2d在每一深度上卷积,然后求和,depthwise_conv2d没有求和这一步,对应代码为:

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]
kernel = tf.reshape(tf.constant([3,1,-2,2,-1,-3,4,5], tf.float32),[2,2,2,1])

print(tf.Session().run(tf.nn.depthwise_conv2d(input,kernel,[1,1,1,1],"VALID")))
[[[[ -2.  18.]
   [ 12.  21.]]

  [[ 17.  -7.]
   [-13.  16.]]]]
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]
kernel = 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])

print(tf.Session().run(tf.nn.depthwise_conv2d(input,kernel,[1,1,1,1],"VALID")))
[[[[ -2.  32.  -7.  18.  26.  40.]
   [ 12.  52.  -8.  21.  31.  19.]]

  [[ 17.  41.   0.  -7. -32.  52.]
   [-13.  11. -34.  16.  29.  29.]]]]
View Code

 返回目录

 

参考资料

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

 返回目录

 

标签:24,kernel,面试题,depthwise,卷积,channels,深度,tf,conv2d
来源: https://www.cnblogs.com/itmorn/p/11250371.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有