当前位置:网站首页>tensorflow2.0 cnn(layerwise)
tensorflow2.0 cnn(layerwise)
2022-07-31 15:55:00 【Full stack programmer webmaster】
大家好,又见面了,我是你们的朋友全栈君.
实验环境:tensorflow版本1.2.0,python2.7
介绍
depthwise_conv2dDerived from depthwise separable convolution:
Xception: Deep Learning with Depthwise Separable Convolutions
tf.nn.depthwise_conv2d(input,filter,strides,padding,rate=None,name=None,data_format=None)除去name参数用以指定该操作的name,data_format指定数据格式,与方法有关的一共五个参数:
- input: 指需要做卷积的输入图像,要求是一个4维Tensor,具有
[batch, height, width, in_channels]这样的shape,具体含义是[训练时一个batch的图片数量, 图片高度, 图片宽度, 图像通道数] - filter: 相当于CNN中的卷积核,要求是一个4维Tensor,具有
[filter_height, filter_width, in_channels, channel_multiplier]这样的shape,具体含义是[卷积核的高度,卷积核的宽度,输入通道数,output convolution multiplier],The same goes for the third dimension herein_channels,就是参数value的第四维 - strides: The sliding step size of the convolution.
- padding: string类型的量,只能是”SAME”,”VALID”其中之一,This value determines how different edges are filled.
- rate: For a detailed explanation of this parameter, see 【Tensorflow】tf.nn.atrous_conv2d如何实现空洞卷积?
结果返回一个Tensor,shape为[batch, out_height, out_width, in_channels * channel_multiplier],Note that here the output channel becomesin_channels * channel_multiplier
实验
for image displaydepthwise_conv2d,We have to create custom input images and convolution kernels
img1 = tf.constant(value=[[[[1],[2],[3],[4]],[[1],[2],[3],[4]],[[1],[2],[3],[4]],[[1],[2],[3],[4]]]],dtype=tf.float32)
img2 = tf.constant(value=[[[[1],[1],[1],[1]],[[1],[1],[1],[1]],[[1],[1],[1],[1]],[[1],[1],[1],[1]]]],dtype=tf.float32)
img = tf.concat(values=[img1,img2],axis=3)filter1 = tf.constant(value=0, shape=[3,3,1,1],dtype=tf.float32)
filter2 = tf.constant(value=1, shape=[3,3,1,1],dtype=tf.float32)
filter3 = tf.constant(value=2, shape=[3,3,1,1],dtype=tf.float32)
filter4 = tf.constant(value=3, shape=[3,3,1,1],dtype=tf.float32)
filter_out1 = tf.concat(values=[filter1,filter2],axis=2)
filter_out2 = tf.concat(values=[filter3,filter4],axis=2)
filter = tf.concat(values=[filter_out1,filter_out2],axis=3)建立好了img和filter,You can do convolution
out_img = tf.nn.conv2d(input=img, filter=filter, strides=[1,1,1,1], padding='VALID')好了,Use a diagram to illustrate this process in detail
This is the normal convolution process,Let's look at depthwise convolution again.
out_img = tf.nn.depthwise_conv2d(input=img, filter=filter, strides=[1,1,1,1], rate=[1,1], padding='VALID')Now we can explain it visuallydepthwise_conv2d卷积了.See ordinary convolution,We apply convolution kernels to eachout_channelThe two channels of , respectively, are convolved and added to the two channels of the input,得到feature map的一个channel,而depthwise_conv2d卷积,We correspond to each onein_channel,Convolution to generate two respectivelyout_channel,所以获得的feature mapnumber of channels availablein_channel* channel_multiplier来表达,这个channel_multiplier,It can be understood as the fourth dimension of the convolution kernel.
代码清单
import tensorflow as tf
img1 = tf.constant(value=[[[[1],[2],[3],[4]],[[1],[2],[3],[4]],[[1],[2],[3],[4]],[[1],[2],[3],[4]]]],dtype=tf.float32)
img2 = tf.constant(value=[[[[1],[1],[1],[1]],[[1],[1],[1],[1]],[[1],[1],[1],[1]],[[1],[1],[1],[1]]]],dtype=tf.float32)
img = tf.concat(values=[img1,img2],axis=3)
filter1 = tf.constant(value=0, shape=[3,3,1,1],dtype=tf.float32)
filter2 = tf.constant(value=1, shape=[3,3,1,1],dtype=tf.float32)
filter3 = tf.constant(value=2, shape=[3,3,1,1],dtype=tf.float32)
filter4 = tf.constant(value=3, shape=[3,3,1,1],dtype=tf.float32)
filter_out1 = tf.concat(values=[filter1,filter2],axis=2)
filter_out2 = tf.concat(values=[filter3,filter4],axis=2)
filter = tf.concat(values=[filter_out1,filter_out2],axis=3)
out_img = tf.nn.depthwise_conv2d(input=img, filter=filter, strides=[1,1,1,1], rate=[1,1], padding='VALID')输出:
rate=1, VALID mode result:
[[[[ 0. 36. 9. 27.] [ 0. 54. 9. 27.]] [[ 0. 36. 9. 27.] [ 0. 54. 9. 27.]]]]发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/127979.html原文链接:https://javaforall.cn
边栏推荐
- leetcode303 Weekly Match Replay
- How to switch remote server in gerrit
- Vb how to connect mysql_vb how to connect to the database collection "advice"
- Implementing click on the 3D model in RenderTexture in Unity
- Bilateral filtering acceleration "recommended collection"
- MySQL database operations
- T - sne + data visualization parts of the network parameters
- Insert into data table to insert data
- mysql黑窗口~建库建表
- The 2nd China PWA Developer Day
猜你喜欢

C language "the third is" upgrade (mode selection + AI chess)
![[Meetup Preview] OpenMLDB+OneFlow: Link feature engineering to model training to accelerate machine learning model development](/img/f6/311d5a4c70993df6291250d2025d3f.jpg)
[Meetup Preview] OpenMLDB+OneFlow: Link feature engineering to model training to accelerate machine learning model development

C language - function

The use of border controls

基于Redis(SETNX)实现分布式锁,案例:解决高并发下的订单超卖,秒杀

「秋招系列」MySQL面试核心25问(附答案)

苹果官网样式调整 结账时产品图片“巨大化”

第05章 存储引擎【1.MySQL架构篇】【MySQL高级】

"Autumn Recruitment Series" MySQL Interview Core 25 Questions (with answers)

Browser's built-in color picker
随机推荐
【7.28】代码源 - 【Fence Painting】【合适数对(数据加强版)】
[MySQL] Mysql paradigm and the role of foreign keys
Internet banking stolen?This article tells you how to use online banking safely
Linux check redis version (check mongodb version)
Baidu cloud web speed playback (is there any website available)
自动化测试如何创造业务价值?
Single-cell sequencing workflow (single-cell RNA sequencing)
C语言-函数
工程水文学试卷
The arm button controls the flashing of the led light (embedded button experiment report)
苹果官网样式调整 结账时产品图片“巨大化”
11 pinia use
Website vulnerability repair service provider's analysis of unauthorized vulnerability
字符串反转的实现方法总结「建议收藏」
Implementing click on the 3D model in RenderTexture in Unity
删除 状态良好(恢复分区)的磁盘
After Grafana is installed, the web opens and reports an error
修改SQL语言实现Mysql 多表关联查询优化
Tencent Cloud Deployment----DevOps
Use of radiobutton