数十种TensorFlow实现案例汇集
EddyNealy
8年前
<p>这是使用 TensorFlow 实现流行的机器学习算法的教程汇集。本汇集的目标是让读者可以轻松通过案例深入 TensorFlow。</p> <p>这些案例适合那些想要清晰简明的 TensorFlow 实现案例的初学者。本教程还包含了笔记和带有注解的代码。</p> <ul> <li> <p>项目地址: <a href="/misc/goto?guid=4959648869643362601" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples</a></p> </li> </ul> <p>教程索引</p> <p>0 - 先决条件</p> <p>机器学习入门:</p> <ul> <li> <p>笔记: <a href="/misc/goto?guid=4959721147985698083" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/0_Prerequisite/ml_introduction.ipynb</a></p> </li> <li> <p>MNIST 数据集入门</p> </li> <li> <p>笔记: <a href="/misc/goto?guid=4959721148081953511" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/0_Prerequisite/mnist_dataset_intro.ipynb</a></p> </li> </ul> <h3><strong>1 - 入门</strong></h3> <p>Hello World:</p> <ul> <li> <p>笔记: <a href="/misc/goto?guid=4959721148166240344" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/1_Introduction/helloworld.ipynb</a></p> </li> <li> <p>代码 <a href="/misc/goto?guid=4959721148249443791" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/1_Introduction/helloworld.py</a></p> </li> </ul> <p>基本操作:</p> <ul> <li> <p>笔记: <a href="/misc/goto?guid=4959721148357075750" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/1_Introduction/basic_operations.ipynb</a></p> </li> <li> <p>代码: <a href="/misc/goto?guid=4959721148442939154" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/1_Introduction/basic_operations.py</a></p> </li> </ul> <h3><strong>2 - 基本模型</strong></h3> <p>最近邻:</p> <ul> <li> <p>笔记: <a href="/misc/goto?guid=4959721148517382950" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/2_BasicModels/nearest_neighbor.ipynb</a></p> </li> <li> <p>代码: <a href="/misc/goto?guid=4959721148611168506" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/2_BasicModels/nearest_neighbor.py</a></p> </li> </ul> <p>线性回归:</p> <ul> <li> <p>笔记: <a href="/misc/goto?guid=4959721148692300910" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/2_BasicModels/linear_regression.ipynb</a></p> </li> <li> <p>代码: <a href="/misc/goto?guid=4959721148768689331" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/2_BasicModels/linear_regression.py</a></p> </li> </ul> <p>Logistic 回归:</p> <ul> <li> <p>笔记: <a href="/misc/goto?guid=4959721148855101762" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/2_BasicModels/logistic_regression.ipynb</a></p> </li> <li> <p>代码: <a href="/misc/goto?guid=4959721148944449929" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/2_BasicModels/logistic_regression.py</a></p> </li> </ul> <h3><strong>3 - 神经网络</strong></h3> <p>多层感知器:</p> <ul> <li> <p>笔记: <a href="/misc/goto?guid=4959721149027485330" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/multilayer_perceptron.ipynb</a></p> </li> <li> <p>代码: <a href="/misc/goto?guid=4959721149114879405" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/multilayer_perceptron.py</a></p> </li> </ul> <p>卷积神经网络:</p> <ul> <li> <p>笔记: <a href="/misc/goto?guid=4959721149197989811" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/convolutional_network.ipynb</a></p> </li> <li> <p>代码: <a href="/misc/goto?guid=4959721149280321443" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/convolutional_network.py</a></p> </li> </ul> <p>循环神经网络(LSTM):</p> <ul> <li> <p>笔记: <a href="/misc/goto?guid=4959721149358872108" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/recurrent_network.ipynb</a></p> </li> <li> <p>代码: <a href="/misc/goto?guid=4959721149448006187" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/recurrent_network.py</a></p> </li> </ul> <p>双向循环神经网络(LSTM):</p> <ul> <li> <p>笔记: <a href="/misc/goto?guid=4959721149533174268" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/bidirectional_rnn.ipynb</a></p> </li> <li> <p>代码: <a href="/misc/goto?guid=4959721149615536913" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/bidirectional_rnn.py</a></p> </li> </ul> <p>动态循环神经网络(LSTM)</p> <ul> <li> <p>代码: <a href="/misc/goto?guid=4959721149694565607" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/dynamic_rnn.py</a></p> </li> </ul> <p>自编码器</p> <ul> <li> <p>笔记: <a href="/misc/goto?guid=4959721149784966861" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/3_NeuralNetworks/autoencoder.ipynb</a></p> </li> <li> <p>代码: <a href="/misc/goto?guid=4959721149867479500" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/autoencoder.py</a></p> </li> </ul> <h3><strong>4 - 实用技术</strong></h3> <p>保存和恢复模型</p> <ul> <li> <p>笔记: <a href="/misc/goto?guid=4959721149949255018" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/4_Utils/save_restore_model.ipynb</a></p> </li> <li> <p>代码: <a href="/misc/goto?guid=4959721150032432589" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/4_Utils/save_restore_model.py</a></p> </li> </ul> <p>图和损失可视化</p> <ul> <li> <p>笔记: <a href="/misc/goto?guid=4959721150120364563" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/4_Utils/tensorboard_basic.ipynb</a></p> </li> <li> <p>代码: <a href="/misc/goto?guid=4959721150200835293" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/4_Utils/tensorboard_basic.py</a></p> </li> </ul> <p>Tensorboard——高级可视化</p> <ul> <li> <p>代码: <a href="/misc/goto?guid=4959721150286872742" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/4_Utils/tensorboard_advanced.py</a></p> </li> </ul> <h3><strong>5 - 多 GPU</strong></h3> <p>多 GPU 上的基本操作</p> <ul> <li> <p>笔记: <a href="/misc/goto?guid=4959721150371052849" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/5_MultiGPU/multigpu_basics.ipynb</a></p> </li> <li> <p>代码: <a href="/misc/goto?guid=4959721150453996987" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/5_MultiGPU/multigpu_basics.py</a></p> </li> </ul> <p>数据集</p> <p>一些案例需要 MNIST 数据集进行训练和测试。不要担心,运行这些案例时,该数据集会被自动下载下来(使用 input_data.py) 。MNIST 是一个手写数字的数据库,查看这个笔记了解关于该数据集的描述: <a href="/misc/goto?guid=4959721148081953511" rel="nofollow,noindex">https://github.com/aymericdamien/TensorFlow-Examples/blob/master/notebooks/0_Prerequisite/mnist_dataset_intro.ipynb</a></p> <ul> <li> <p>官方网站: <a href="/misc/goto?guid=4959616969854868915" rel="nofollow,noindex"> http://yann.lecun.com/exdb/mnist/ </a></p> </li> </ul> <h3><strong>更多案例</strong></h3> <p>接下来的示例来自 <a href="/misc/goto?guid=4959721150577216517" rel="nofollow,noindex"> TFLearn </a> ,这是一个为 TensorFlow 提供了简化的接口的库。你可以看看,这里有很多示例和预构建的运算和层。</p> <ul> <li> <p>示例: <a href="/misc/goto?guid=4959721150660744747" rel="nofollow,noindex"> https://github.com/tflearn/tflearn/tree/master/examples </a></p> </li> <li> <p>预构建的运算和层: <a href="/misc/goto?guid=4959721150660744747" rel="nofollow,noindex"> http://tflearn.org/doc_index/#api </a></p> </li> </ul> <h3><strong>教程</strong></h3> <p>TFLearn 快速入门。通过一个具体的机器学习任务学习 TFLearn 基础。开发和训练一个深度神经网络分类器。</p> <ul> <li> <p>笔记:<https://github.com/tflearn/tflearn/blob/master/tutorials/intro/quickstart.md</p> </li> </ul> <h3><strong>基础</strong></h3> <ul> <li> <p>线性回归,使用 TFLearn 实现线性回归: <a href="/misc/goto?guid=4959721150755503517" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/basics/linear_regression.py</a></p> </li> <li> <p>逻辑运算符。使用 TFLearn 实现逻辑运算符: <a href="/misc/goto?guid=4959721150841787665" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/basics/logical.py</a></p> </li> <li> <p>权重保持。保存和还原一个模型: <a href="/misc/goto?guid=4959721150924873010" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/basics/weights_persistence.py</a></p> </li> <li> <p>微调。在一个新任务上微调一个预训练的模型: <a href="/misc/goto?guid=4959721151004677823" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/basics/finetuning.py</a></p> </li> <li> <p>使用 HDF5。使用 HDF5 处理大型数据集: <a href="/misc/goto?guid=4959721151092868640" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/basics/use_hdf5.py</a></p> </li> <li> <p>使用 DASK。使用 DASK 处理大型数据集: <a href="/misc/goto?guid=4959721151175132581" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/basics/use_dask.py</a></p> </li> </ul> <h3><strong>计算机视觉</strong></h3> <ul> <li> <p>多层感知器。一种用于 MNIST 分类任务的多层感知实现: <a href="/misc/goto?guid=4959721151250547593" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/images/dnn.py</a></p> </li> <li> <p>卷积网络(MNIST)。用于分类 MNIST 数据集的一种卷积神经网络实现: <a href="/misc/goto?guid=4959721151333787775" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/images/convnet_mnist.py</a></p> </li> <li> <p>卷积网络(CIFAR-10)。用于分类 CIFAR-10 数据集的一种卷积神经网络实现: <a href="/misc/goto?guid=4959721151418636662" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/images/convnet_cifar10.py</a></p> </li> <li> <p>网络中的网络。用于分类 CIFAR-10 数据集的 Network in Network 实现: <a href="/misc/goto?guid=4959721151501128895" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/images/network_in_network.py</a></p> </li> <li> <p>Alexnet。将 Alexnet 应用于 Oxford Flowers 17 分类任务: <a href="/misc/goto?guid=4959721151588761619" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/images/alexnet.py</a></p> </li> <li> <p>VGGNet。将 VGGNet 应用于 Oxford Flowers 17 分类任务: <a href="/misc/goto?guid=4959721151668987381" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/images/vgg_network.py</a></p> </li> <li> <p>VGGNet Finetuning (Fast Training)。使用一个预训练的 VGG 网络并将其约束到你自己的数据上,以便实现快速训练: <a href="/misc/goto?guid=4959721151741116311" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/images/vgg_network_finetuning.py</a></p> </li> <li> <p>RNN Pixels。使用 RNN(在像素的序列上)分类图像: <a href="/misc/goto?guid=4959721151829030344" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/images/rnn_pixels.py</a></p> </li> <li> <p>Highway Network。用于分类 MNIST 数据集的 Highway Network 实现: <a href="/misc/goto?guid=4959721151912730113" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/images/highway_dnn.py</a></p> </li> <li> <p>Highway Convolutional Network。用于分类 MNIST 数据集的 Highway Convolutional Network 实现: <a href="/misc/goto?guid=4959721151993935346" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/images/convnet_highway_mnist.py</a></p> </li> <li> <p>Residual Network (MNIST) ( <a href="/misc/goto?guid=4959721152077559398" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/images/residual_network_mnist.py</a> ).。应用于 MNIST 分类任务的一种瓶颈残差网络(bottleneck residual network): <a href="/misc/goto?guid=4959721152077559398" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/images/residual_network_mnist.py</a></p> </li> <li> <p>Residual Network (CIFAR-10)。应用于 CIFAR-10 分类任务的一种残差网络: <a href="/misc/goto?guid=4959721152171272958" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/images/residual_network_cifar10.py</a></p> </li> <li> <p>Google Inception(v3)。应用于 Oxford Flowers 17 分类任务的谷歌 Inception v3 网络: <a href="/misc/goto?guid=4959721152258226884" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/images/googlenet.py</a></p> </li> <li> <p>自编码器。用于 MNIST 手写数字的自编码器: <a href="/misc/goto?guid=4959721152339565069" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/images/autoencoder.py</a></p> </li> </ul> <h3><strong>自然语言处理</strong></h3> <ul> <li> <p>循环神经网络(LSTM),应用 LSTM 到 IMDB 情感数据集分类任务: <a href="/misc/goto?guid=4959721152412717357" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/nlp/lstm.py</a></p> </li> <li> <p>双向 RNN(LSTM),将一个双向 LSTM 应用到 IMDB 情感数据集分类任务: <a href="/misc/goto?guid=4959721152500773974" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/nlp/bidirectional_lstm.py</a></p> </li> <li> <p>动态 RNN(LSTM),利用动态 LSTM 从 IMDB 数据集分类可变长度文本: <a href="/misc/goto?guid=4959721152592915380" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/nlp/dynamic_lstm.py</a></p> </li> <li> <p>城市名称生成,使用 LSTM 网络生成新的美国城市名: <a href="/misc/goto?guid=4959721152664823065" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/nlp/lstm_generator_cityname.py</a></p> </li> <li> <p>莎士比亚手稿生成,使用 LSTM 网络生成新的莎士比亚手稿: <a href="/misc/goto?guid=4959721152753468004" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/nlp/lstm_generator_shakespeare.py</a></p> </li> <li> <p>Seq2seq,seq2seq 循环网络的教学示例: <a href="/misc/goto?guid=4959721152835551816" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/nlp/seq2seq_example.py</a></p> </li> <li> <p>CNN Seq,应用一个 1-D 卷积网络从 IMDB 情感数据集中分类词序列: <a href="/misc/goto?guid=4959721152920401874" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/nlp/cnn_sentence_classification.py</a></p> </li> </ul> <h3><strong>强化学习</strong></h3> <p>Atari Pacman 1-step Q-Learning,使用 1-step Q-learning 教一台机器玩 Atari 游戏: <a href="/misc/goto?guid=4959721153004457370" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/reinforcement_learning/atari_1step_qlearning.py</a></p> <p>其他</p> <p>Recommender-Wide&Deep Network,推荐系统中 wide & deep 网络的教学示例: <a href="/misc/goto?guid=4959721153080820753" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/others/recommender_wide_and_deep.py</a></p> <p>Notebooks</p> <ul> <li> <p>Spiral Classification Problem,对斯坦福 CS231n spiral 分类难题的 TFLearn 实现: <a href="/misc/goto?guid=4959721153167976553" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/notebooks/spiral.ipynb</a></p> </li> </ul> <h3><strong>可延展的 TensorFlow</strong></h3> <ul> <li> <p>层,与 TensorFlow 一起使用 TFLearn 层: <a href="/misc/goto?guid=4959721153243262281" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/extending_tensorflow/layers.py</a></p> </li> <li> <p>训练器,使用 TFLearn 训练器类训练任何 TensorFlow 图: <a href="/misc/goto?guid=4959721153243262281" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/extending_tensorflow/layers.py</a></p> </li> <li> <p>Bulit-in Ops,连同 TensorFlow 使用 TFLearn built-in 操作: <a href="/misc/goto?guid=4959721153337855967" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/extending_tensorflow/builtin_ops.py</a></p> </li> <li> <p>Summaries,连同 TensorFlow 使用 TFLearn summarizers: <a href="/misc/goto?guid=4959721153424528447" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/extending_tensorflow/summaries.py</a></p> </li> <li> <p>Variables,连同 TensorFlow 使用 TFLearn Variables: <a href="/misc/goto?guid=4959721153503412775" rel="nofollow,noindex">https://github.com/tflearn/tflearn/blob/master/examples/extending_tensorflow/variables.py</a></p> </li> </ul> <p> </p> <p>来自:http://www.jiqizhixin.com/article/1648</p> <p> </p>