#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实现卷积层的几种方式的更多相关文章

  1. MyBatis开发Dao层的两种方式(原始Dao层开发)

    本文将介绍使用框架mybatis开发原始Dao层来对一个对数据库进行增删改查的案例. Mapper动态代理开发Dao层请阅读我的下一篇博客:MyBatis开发Dao层的两种方式(Mapper动态代理方 ...

  2. MyBatis开发Dao层的两种方式(Mapper动态代理方式)

    MyBatis开发原始Dao层请阅读我的上一篇博客:MyBatis开发Dao层的两种方式(原始Dao层开发) 接上一篇博客继续介绍MyBatis开发Dao层的第二种方式:Mapper动态代理方式 Ma ...

  3. 『TensorFlow』卷积层、池化层详解

    一.前向计算和反向传播数学过程讲解

  4. TensorFlow的 卷积层

    用 TensorFlow 做卷积 让我们用所学知识在 TensorFlow 里构建真的 CNNs.在下面的练习中,你需要设定卷积核滤波器(filters)的维度,weight,bias.这在很大程度上 ...

  5. CNN中卷积层的计算细节

    原文链接: https://zhuanlan.zhihu.com/p/29119239 卷积层尺寸的计算原理 输入矩阵格式:四个维度,依次为:样本数.图像高度.图像宽度.图像通道数 输出矩阵格式:与输 ...

  6. TensorFlow实现卷积神经网络

    1 卷积神经网络简介 在介绍卷积神经网络(CNN)之前,我们需要了解全连接神经网络与卷积神经网络的区别,下面先看一下两者的结构,如下所示: 图1 全连接神经网络与卷积神经网络结构 虽然上图中显示的全连 ...

  7. 82、TensorFlow教你如何构造卷积层

    ''' Created on 2017年4月22日 @author: weizhen ''' import tensorflow as tf #通过tf.get_variable的方式创建过滤器的权重 ...

  8. tensorflow 1.0 学习:卷积层

    在tf1.0中,对卷积层重新进行了封装,比原来版本的卷积层有了很大的简化. 一.旧版本(1.0以下)的卷积函数:tf.nn.conv2d conv2d( input, filter, strides, ...

  9. TensorFlow与caffe中卷积层feature map大小计算

    刚刚接触Tensorflow,由于是做图像处理,因此接触比较多的还是卷及神经网络,其中会涉及到在经过卷积层或者pooling层之后,图像Feature map的大小计算,之前一直以为是与caffe相同 ...

随机推荐

  1. text字体样式(多行结尾省略,彩色渐变字体)

    text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; ...

  2. HDU - 5976 Detachment(逆元)

    题意:将一个数x拆成a1+a2+a3+……,ai不等于aj,求最大的a1*a2*a3*……. 分析: 1.预处理前缀和前缀积,因为拆成1对乘积没有贡献,所以从2开始拆起. 2.找到一个id,使得2+3 ...

  3. AVCodec 结构体

    typedef struct AVCodec { // 标示Codec 的名字, 比如,"h264" "h263" 等. const char *name; / ...

  4. silicon射频发射器 SI4010-C2-GSR

    Si4010是第一款系统级的自动天线调谐发射器,具有专利的调谐电路,可自动微调天线以达到最佳效果,以及恒定的输出功耗.PCB环形天线的制造公差和环境改变,将会引起发射频率的变化,从而可能导致天线的效率 ...

  5. 创建maven项目时pom.xml报错的解决方法

    创建maven项目时pom.xml时: 出现如下报错信息: Failure to transfer commons-lang:commons-lang:jar:2.1 from https://rep ...

  6. Oracle学习笔记(2)

    2.Oracle用户管理 (1)创建用户:create user 用户名 identified by 密码(需要dba权限); sql>create user yzw identified by ...

  7. 解决fixed布局里内容不滚动问题

    //注意给父级加上 (1)横向滚动 left:0; right:0; 然后想要横向滚动的话 overflow-x:scroll; overflow-y:hidden; (2)竖直方向滚动top:0;b ...

  8. LinkedList源码阅读笔记

    LinkedList LinkedList是双向链表,不循环(1.6之前循环),继承AbstractSequentialList类,实现了List, Deque, Cloneable接口. 链表的特点 ...

  9. Git--git log

    参考 https://www.cnblogs.com/bellkosmos/p/5923439.html https://www.cnblogs.com/mkl34367803/p/9219913.h ...

  10. ADC分辨率

    转载:http://www.rationmcu.com/elecjc/1874.html 今天给大家简单介绍一下ADC器件的常识. ADC,模数转换器,功能是把模拟电压转换成数字量. 概念听的模糊,说 ...