Python Deep Learning 简明教程
Libraries and Frameworks
在本章中,我们将把深度学习与不同的库和框架联系起来。
In this chapter, we will relate deep learning to the different libraries and frameworks.
Deep learning and Theano
如果我们想要开始编码深度神经网络,最好对 Theano、TensorFlow、Keras、PyTorch 等不同框架的工作原理有所了解。
If we want to start coding a deep neural network, it is better we have an idea how different frameworks like Theano, TensorFlow, Keras, PyTorch etc work.
Theano 是 python 库,它提供了一组函数,用于构建深度网络,以便在我们的机器上快速训练。
Theano is python library which provides a set of functions for building deep nets that train quickly on our machine.
Theano 是在加拿大蒙特利尔大学在深度网络先驱约书亚·本吉奥的领导下开发的。
Theano was developed at the University of Montreal, Canada under the leadership of Yoshua Bengio a deep net pioneer.
Theano 让我们能够定义和评估带向量和矩阵的数学表达式,它们是数字的矩形数组。
Theano lets us define and evaluate mathematical expressions with vectors and matrices which are rectangular arrays of numbers.
从技术上讲,神经网络和输入数据都可以表示为矩阵,所有标准网络操作都可以重新定义为矩阵操作。这很重要,因为计算机可以非常快速地执行矩阵操作。
Technically speaking, both neural nets and input data can be represented as matrices and all standard net operations can be redefined as matrix operations. This is important since computers can carry out matrix operations very quickly.
我们可以在并行处理多个矩阵值,如果我们构建具有这种底层结构的神经网络,我们可以使用带 GPU 的单台机器在合理的时间窗口内训练巨大的网络。
We can process multiple matrix values in parallel and if we build a neural net with this underlying structure, we can use a single machine with a GPU to train enormous nets in a reasonable time window.
但是,如果我们使用 Theano,我们必须从头开始构建深度网络。该库不提供用于创建特定类型深度网络的完整功能。
However if we use Theano, we have to build the deep net from ground up. The library does not provide complete functionality for creating a specific type of deep net.
相反,我们需要对深度网络的每方面进行编码,如模型、层、激活、训练方法和阻止过拟合的任何特殊方法。
Instead, we have to code every aspect of the deep net like the model, the layers, the activation, the training method and any special methods to stop overfitting.
但是,好消息是 Theano 允许在矢量化函数之上构建我们的实现,为我们提供高度优化的解决方案。
The good news however is that Theano allows the building our implementation over a top of vectorized functions providing us with a highly optimized solution.
还有许多其他可扩展 Theano 功能的库。TensorFlow 和 Keras 作为后端与 Theano 配合使用。
There are many other libraries that extend the functionality of Theano. TensorFlow and Keras can be used with Theano as backend.
Deep Learning with TensorFlow
谷歌 TensorFlow 是一个 Python 库。该库是构建商业级深度学习应用程序的不错选择。
Googles TensorFlow is a python library. This library is a great choice for building commercial grade deep learning applications.
TensorFlow 源于谷歌大脑项目的一部分 DistBelief V2 的另一个库。该库的目标是扩展机器学习的可移植性,以便将研究模型应用于商业级应用程序。
TensorFlow grew out of another library DistBelief V2 that was a part of Google Brain Project. This library aims to extend the portability of machine learning so that research models could be applied to commercial-grade applications.
类似于 Theano 库,TensorFlow 基于计算图,节点表示持久数据或数学运算,边表示节点之间的数据流,这是多维数组或张量;因此得名 TensorFlow。
Much like the Theano library, TensorFlow is based on computational graphs where a node represents persistent data or math operation and edges represent the flow of data between nodes, which is a multidimensional array or tensor; hence the name TensorFlow
运算或一组运算的输出被作为输入送入下一个运算。
The output from an operation or a set of operations is fed as input into the next.
尽管 TensorFlow 是为神经网络设计的,但它也适用于其他可以将计算建模为数据流图的网络。
Even though TensorFlow was designed for neural networks, it works well for other nets where computation can be modelled as data flow graph.
TensorFlow 还使用了 Theano 的几个特性,如通用和子表达式消除、自动微分、共享和符号变量。
TensorFlow also uses several features from Theano such as common and sub-expression elimination, auto differentiation, shared and symbolic variables.
可以使用 TensorFlow 构建不同类型的深度网络,如卷积网络、自动编码器、RNTN、RNN、RBM、DBM/MLP 等。
Different types of deep nets can be built using TensorFlow like convolutional nets, Autoencoders, RNTN, RNN, RBM, DBM/MLP and so on.
但是,TensorFlow 中不支持超参数配置。对于该功能,我们可以使用 Keras。
However, there is no support for hyper parameter configuration in TensorFlow.For this functionality, we can use Keras.
Deep Learning and Keras
Keras 是一个易于使用的强大 Python 库,用于开发和评估深度学习模型。
Keras is a powerful easy-to-use Python library for developing and evaluating deep learning models.
它采用简约的设计,允许我们逐层构建网络;训练和运行网络。
It has a minimalist design that allows us to build a net layer by layer; train it, and run it.
它封装了高效的数值计算库 Theano 和 TensorFlow,并允许我们在几行代码中定义和训练神经网络模型。
It wraps the efficient numerical computation libraries Theano and TensorFlow and allows us to define and train neural network models in a few short lines of code.
它是一个高级神经网络 API,有助于广泛使用深度学习和人工智能。它在许多较低级库(包括 TensorFlow、Theano 等)之上运行。Keras 代码是可移植的;我们可以使用 Theano 或 TensorFlow 作为后端在 Keras 中实现神经网络,而不会更改任何代码。
It is a high-level neural network API, helping to make wide use of deep learning and artificial intelligence. It runs on top of a number of lower-level libraries including TensorFlow, Theano,and so on. Keras code is portable; we can implement a neural network in Keras using Theano or TensorFlow as a back ended without any changes in code.