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. LINQ(语言集成查询)

    LINQ,语言集成查询(Language Integrated Query)是一组用于c#和Visual Basic语言的扩展.它允许编写C#或者Visual Basic代码以查询数据库相同的方式操作 ...

  2. C#多线程之间事件通知

    我有两个线程,线程1接受网络数据,存到队列;线程2取队列,进行各种复杂的处理然后绘制到界面上;想让线程1有数据了通知线程2,线程2再取队列,因为不通知的话,线程2一直在while循环检索队列时候有东西 ...

  3. A Simple Problem with Integers POJ - 3468 (线段树)

    思路:线段树,区间更新,区间查找 #include<iostream> #include<vector> #include<string> #include< ...

  4. fastjson 对象和json互转

    list转json List<Openid> openids = od.getAll(session); String json = JSONObject.toJSONString(ope ...

  5. mysql优化-数据库设计基本原则

    mysql优化-数据库设计基本原则 一.数据库设计三范式 第一范式:字段具有原子性 原子性是指数据库的所有字段都不可被再次划分,如下表就不满足原子性,起点与终点 字段就可被拆分为起点与终点两个字段. ...

  6. 【洛谷】P1880 石子合并

    P1880 石子合并 题目描述 在一个园形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分. 试设计出1个算法,计 ...

  7. win10 请求操作需要提升解决方案

    记录一下: win10   系统管理员 打开后缀为  .xxx 的文件时, 系统提示: 请求操作需要提升 网上搜索了一下,原因是权限不够,故系统提示. 给当前用户加入了 管理员权限,各种权限都无效. ...

  8. 关于父组件通过v-on接收子组件多个参数的一点研究

    写组件的时候遇到一个需求,我需要在子组件向父组件传递信息 this.$emit('myEvent', 信息1, 信息2) 在父组件使用v-on来接收 <my-component @myEvent ...

  9. vue中router以及route的使用

    路由基本概念 route,它是一条路由. { path: '/home', component: Home } routes,是一组路由. const routes = [ { path: '/hom ...

  10. python mooc 3维可视化<第一周第二&三单元>

    小结: 创建 数据对象 structuredGrid grid 使用contourfilter con PolyDataMapper m Actor a 使用 MaskPoint3D mask gly ...