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相同 ...
随机推荐
- spring学习第8天(advisor)
1.关于之前的一个错误:aop的输出顺序,实际上官方文档上并没有说是否按照书写顺序输出的,有可能你1000次里面800次按顺序输出,200是随机输出的.<aop:aspect>有一个ord ...
- c++程序—switch分支
#include<iostream> using namespace std; #include<string> int main() { //多元分支 cout <&l ...
- (转) Windows如何区分鼠标双击和两次单击
Windows如何区分鼠标双击和两次单击 http://lbsloveldm.blog.hexun.com/12212875_d.html 在Windows平台上,鼠标左键的按下.松开.快速的两次点击 ...
- python 列表和字符串
python 列表中保留所有字符串前三项,并保存到一个新的列表l = [s[:3] for s in data] python 在列表中查找包含所以某个字符串的项,并保存到一个新的列表l = [s f ...
- 不同DIV滚动条如何同步?
$(".DIV").scroll(function(){ $(".target").scrollLeft($(".DIV ").scrol ...
- mybatis环境搭建(eclipse,idea)
基于java配置SSM,eclipse 新建maven,web项目 .... 项目结构: jar包 pom.xml spring和DispatcherServlet上下文 public class D ...
- JAVAEE 和项目开发(第三课:HTTP的请求头和请求方式)
HTTP 协议之请求格式 请求格式的结构:请求行:请求方式.请求的地址和 HTTP 协议版本 请求头:消息报头,一般用来说明客户端要使用的一些附加信息 空行: 位于请求行和请求数据之间,空行是必须 ...
- 二十、CI框架数据库操作之查看生产的sql语句
一.代码如下: 二.我们访问一下: 三.我们对比一下数据库内容 不忘初心,如果您认为这篇文章有价值,认同作者的付出,可以微信二维码打赏任意金额给作者(微信号:382477247)哦,谢谢.
- Java中多态的实例
public class cf { /** * 实际上这里涉及方法调用的优先问题, * 优先级由高到低依次为:this.show(O).super.show(O).this.show((super)O ...
- C#应用程序结构
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...