TensorFlow 卷积层

 

让我们看下如何在 TensorFlow 里面实现 CNN。

TensorFlow 提供了 tf.nn.conv2d() 和 tf.nn.bias_add() 函数来创建你自己的卷积层。

# Output depth
k_output = # Image Properties
image_width =
image_height =
color_channels = # Convolution filter
filter_size_width =
filter_size_height = # Input/Image
input = tf.placeholder(
tf.float32,
shape=[None, image_height, image_width, color_channels]) # Weight and bias
weight = tf.Variable(tf.truncated_normal(
[filter_size_height, filter_size_width, color_channels, k_output]))
bias = tf.Variable(tf.zeros(k_output)) # Apply Convolution
conv_layer = tf.nn.conv2d(input, weight, strides=[, , , ], padding='SAME')
# Add bias
conv_layer = tf.nn.bias_add(conv_layer, bias)
# Apply activation function
conv_layer = tf.nn.relu(conv_layer)

上述代码用了 tf.nn.conv2d() 函数来计算卷积,weights 作为滤波器,[1, 2, 2, 1] 作为 strides。TensorFlow 对每一个 input 维度使用一个单独的 stride 参数,[batch, input_height, input_width, input_channels]。我们通常把 batch 和 input_channels (strides 序列中的第一个第四个)的 stride 设为 1

你可以专注于修改 input_height 和 input_width, batch 和 input_channels 都设置成 1。input_height 和 input_width strides 表示滤波器在input 上移动的步长。上述例子中,在 input 之后,设置了一个 5x5 ,stride 为 2 的滤波器。

tf.nn.bias_add() 函数对矩阵的最后一维加了偏置项。

tensorflow 卷积层的更多相关文章

  1. TensorFlow卷积层-函数

    函数1:tf.nn.conv2d是TensorFlow里面实现卷积的函数,实际上这是搭建卷积神经网络比较核心的一个方法 函数原型: tf.nn.conv2d(input,filter,strides, ...

  2. tensorflow 1.0 学习:卷积层

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

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

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

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

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

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

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

  6. 81、Tensorflow实现LeNet-5模型,多层卷积层,识别mnist数据集

    ''' Created on 2017年4月22日 @author: weizhen ''' import os import tensorflow as tf import numpy as np ...

  7. tensorflow CNN 卷积神经网络中的卷积层和池化层的代码和效果图

    tensorflow CNN 卷积神经网络中的卷积层和池化层的代码和效果图 因为很多 demo 都比较复杂,专门抽出这两个函数,写的 demo. 更多教程:http://www.tensorflown ...

  8. AI相关 TensorFlow -卷积神经网络 踩坑日记之一

    上次写完粗浅的BP算法 介绍 本来应该继续把 卷积神经网络算法写一下的 但是最近一直在踩 TensorFlow的坑.所以就先跳过算法介绍直接来应用场景,原谅我吧. TensorFlow 介绍 TF是g ...

  9. Tensorflow卷积神经网络

    卷积神经网络(Convolutional Neural Network, CNN)是一种前馈神经网络, 在计算机视觉等领域被广泛应用. 本文将简单介绍其原理并分析Tensorflow官方提供的示例. ...

随机推荐

  1. spring boot指定外部配置的坑

    外部配置文件所在目录path/to/dir 指定--spring.config.location=path/to/dir 项目启动,没有使用任何配置文件,项目外和jar包中的都没有使用 这是因为其把p ...

  2. Jeecms网站直接访问html静态页面

    jeecms网站维护,遇到了直接通过链接的方式访问静态页面,jeecms官网也做了详细的解答,但是没有得到满意的结果.但是通过自己的深入研究以及别人的帮助,发现了一个很好的解决方法. 首先说明一下je ...

  3. gomod

    package main import "mycore" func main(){ mycore.ShowName() } main.go module mytest requir ...

  4. Spring boot随时获取ApplicationContex

    @Service public class SpringManager implements ApplicationListener<ContextRefreshedEvent> { pr ...

  5. mysql导入数据中文乱码解决方法

    常见的MySQL导入方法有两种 第一种方法,使用MySQL命令导入 mysql -uroot -p123456 --default-character-set=utf8 [db_name] < ...

  6. Leetcode59. Spiral Matrix II螺旋矩阵2

    给定一个正整数 n,生成一个包含 1 到 n2 所有元素,且元素按顺时针顺序螺旋排列的正方形矩阵. 示例: 输入: 3 输出: [ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, ...

  7. 微信小程序之组件开发中的基础知识

    跟着视频开始小程序的项目的开发,视频中这个小程序已经上线了,可以很好的看着小程序的界面进行开发,昨天看了一下具体的需求,觉得真的细节好多啊,而且其中设计的组件的思想也是很好的,能够很好的实现代码的复用 ...

  8. 模拟20 题解(waiting)

    留坑待填 T2 #include<cstdio> #include<vector> #include<cstring> #include<iostream&g ...

  9. web前端学习(二)html学习笔记部分(6)--fileAPI

    1.2.18 html5 File API的应用 1.2.18.1  实现可选择列表 通过为列表项增加一个选择框,进而实现列表的多选和对选择文件的删除.同时,在选择.取消选择时实现操作栏的切换. 1. ...

  10. mytop安装,使用mytop监控MySQL性能 (总结)

    mytop 是一个类似 Linux 下的 top 命令风格的 MySQL 监控工具,可以监控当前的连接用户和正在执行的命令. 1. 安装TermReadKey    下载地址:  wget  http ...