首页   

资源 | GitHub万星:适用于初学者的TensorFlow代码资源集

机器之心  · AI  · 6 年前

选自GitHub

机器之心编译

参与:路雪


这套资源可以通过示例让你轻松学习 TensorFlow。至于可读性,它可以作为包括笔记本和注释的源代码教程,适合想寻找清晰准确的 TensorFlow 示例的初学者。除了传统的「原始」TensorFlow 实现之外,你还可以找到最新的 TensorFlow API 实践(如层、估计器、数据集等)。


链接:https://github.com/aymericdamien/TensorFlow-Examples


最近一次更新(2017.08.27):本教程推荐使用 TensorFlow v1.3。本次更新增加了很多新的示例(k 均值、随机森林、多 gpu 训练、层 api、估计器 api、数据集 api 等)。


如果你使用旧的 TensorFlow 版本(0.11 及以下),请点击此处查看相关示例:https://github.com/aymericdamien/TensorFlow-Examples/tree/0.11。


教程目录


0. 前提


机器学习简介:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/0_Prerequisite/ml_introduction.ipynb


MNIST 数据集简介:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/0_Prerequisite/mnist_dataset_intro.ipynb


1. 简介


Hello World


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/1_Introduction/helloworld.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/1_Introduction/helloworld.py


以上内容是非常简单的示例,教你使用 TensorFlow 输出「hello world」。


基础操作


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/1_Introduction/basic_operations.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/1_Introduction/basic_operations.py


一个简单的示例覆盖 TensorFlow 基础操作。


2. 基础模型


线性回归


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/2_BasicModels/linear_regression.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/2_BasicModels/linear_regression.py


使用 TensorFlow 实现线性回归模型。


Logistic 回归


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/2_BasicModels/logistic_regression.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/2_BasicModels/logistic_regression.py


使用 TensorFlow 实现 Logistic 回归模型。


最近邻


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/2_BasicModels/nearest_neighbor.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/2_BasicModels/nearest_neighbor.py


使用 TensorFlow 实现最近邻算法。


K 均值


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/2_BasicModels/kmeans.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/2_BasicModels/kmeans.py


使用 TensorFlow 构建 K 均值分类器。


随机森林


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/2_BasicModels/random_forest.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/2_BasicModels/random_forest.py


使用 TensorFlow 构建随机森林分类器。


3. 神经网络


监督


简单的神经网络


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/neural_network_raw.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/neural_network_raw.py


构建一个简单的神经网络(又叫作多层感知器)对 MNIST 数据集进行分类。属于原始的 TensorFlow 实现。


简单的神经网络 tf.layers/estimator api


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/neural_network.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/neural_network.py


使用 TensorFlow「层」和「估计器」API,构建简单的神经网络(又叫作多层感知器)来对 MNIST 数据集进行分类。


卷积神经网络


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/convolutional_network_raw.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/convolutional_network_raw.py


构建卷积神经网络对 MNIST 数据集进行分类。属于原始的 TensorFlow 实现。


卷积神经网络 tf.layers/estimator api


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/convolutional_network.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/convolutional_network.py


使用 TensorFlow「层」和「估计器」API,构建卷积神经网络,来对 MNIST 数据集进行分类。


循环神经网络(LSTM)


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/recurrent_network.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/recurrent_network.py


构建循环神经网络(LSTM)对 MNIST 数据集进行分类。


双向循环神经网络(LSTM)


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/bidirectional_rnn.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/bidirectional_rnn.py


构建一个双向循环神经网络(LSTM)对 MNIST 数据集进行分类。


动态循环神经网络(LSTM)


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/dynamic_rnn.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/dynamic_rnn.py


构建一个动态循环神经网络(LSTM)来执行动态计算,来对不同长度的序列进行分类。


非监督


自编码器


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/autoencoder.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/autoencoder.py


构建一个自编码器对图像进行编码,使之降维,然后重建该图像。


变分自编码器


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/Variational_autoencoder.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/Variational_autoencoder.py


