本节对tflearn包里各文件进行分析 根目录: ? 1. _pycache文件夹: python运行时,编译生成的过度文件。 2.datasets文件夹: ? datasets文件夹包含的是tflearn预先准备的几个数据集加载文件。可以方便测试,具体如下 clfar-10 clfar-100:小型图像识别数据库。 imdb:互联网电影资料库。
一.安装 pip 下载tensorflow和tflearn 二.泰坦尼克号船员分类 创建py文件(我这里是titanic.py) import numpy as np import tflearn # 下载 Titanic 数据并保存 from tflearn.datasets import titanic titanic.download_dataset('titanic_dataset.csv' ) # 加载 CSV 文件 from tflearn.data_utils import load_csv data, labels = load_csv('titanic_dataset.csv', (shape=[None, 6]) net = tflearn.fully_connected(net, 32) net = tflearn.fully_connected(net, 32) net = tflearn.fully_connected(net, 2, activation='softmax') net = tflearn.regression(net) # 选择 model model
1、安装anaconda 2、安装pycharm 3、“启动”--“cmd” 输入pip install tflearn 或 conda install tflearn 4、将python--lib --site-packages下的tflearn相关文件夹复制到 anaconda路径下lib--site-packages 出现的问题:curses is not supported on this
一:下载支持 需要tensorflow,tflearn。 pip install tensorflow tflearn 二:代码 创建py文件(我这里是XianXingHuiGui.py) """ 线性回归实例 """ from __future__ import 1.7,2.76,2.09,3.19,1.694,1.573,3.366,2.596,2.53,1.221,2.827,3.465,1.65,2.904,2.42,2.94,1.3] # 线性回归模型 input_ = tflearn.input_data (shape=[None]) linear = tflearn.single_unit(input_) regression = tflearn.regression(linear, optimizer ='sgd', loss='mean_square', metric='R2', learning_rate=0.01) m = tflearn.DNN
import tensorflow as tf from tflearn.layers.conv import conv_2d # Data loading from tflearn.datasets tflearn.activation(net, 'relu') net = tflearn.global_avg_pool(net) # Regression net = tflearn.fully_connected @author: me """ import tflearn # Data loading from tflearn.datasets import mnist X, Y, testX, testY = tflearn.residual_block(net, 1, 8, downsample=True) net = tflearn.batch_normalization(net) net = tflearn.activation (net, 'relu') net = tflearn.global_avg_pool(net) # Regression net = tflearn.fully_connected(net, 10,
的 pad_sequences 将 strings 转化成向量,用 tflearn.embedding 得到 word vector,再传递给 LSTM 得到 feature vector,经过全联接层后 ,再用一个分类器,loss 为 categorical_crossentropy 数据用 tflearn 里面预先处理好的 imdb,IMDB 是一个电影评论的数据库。 from __future__ import division, print_function, absolute_import import tflearn from tflearn.data_utils import to_categorical, pad_sequences from tflearn.datasets import imdb path 是存储的路经,pkl 是 byte stream (net, input_dim=10000, output_dim=128) 模型用的 LSTM,可以保持记忆,dropout 为了减小过拟合 net = tflearn.lstm(net, 128,
net = tflearn.lstm(net, 64) net = tflearn.dropout(net, 0.5) net = tflearn.fully_connected(net, 5000, TFLearn安装 要安装TFLearn,最简单的方法就是运行。 对于前沿版本(推荐): pip install git + https://github.com/tflearn/tflearn.git 对于最新的稳定版本: pip install tflearn 否则 入门 请参阅TFLearn入门,了解TFLearn基本功能或开始浏览TFLearn教程。 【1】tflearn:https://github.com/tflearn/tflearn
TFLearn地址:https://github.com/tflearn/tflearn 示例:https://github.com/tflearn/tflearn/tree/master/examples 预构建的运算和层:http://tflearn.org/doc_index/#api 笔记:https://github.com/tflearn/tflearn/blob/master/tutorials /intro/quickstart.md 基础模型以及数据集 线性回归,使用 TFLearn 实现线性回归 https://github.com/tflearn/tflearn/blob/master/ 使用 TFLearn 实现逻辑运算符 https://github.com/tflearn/tflearn/blob/master/examples/basics/logical.py 权重保持。 Variables,连同 TensorFlow 使用 TFLearn Variables: https://github.com/tflearn/tflearn/blob/master/examples
示例:https://github.com/tflearn/tflearn/tree/master/examples 预构建的运算和层:http://tflearn.org/doc_index/#api 笔记:https://github.com/tflearn/tflearn/blob/master/tutorials/intro/quickstart.md 基础 线性回归,使用 TFLearn 实现线性回归 使用 TFLearn 实现逻辑运算符:https://github.com/tflearn/tflearn/blob/master/examples/basics/logical.py 权重保持。 ,对斯坦福 CS231n spiral 分类难题的 TFLearn 实现:https://github.com/tflearn/tflearn/blob/master/examples/notebooks /spiral.ipynb 可延展的 TensorFlow 层,与 TensorFlow 一起使用 TFLearn 层:https://github.com/tflearn/tflearn/blob/
使用教程:TFLearn 快速入门。通过一个具体的机器学习任务学习 TFLearn 基础。开发和训练一个深度神经网络分类器。 TFLearn地址:https://github.com/tflearn/tflearn 示例:https://github.com/tflearn/tflearn/tree/master/examples 预构建的运算和层:http://tflearn.org/doc_index/#api 笔记:https://github.com/tflearn/tflearn/blob/master/tutorials /intro/quickstart.md 基础模型以及数据集 线性回归,使用 TFLearn 实现线性回归 https://github.com/tflearn/tflearn/blob/master/ 使用 TFLearn 实现逻辑运算符 https://github.com/tflearn/tflearn/blob/master/examples/basics/logical.py 权重保持。
示例:https://github.com/tflearn/tflearn/tree/master/examples 预构建的运算和层:http://tflearn.org/doc_index/#api 笔记:https://github.com/tflearn/tflearn/blob/master/tutorials/intro/quickstart.md 基础 线性回归,使用 TFLearn 实现线性回归 使用 TFLearn 实现逻辑运算符:https://github.com/tflearn/tflearn/blob/master/examples/basics/logical.py 权重保持。 ,对斯坦福 CS231n spiral 分类难题的 TFLearn 实现:https://github.com/tflearn/tflearn/blob/master/examples/notebooks /spiral.ipynb 可延展的 TensorFlow 层,与 TensorFlow 一起使用 TFLearn 层:https://github.com/tflearn/tflearn/blob/
TFLearn地址:https://github.com/tflearn/tflearn 示例:https://github.com/tflearn/tflearn/tree/master/examples 预构建的运算和层:http://tflearn.org/doc_index/#api 笔记:https://github.com/tflearn/tflearn/blob/master/tutorials /intro/quickstart.md 基础模型以及数据集 线性回归,使用 TFLearn 实现线性回归 https://github.com/tflearn/tflearn/blob/master/ 使用 TFLearn 实现逻辑运算符 https://github.com/tflearn/tflearn/blob/master/examples/basics/logical.py 权重保持。 Variables,连同 TensorFlow 使用 TFLearn Variables: https://github.com/tflearn/tflearn/blob/master/examples
CS231n spiral 分类难题的 TFLearn 实现: https://github.com/tflearn/tflearn/blob/master/examples/notebooks/spiral.ipynb 层,与 TensorFlow 一起使用 TFLearn 层: https://github.com/tflearn/tflearn/blob/master/examples/extending_tensorflow /layers.py 训练器,使用 TFLearn 训练器类训练任何 TensorFlow 图: https://github.com/tflearn/tflearn/blob/master/examples TFLearn summarizers: https://github.com/tflearn/tflearn/blob/master/examples/extending_tensorflow/summaries.py Variables,连同 TensorFlow 使用 TFLearn Variables: https://github.com/tflearn/tflearn/blob/master/examples
TFLearn地址:https://github.com/tflearn/tflearn 示例:https://github.com/tflearn/tflearn/tree/master/examples 预构建的运算和层:http://tflearn.org/doc_index/#api 笔记:https://github.com/tflearn/tflearn/blob/master/tutorials /intro/quickstart.md 基础模型以及数据集 线性回归,使用 TFLearn 实现线性回归 https://github.com/tflearn/tflearn/blob/master/ 使用 TFLearn 实现逻辑运算符 https://github.com/tflearn/tflearn/blob/master/examples/basics/logical.py 权重保持。 Variables,连同 TensorFlow 使用 TFLearn Variables: https://github.com/tflearn/tflearn/blob/master/examples
本文采用TensorFlow 1.0和TFLearn 0.3.2,编写了图像分类的程序,采用的图像数据为CIFAR-10。CIFAR-10是一个非常常用的图像数据集,包含10个类别的图像。 可以在这个网址找到具体介绍:https://www.cs.toronto.edu/~kriz/cifar.html 2.png 参照ResNet代码(https://github.com/tflearn /tflearn/blob/master/examples/images/residual_network_cifar10.py),所编写的深度残差收缩网络的代码如下: #! (scales) scales = tflearn.activation(scales, 'relu') scales = tflearn.fully_connected (net) net = tflearn.activation(net, 'relu') net = tflearn.global_avg_pool(net) # Regression net = tflearn.fully_connected
下面使用tflearn重写上面代码,tflearn是TensorFlow的高级封装,类似Keras。 tflearn提供了更简单、直观的接口。 和scikit-learn差不多,代码如下: # -*- coding:utf-8 -*- import tflearn from tflearn.layers.conv import conv_2d, max_pool_2d from tflearn.layers.core import input_data, dropout, fully_connected from tflearn.layers.estimator import regression train_x, train_y, test_x, test_y = tflearn.datasets.mnist.load_data( data_dir
导入库 需要用到 tflearn,这是建立在 TensorFlow 上的高级的库,可以很方便地建立网络。 还会用到辅助的类 speech_data,用来下载数据并且做一些预处理。 from __future__ import division, print_function, absolute_import import tflearn import speech_data import # Network building net = tflearn.input_data([None, width, height]) net = tflearn.lstm(net, 128, dropout =0.8) net = tflearn.fully_connected(net, classes, activation='softmax') net = tflearn.regression(net, 训练模型并预测 然后用 tflearn.DNN 函数来初始化一下模型,接下来就可以训练并预测,最后再保存训练好的模型。
6.Keras和TFLearn程序简介 本程序以图像分类为例,构建了小型的深度残差收缩网络,超参数也未进行优化。为追求高准确率的话,可以适当增加深度,增加训练迭代次数,以及适当调整超参数。 import numpy as np import tensorflow as tf from tflearn.layers.conv import conv_2d # Data loading from tflearn.datasets import cifar10 (X, Y), (testX, testY) = cifar10.load_data() # Add noise X = (scales) scales = tflearn.activation(scales, 'relu') scales = tflearn.fully_connected (net) net = tflearn.activation(net, 'relu') net = tflearn.global_avg_pool(net) # Regression net = tflearn.fully_connected
TFLearn示例代码 #! import numpy as np import tensorflow as tf from tflearn.layers.conv import conv_2d # Data loading from tflearn.datasets import cifar10 (X, Y), (testX, testY) = cifar10.load_data() # Add noise X = (scales) scales = tflearn.activation(scales, 'relu') scales = tflearn.fully_connected (net) net = tflearn.activation(net, 'relu') net = tflearn.global_avg_pool(net) # Regression net = tflearn.fully_connected
TFLearn程序 #! import numpy as np import tensorflow as tf from tflearn.layers.conv import conv_2d # Data loading from tflearn.datasets import cifar10 (X, Y), (testX, testY) = cifar10.load_data() # Add noise X = (scales) scales = tflearn.activation(scales, 'relu') scales = tflearn.fully_connected (net) net = tflearn.activation(net, 'relu') net = tflearn.global_avg_pool(net) # Regression net = tflearn.fully_connected