tensorflow实现卷积层的几种方式
#coding:utf-8 #第一种实现 tf.nn
import tensorflow as tf
import tensorflow.contrib.slim as slim tf.reset_default_graph()
image = tf.random_normal([1, 112, 96, 3])
in_channels = 3
out_channels = 32
kernel_size = 5 conv_weight = tf.Variable(tf.truncated_normal([kernel_size,kernel_size,in_channels,out_channels],
stddev=0.1, dtype=tf.float32)) bias = tf.Variable(tf.zeros([out_channels], dtype=tf.float32))
conv = tf.nn.conv2d(image, conv_weight, strides=[1, 2, 2, 1], padding='SAME')
conv = tf.nn.bias_add(conv,bias)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
convres = sess.run(conv)
print convres
print (conv.get_shape()) #第二种实现 tf.layers
truncated_norm_init = tf.truncated_normal_initializer(stddev=0.1, dtype=tf.float32)
zero_init = tf.zeros_initializer(dtype=tf.float32)
l2_regularizer = tf.contrib.layers.l2_regularizer(1.0)
conv = tf.layers.conv2d(image, out_channels, [kernel_size, kernel_size], strides=[2, 2], padding='SAME',
kernel_initializer=truncated_norm_init, bias_initializer=zero_init,
kernel_regularizer=l2_regularizer, bias_regularizer=l2_regularizer) with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
convres = sess.run(conv)
print convres
print (conv.get_shape()) #第三种实现 slim
conv = slim.conv2d(image, out_channels, [kernel_size, kernel_size], scope='conv1_1')
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
convres = sess.run(conv)
print convres
print (conv.get_shape())
tensorflow实现卷积层的几种方式的更多相关文章
- MyBatis开发Dao层的两种方式(原始Dao层开发)
本文将介绍使用框架mybatis开发原始Dao层来对一个对数据库进行增删改查的案例. Mapper动态代理开发Dao层请阅读我的下一篇博客:MyBatis开发Dao层的两种方式(Mapper动态代理方 ...
- MyBatis开发Dao层的两种方式(Mapper动态代理方式)
MyBatis开发原始Dao层请阅读我的上一篇博客:MyBatis开发Dao层的两种方式(原始Dao层开发) 接上一篇博客继续介绍MyBatis开发Dao层的第二种方式:Mapper动态代理方式 Ma ...
- 『TensorFlow』卷积层、池化层详解
一.前向计算和反向传播数学过程讲解
- TensorFlow的 卷积层
用 TensorFlow 做卷积 让我们用所学知识在 TensorFlow 里构建真的 CNNs.在下面的练习中,你需要设定卷积核滤波器(filters)的维度,weight,bias.这在很大程度上 ...
- CNN中卷积层的计算细节
原文链接: https://zhuanlan.zhihu.com/p/29119239 卷积层尺寸的计算原理 输入矩阵格式:四个维度,依次为:样本数.图像高度.图像宽度.图像通道数 输出矩阵格式:与输 ...
- TensorFlow实现卷积神经网络
1 卷积神经网络简介 在介绍卷积神经网络(CNN)之前,我们需要了解全连接神经网络与卷积神经网络的区别,下面先看一下两者的结构,如下所示: 图1 全连接神经网络与卷积神经网络结构 虽然上图中显示的全连 ...
- 82、TensorFlow教你如何构造卷积层
''' Created on 2017年4月22日 @author: weizhen ''' import tensorflow as tf #通过tf.get_variable的方式创建过滤器的权重 ...
- tensorflow 1.0 学习:卷积层
在tf1.0中,对卷积层重新进行了封装,比原来版本的卷积层有了很大的简化. 一.旧版本(1.0以下)的卷积函数:tf.nn.conv2d conv2d( input, filter, strides, ...
- TensorFlow与caffe中卷积层feature map大小计算
刚刚接触Tensorflow,由于是做图像处理,因此接触比较多的还是卷及神经网络,其中会涉及到在经过卷积层或者pooling层之后,图像Feature map的大小计算,之前一直以为是与caffe相同 ...
随机推荐
- Hadoop组件详解(随缘摸虾)
1.1. Hadoop组成: Hadoop = hdfs(存储) + mapreduce(计算) + yarn(资源协调) + common(工具包) + ozone(对象存储) + submarin ...
- 小程序Promise
/** 异步函数回调简化处理 const promisify = require('./promisify') const getSystemInfo = promisify(wx.getSystem ...
- vue学习(五)生命周期 的钩子函数
生命周期的钩子函数 主要有以下几种 beforeCreate created beforeMount mounted beforeUpdate updated activated deactivate ...
- MFC 选择文件夹
WCHAR szPath[_MAX_PATH] = {}; BROWSEINFO bi; //指定父窗口,在对话框显示期间,父窗口将被禁用 bi.hwndOwner = this->GetSaf ...
- TX2-刷机完成后安装程序ubuntu_linux命令&TX2学习总结
Linux教程|菜鸟教程:http://www.runoob.com/linux/linux-tutorial.html 认识linux:ping命令:ping命令是常用的网络命令ping网关:pin ...
- 创建maven项目时pom.xml报错的解决方法
创建maven项目时pom.xml时: 出现如下报错信息: Failure to transfer commons-lang:commons-lang:jar:2.1 from https://rep ...
- No enclosing instance of type test is accessible. Must qualify the allocation with an enclosing inst
今日遇到一个报错如下: No enclosing instance of type test is accessible. Must qualify the allocation with an en ...
- Java版本和功能指南
您可以使用本指南查找和安装最新的Java,了解Java发行版(AdoptOpenJdk,OpenJDK,OracleJDK等)之间的差异,以及获得Java语言功能的概述,包括Java版本8-13. J ...
- python安装wordcloud、jieba,pyecharts
1.安装wordcloud: 适用于无法使用pip install wordcloud安装的情况: 据python和windows 版本 到https://www.lfd.uci.edu/~gohlk ...
- Window NodeJs安装
1.下载NodeJs 官网下载地址:http://nodejs.cn/download/ 2.安装 双击,全程next安装. 安装完成,在cmd下面执行查看版本命令,命令如下 C:\Users\A ...