#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. 吴裕雄--天生自然C++语言学习笔记:C++ 实例

    C++ 实例 - 输出 "Hello, World!" #include <iostream> using namespace std; int main() { co ...

  2. ProxyPass与ProxyPassReverse及ProxyPassMatch的概述

    转载自:https://blog.csdn.net/xiaokui_wingfly/article/details/51481653 apache中的mod_proxy模块主要作用就是进行url的转发 ...

  3. django下载

    pip install django ==2.0.5 创建目录 1创建目录 2终端下进入目录 3输入django-admin startproject project

  4. UVA - 1605 Building for UN (联合国大楼)

    题意:一个联合国大楼每层都有数量相等大小相同的格子,将其分配给n个国家,使任意两个不同的国家都相邻(同层有公共边或相邻层的同一个格子). 分析:可以设计一个只有两层的大楼,第一层每个国家占一行,第二层 ...

  5. HDU 5461:Largest Point

    Largest Point Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) To ...

  6. 屏幕适配 - JS - 网站布局元素

    网页可见区域宽:document.body.clientWidth; 网页可见区域高:document.body.clientHeight; 网页可见区域高:document.body.offsetW ...

  7. 使用模拟器调试react-native步骤(安卓机)

    1.在cmd界面搭建react-native 环境: 可参考https://reactnative.cn/docs/0.51/getting-started.html#content (1)npm i ...

  8. ubuntu下解压.zip文件乱码

    解决方法 查看文件: lsar BA_schur.zip 解压文件: unar BA_schur.zip

  9. [题解] LuoguP4381 [IOI2008]Island

    LuoguP4381 [IOI2008]Island Description 一句话题意:给一个基环树森林,求每棵基环树的直径长度的和(基环树的直径定义与树类似,即基环树上一条最长的简单路径),节点总 ...

  10. 【数据结构】C++语言环形队列的实现

    队列--先进先出 队列的一个缺点--出队后的内存空间浪费了,不能二次利用 环形队列--解决以上缺点的队列,用过的内存空间可以重复利用 github: https://github.com/HITFis ...