Introduction to Theano

Theano is a Python library for fast numerical computation that can be run on the CPU or GPU.

It is a key foundational library for deep learning in Python that you can use directly to create deep learning models. After completing this lesson, you will know:

  • About the Theano library for Python
  • How a very simple symbolic expression can be defined, compiled and calculated.
  • Where you can learn more about Theano

2.1 What is Theano?

At it’s heart Theano is a compiler for mathematical expressions in Python. It knows how to take your structures and turn them into very efficient code that uses NumPy,efficient native libraries like BLAS and native code to run as fast as possible on CPUs or GPUs.

It uses a host of clever code optimizations to squeeze as much performance as possible from your hardware. If you are into the nitty-gritty of mathematical optimizations in code, check out this interesting list2. The actual syntax of Theano expressions is symbolic, which can be o↵ putting to beginners. Specifically, expression are defined in the abstract sense, compiled and later actually used to make calculations. Theano was specifically designed to handle the types of computation required for large neural network algorithms used in deep learning. It was one of the first libraries of its kind (development started in 2007) and is considered an industry standard for deep learning research and development

2.2 How to Install Theano

Theano provides extensive installation instructions for the major operating systems: Windows, OS X and Linux.Theano assumes a working Python 2 or Python 3 environment with SciPy.There are ways to make the installation easier, such as using Anaconda4 to quickly setup Python and SciPy on your machine as well as using Docker images. With a working Python and SciPy environment, it is relatively straightforward to install Theano using pip, for example

Install Theano using pip :

 pip install Theano

 New releases of Theano may be announced and you will want to update to get any bug fixes and efficiency improvements . You can upgrade Theano using pip as follows:

pip install --upgrade --no-deps theano

 You may want to use the bleeding edge version of Theano checked directly out of GitHub. This may be required for some wrapper libraries that make use of bleeding edge API changes. You can install Theano directly from a GitHub checkout as follows:

pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git

2.3 Simple Theano Example

In this section we demonstrate a simple Python script that gives you a flavor of Theano.

 

# Example of Theano library
import theano

from theano import tensor

# declare two symbolic floating-point scalars
a = tensor.dscalar()
b = tensor.dscalar()

# create a simple symbolic expression
c = a + b

# convert the expression into a callable object that taes (a,b) and computes c
f = theano.function([a,b], c)

# bind 1.5 to 'a', 2.5 to 'b' and evaluate 'c'
result = f(1.5, 2.5)
print(result)

2.4 Extensions and Wrappers for Theano

If you are new to deep learning you do not have to use Theano directly. In fact, you are highly encouraged to use one of many popular Python projects that make Theano a lot easier to use for deep learning. These projects provide data structures and behaviors in Python, specifically designed to quickly and reliably create deep learning models whilst ensuring that fast and efficient models are created and executed by Theano under the covers. The amount of Theano syntax exposed by the libraries varies.

   Keras is a wrapper library that hides Theano completely and provides a very simple API to work with to create deep learning models. It hides Theano so well, that it can in fact run as a wrapper for another popular foundation framework called TensorFlow (discussed next).

2.5 More Theano Resources

Looking for some more resources on Theano? Take a look at some of the following.

http://deeplearning.net/software/theano/

https://github.com/Theano/Theano/

http://www.iro.umontreal.ca/~lisa/pointeurs/theano_scipy2010.pdf

https://github.com/Theano/Theano/wiki/Related-projects

http://deeplearning.net/software/theano/library/config.html

 2.6 Summary

In this lesson you discovered the Theano Python library for efficient numerical computation.

You learned :

  • Theano is a foundation library used for deep learning research and development.
  • Deep learning models can be developed directly in Theano if desired.
  • The  development and evaluation of deep learning models is easier with wrapper libraries like Keras.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值