构建一个变分自编码器(VAE)对图像进行编码,利用噪声生成图像。


生成对抗网络(GAN)


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/gan.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/gan.py


构建一个生成对抗网络,利用噪声生成图像。


深度卷积生成对抗网络(DCGAN)


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/dcgan.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/dcgan.py


构建一个深度卷积生成对抗网络,利用噪声生成图像。


4. 工具


保存和存储模型


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/4_Utils/save_restore_model.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/4_Utils/save_restore_model.py


使用 TensorFlow 保存和存储模型。


Tensorboard——图和损失可视化


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/4_Utils/tensorboard_basic.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/4_Utils/tensorboard_basic.py


使用 Tensorboard 使计算图和损失可视化。


Tensorboard——高级可视化


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/4_Utils/tensorboard_advanced.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/4_Utils/tensorboard_advanced.py


深入了解 Tensorboard;使变量、梯度等可视化。


5. 数据管理


构建图像数据集


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/5_DataManagement/build_an_image_dataset.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/5_DataManagement/build_an_image_dataset.py


使用 TensorFlow 数据队列从图像文件夹或数据集文件构建自己的图像数据集。


TensorFlow 数据集 API


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/5_DataManagement/tensorflow_dataset_api.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/5_DataManagement/tensorflow_dataset_api.py


引入 TensorFlow 数据集 API,优化输入数据管道。


6. 多 GPU


在多 GPU 上进行的基础操作


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/6_MultiGPU/multigpu_basics.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/5_MultiGPU/multigpu_basics.py


一个简单的在 TensorFlow 中引入多 GPU 的示例。


在多 GPU 上训练神经网络


笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/6_MultiGPU/multigpu_cnn.ipynb


代码:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/5_MultiGPU/multigpu_cnn.py


一个清晰简单的 TensorFlow 实现,在多个 GPU 上训练卷积神经网络。


数据集


一些示例要求使用 MNIST 数据集进行训练和测试。不要担心,示例运行时,该数据集可以自动下载。MNIST 是一个手写数字数据库,想了解该数据集的简介,请查看笔记本:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/0_Prerequisite/mnist_dataset_intro.ipynb


官方网址:http://yann.lecun.com/exdb/mnist/


安装


下载所有示例,只需复制该 repository:


  1. git clone https://github.com/aymericdamien/TensorFlow-Examples


要想运行示例,你还需要 TensorFlow 的最新版本。使用下列方式安装:


  1. pip install tensorflow


或下列方式(如果你想获取 GPU 支持):


  1. pip install tensorflow_gpu


关于 TensorFlow 安装的更多细节,请查看 TensorFlow 安装指南:https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md


更多示例


下列示例来自 TFLearn,一个提供 TensorFlow 简化接口的库,其中有很多内容可供参考,包括很多示例:https://github.com/tflearn/tflearn/tree/master/examples


和预置操作和层:http://tflearn.org/doc_index/#api


教程


TFLearn 快速入门:https://github.com/tflearn/tflearn/blob/master/tutorials/intro/quickstart.md


通过具体的机器学习任务学习 TFLearn 基础。构建和训练一个深度神经网络分类器。


示例


TFLearn 示例:https://github.com/tflearn/tflearn/blob/master/examples


使用 TFLearn 的示例的大型集合。 



本文为机器之心编译,转载请联系本公众号获得授权

✄------------------------------------------------

加入机器之心(全职记者/实习生):hr@jiqizhixin.com

投稿或寻求报道:content@jiqizhixin.com

广告&商务合作:bd@jiqizhixin.com

推荐文章
中信建投期货微资讯  ·  建投专题 · ...  ·  3 天前  
君合法律评论  ·  《君合生命健康与医疗法律月报》总第61期  ·  5 月前  
华夏时报  ·  GDP或达110万亿!2021中国经济“成绩 ...  ·  2 年前  
© 2022 51好读
删除内容请联系邮箱 2879853325@qq.com