TFLearn构建神经网络
TFLearn构建神经网络
Building the network
TFLearn lets you build the network by defining the layers.
Input layer
For the input layer, you just need to tell it how many units you have. For example,
net = tflearn.input_data([None, 100])
would create a network with 100 input units. The first element in the list, None
in this case, sets the batch size. Setting it to None
here leaves it at the default batch size.
The number of inputs to your network needs to match the size of your data. For this example, we're using 10000 element long vectors to encode our input data, so we need 10000 input units.
Adding layers
To add new hidden layers, you use
net = tflearn.fully_connected(net, n_units, activation='ReLU')
This adds a fully connected layer where every unit in the previous layer is connected to every unit in this layer. The first argument net
is the network you created in the tflearn.input_data
call. It's telling the network to use the output of the previous layer as the input to this layer. You can set the number of units in the layer with n_units
, and set the activation function with the activation
keyword. You can keep adding layers to your network by repeated calling net = tflearn.fully_connected(net, n_units)
.
Output layer
The last layer you add is used as the output layer. Therefore, you need to set the number of units to match the target data. In this case we are predicting two classes, positive or negative sentiment. You also need to set the activation function so it's appropriate for your model. Again, we're trying to predict if some input data belongs to one of two classes, so we should use softmax.
net = tflearn.fully_connected(net, 2, activation='softmax')
Training
To set how you train the network, use
net = tflearn.regression(net, optimizer='sgd', learning_rate=0.1, loss='categorical_crossentropy')
Again, this is passing in the network you've been building. The keywords:
optimizer
sets the training method, here stochastic gradient descentlearning_rate
is the learning rateloss
determines how the network error is calculated. In this example, with the categorical cross-entropy.
Finally you put all this together to create the model with tflearn.DNN(net)
. So it ends up looking something like
net = tflearn.input_data([None, 10]) # Input
net = tflearn.fully_connected(net, 5, activation='ReLU') # Hidden
net = tflearn.fully_connected(net, 2, activation='softmax') # Output
net = tflearn.regression(net, optimizer='sgd', learning_rate=0.1, loss='categorical_crossentropy')
model = tflearn.DNN(net)
TFLearn构建神经网络的更多相关文章
- 使用pytorch构建神经网络的流程以及一些问题
使用PyTorch构建神经网络十分的简单,下面是我总结的PyTorch构建神经网络的一般过程以及我在学习当中遇到的一些问题,期望对你有所帮助. PyTorch构建神经网络的一般过程 下面的程序是PyT ...
- Tensorflow BatchNormalization详解:2_使用tf.layers高级函数来构建神经网络
Batch Normalization: 使用tf.layers高级函数来构建神经网络 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 吴恩达deeplearningai课程 课程笔 ...
- 使用 Visual Studio 2015 + Python3.6 + tensorflow 构建神经网络时报错:'utf-8' codec can't decode byte 0xcc in position 78: invalid continuation byte
使用 Visual Studio 2015 + Python3.6 + tensorflow 构建神经网络时报错:'utf-8' codec can't decode byte 0xcc in pos ...
- 使用PyTorch构建神经网络以及反向传播计算
使用PyTorch构建神经网络以及反向传播计算 前一段时间南京出现了疫情,大概原因是因为境外飞机清洁处理不恰当,导致清理人员感染.话说国外一天不消停,国内就得一直严防死守.沈阳出现了一例感染人员,我在 ...
- 使用Sybmol模块来构建神经网络
符号编程 在之前的文章,我们介绍了NDArray模块,它是MXNet中处理数据的核心模块,我们可以使用NDArray完成非常丰富的数学运算.实际上,我们完全可以使用NDArray来定义神经网络,这种方 ...
- pytorch中torch.nn构建神经网络的不同层的含义
主要是参考这里,写的很好PyTorch 入门实战(四)--利用Torch.nn构建卷积神经网络 卷积层nn.Con2d() 常用参数 in_channels:输入通道数 out_channels:输出 ...
- TensorFlow深度学习!构建神经网络预测股票价格!⛵
作者:韩信子@ShowMeAI 深度学习实战系列:https://www.showmeai.tech/tutorials/42 TensorFlow 实战系列:https://www.showmeai ...
- caffe中是如何运用protobuf构建神经网络的?
caffe这个框架设计的比较小巧精妙,它采用了protobuf来作为交互的媒介,避免了繁重的去设计各个语言的接口,开发者可以使用任意语言通过这个protobuf这个媒介,来运行这个框架. 我们这里不过 ...
- 用tensorflow构建神经网络学习简单函数
目标是学习\(y=2x+3\) 建立一个5层的神经网络,用平方误差作为损失函数. 代码如下: import tensorflow as tf import numpy as np import tim ...
随机推荐
- 机器学习(3)-Tensorflow安装与测试
安装.# Ubuntu/Linux 64-bit $ sudo apt-get install python-pip python-dev # Ubuntu/Linux 64-bit, CPU onl ...
- ML(2)--感知机
案例银行办信用卡--获得感知机 我们到银行办信用卡时,银行并不是直接就给你办卡的,而是会根据你的一些个人信息.消费信息.个人信誉等指标综合考虑后,才会决定是否给你办卡(不像现在银行办信用卡有点随意). ...
- jsp函数的使用
在这篇博客里面谈一谈jsp函数的一些使用规则 1.在jsp里面,函数和类是等价的,因为在函数的内部可以定义函数和变量.定义在函数内的函数和变量分为实例属性.实例函数.类属性.类函数.实例和类是面向对象 ...
- ORACLE - 用户和角色的权限管理
在ORACLE中,创建用户后需要授权才能使用. 一.用户管理 1. 用户和角色信息查询 --查询所有用户 SQL> select * from dba_users; --经授予的用户或角色的系统 ...
- css简单实现五角星评分、点赞收藏、展示评分(半颗星、1/3颗星)
1.前言 之前做的好几个项目中,都会遇到打分,评分,点赞这样的需求,写了很多次,每次需要再写的时候,就会翻出之前写过的代码,然后copy过来.总觉得这样的话没有进步,没有把知识放进脑袋里,所以,自己花 ...
- HPU--1091 N!的位数
1091: N!的位数 [数学] 时间限制: 1 Sec 内存限制: 128 MB提交: 97 解决: 12 统计 题目描述 我们知道n!=n*(n-1)*(n-2)*-*2*1. 那么给定一个n,n ...
- akoj-1280另类阶乘问题
另类阶乘问题 Time Limit:3000MS Memory Limit:65536K Total Submit:22 Accepted:20 Description 大家都知道阶乘这个概念,举个 ...
- 【HTTP权威指南】第二章-URL与资源
[统一资源定位符URL]通过位置来标示资源,其表达的格式如下:https://item.jd.com/523961.html 第一部分(https)是方案,告知客户端要[怎样访问],这里使用的是htt ...
- 【性能测试工具】- ApacheBench
优点:提供的测试结果信息更完备:缺点:每次只能测试一个链接 概述: ab全称是ApacheBench,是 Apache 附带的一个HTTP性能测试小工具,可以同时模拟多个并发请求. 安装: Apach ...
- MySQL权限说明
--MySQL权限说明 ----------------------2014/06/09 一.权限表 mysql数据库中的3个权限表:user .db. host 权限表的存取过程是: 1)先从use ...