#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. Spark SQL 笔记

    Spark SQL 简介 SparkSQL 的前身是 Shark, SparkSQL 产生的根本原因是其完全脱离了 Hive 的限制.(Shark 底层依赖于 Hive 的解析器, 查询优化器) Sp ...

  2. (四)requests模块的cookies和代理操作

    基于requests模块的cookie操作 引言:有些时候,我们在使用爬虫程序去爬取一些用户相关信息的数据(爬取某个人“人人网”个人主页数据)时,如果使用之前requests模块常规操作时,往往达不到 ...

  3. 2016蓝桥杯省赛C/C++A组第六题 寒假作业

    题意:现在小学的数学题目也不是那么好玩的. 看看这个寒假作业: □ + □ = □ □ - □ = □ □ × □ = □ □ ÷ □ = □ 每个方块代表1~13中的某一个数字,但不能重复. 比如: ...

  4. [Mathematics][MIT 18.03] Detailed Explanation of the Frequency Problems in Second-Order Differential Equation of Oscillation System

    Well, to begin with, I'd like to say thank you to MIT open courses twice. It's their generosity that ...

  5. HDU—4699 Editor 双向链表+子集和

    惨.今天聪哥选了2013 多校10做训练,结果一题都没做出来.这个题目是数据结构,正好是我强项 如果只是插入 删除 光标左右移动,那都小菜,用链表全解决,关键是那个Q k 要求 a1到aq的连续子序列 ...

  6. Codeforces 442A Borya and Hanabi

    有五种花色 外加 五种点数 共25张牌,每次有n张牌,主人知道这n张牌中有哪些牌,并且哪种牌有几张,但是不知道具体是哪张牌,他可以问某种花色,然后知道了哪几张是该花色,也可以问点数,然后就知道了哪几张 ...

  7. java中流的注意事项

    缓冲流 缓冲流继承自过滤流,使用缓冲流时一些要注意的知识点: 1.如果在缓冲流对象创建时使用了其他流,最后关闭时只需关闭缓冲流就可以了,其他流会跟着自动关闭. 2.缓冲字符输入流(BufferedRe ...

  8. C++ Opencv播放AVI

    #include "cxcore.h" #include "cvcam.h" #include "windows.h" #include & ...

  9. Java IO流操作 (II)

    缓冲流 /* * BufferedWriter:将文本写入字符输出流,缓冲各个字符,从而提供单个字符.数组和字符串的高效写入. * BufferedReader:从字符输入流中读取文本,缓冲各个字符, ...

  10. openv uMat和Mat数据格式的转换

    Mat 转成 UMat: UMat umat; mat.copyTo(umat); UMat转成 Mat : Mat mat; umat.copyTo(mat);