Theano vs TensorFlow : A Quick Comparision of Frameworks

Now that you have known about the Salary of Network Security Engineer, you must be attracted to achieving it. If you wish to have it, you must have to do lots and lots of studies, unless you have a good and reliable COmpTIA Project+ PK0 004 Dumps provider like that of the ITCertDumps.

The era of Deep Learning and Machine Learning is at its peak. It is going to create 2.3 Million Jobs by 2020. With new frameworks coming up every month, TensorFlow and Theano have been there for a while and have gained a good amount of popularity as well. So in this Theano vs TensorFlow article, I’ll be discussing the following topics:

  • What is Theano?
  • What is TensorFlow?
  • Theano vs Tensorflow
      • Popularity
      • Execution Speed
      • Technology Benefits
      • Compatibility
      • Community Support
      • Code Readability
  • Final Verdict: Theano vs TensorFlow


What is Theano?

Theano can be defined as a library for Scientific Computing. It was developed by the Université de Montréal and has been available since 2007.

It allows you to define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays efficiently. It can run on both CPU and GPU.


What is TensorFlow?

TensorFlow is an open-source software library by Google Brain for dataflow programming across a range of tasks.

It is a symbolic math library that is used for machine learning applications like neural networks.


Theano vs TensorFlow

We will compare Theano vs TensorFlow based on the following Metrics:


Theano TensorFlow
Theano being an old Framework is not that popular among Data Scientists, Researchers. It was once upon a time TensorFlow is hands down the most famous Deep Learning Framework and is used in a lot of research.


Execution Speed:

Theano TensorFlow
Performs Tasks Faster than TensorFlow. Especially the single GPU Tasks run, way fast in Theano. TensorFlow’s Execution speed is Slower as compared to Theano, But in Multi-GPU Tasks it takes the Lead.


Technology Benefits:

Theano TensorFlow
It supports a wide range of Operations.

Theano computes the gradient when determining the Backpropagation error.

You have full control over Optimizers as you have to hard code it.

TensorFlow still has to come at par with Theano.

That’s not the case for TensorFlow

It gives access to lots of good Optimizers out of the box. Which makes Coding Easier



Acquiring the certification isn‘s going to be an easy task, but if you have the expertise help of the COmpTIA Network+ N10 007 Dumps offered at the ITCertDumps, you would be able to achieve it in a single attempt.

ccnp exam

Theano TensorFlow
Keras an amazing Deep Learning Library is compatible with Theano. It Integrates Well.

It has Native Windows Support.

It also supports High-Level Wrappers like Lasagne.

But In case of TensorFlow, it’s not quite there yet. However, in v2.0 this won’t be the case.

Currently, TensorFlow lacks this Support.

No Support for Lasagne.


Community Support:

Theano TensorFlow
 Theano has Bigger Community Support as it came way before TensorFlow.

It has More Documentation than TensorFlow

TensorFlow’s Online Community Support is Increasing rapidly with its Popularity.

Documentation is comparatively lesser.


Code Readability:

Let us Compare Theano vs TensorFlow based on their Code. Here I’m Taking a Basic Example Script where we will take some Phony data and initialize the best fit for that data so it can predict future data points.

Theano Code:

import theanoimport theano.tensor as Timport numpy# Again, make 100 points in numpyx_data = numpy.float32(numpy.random.rand(2, 100))y_data =[0.100, 0.200], x_data) + 0.3# Intialise the Theano modelX = T.matrix()Y = T.vector()b = theano.shared(numpy.random.uniform(-1, 1), name="b")W = theano.shared(numpy.random.uniform(-1.0, 1.0, (1, 2)), name="W")y = + b # Compute the gradients WRT the mean-squared-error for each parametercost = T.mean(T.sqr(y - Y))gradientW = T.grad(cost=cost, wrt=W)gradientB = T.grad(cost=cost, wrt=b)updates = [[W, W - gradientW * 0.5], [b, b - gradientB * 0.5]] train = theano.function(inputs=[X, Y], outputs=cost, updates=updates, allow_input_downcast=True) for i in xrange(0, 201):    train(x_data, y_data)    print W.get_value(), b.get_value()

Equivalent TensorFlow Code:

import tensorflow as tfimport numpy as np# Make 100 phony data points in NumPy.x_data = np.float32(np.random.rand(2, 100)) # Random inputy_data =[0.100, 0.200], x_data) + 0.300# Construct a linear model.b = tf.Variable(tf.zeros([1]))W = tf.Variable(tf.random_uniform([1, 2], -1.0, 1.0))y = tf.matmul(W, x_data) + b# Minimize the squared errors.loss = tf.reduce_mean(tf.square(y - y_data))optimizer = tf.train.GradientDescentOptimizer(0.5)train = optimizer.minimize(loss)# For initializing the variables.init = tf.initialize_all_variables()# Launch the graphsess = tf.Session() Fit the plane.for step in xrange(0, 201):    if step % 20 == 0:        print step,, Learns best fit is W: [[0.100  0.200]], b: [0.300]

Length Wise Both the Code are almost Similar there’s not much difference. Two identically-generated NumPy arrays describing the input, and the target output. But if we have a look at the Model Initialization.

Model Initialization:

# TensorFlowb = tf.Variable(tf.zeros([1]))W = tf.Variable(tf.random_uniform([1, 2], -1.0, 1.0))y = tf.matmul(W, x_data) + b# TheanoX = T.matrix()Y = T.vector()b = theano.shared(numpy.random.uniform(-1, 1), name="b")W = theano.shared(numpy.random.uniform(-1.0, 1.0, (1, 2)), name="W")y = + b

As you can see here that TensorFlow doesn’t require any Special Treatment of X and Y Variables. On the other hand, Theano requires an extra effort to make sure that the variables are Symbolic Inputs to the Function. The definition of b and W are explanatory and also nicer.

The Learning: Optimization

# Tensorflowloss = tf.reduce_mean(tf.square(y - y_data)) # (1)optimizer = tf.train.GradientDescentOptimizer(0.5) # (2)train = optimizer.minimize(loss) # (3)# Theanocost = T.mean(T.sqr(y - Y)) # (1)gradientW = T.grad(cost=cost, wrt=W) # (2)gradientB = T.grad(cost=cost, wrt=b) # (2)updates = [[W, W - gradientW * 0.5], [b, b - gradientB * 0.5]] # (2)train = theano.function(inputs=[X, Y], outputs=cost, updates=updates, allow_input_downcast=True) # (3)

For (1) the MSE is almost the same for Theano vs TensorFlow.

For (2) Defining the Optimizer is easy and simple as it gets in case of TensorFlow, but Theanno gives you a great deal of Control overt the Optimizers although its quite lengthy and increases Verification Effort.

For (3) Training Function the Code is almost Similar


Training Body:

# TensorFlowinit = tf.initialize_all_variables()sess = tf.Session() step in xrange(0, 201): Theanofor i in xrange(0, 201):    train(x_data, y_data)    print W.get_value(), b.get_value()

The code for Training is almost Identical, but Encapsulating the Graph Execution in Session Object is Conceptually Cleaner than Theano.


Final Verdict: Theano vs TensorFlow

On a Concluding Note, it can be said that both APIs have a similar Interface. But TensorFlow is comparatively easier yo use as it provides a lot of Monitoring and Debugging Tools. Theano takes the Lead in Usability and Speed, but TensorFlow is better suited for Deployment. Paperwork or Documentation for Theano is more than TensorFlow and TensorFlow being a new Language people don’t have many resources, to begin with. Open-source deep-libraries such as Keras, Lasagne and Blocks have been built on top of Theano.

I hope this comparison was enough for you to decide which framework to opt for, check out the AI and Deep Learning With Tensorflow by Edureka, a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe. This Certification Training is curated by industry professionals as per the industry requirements & demands. You will master the concepts such as SoftMax function, Autoencoder Neural Networks, Restricted Boltzmann Machine (RBM) and work with libraries like Keras & TFLearn.

Got a question for us? Please mention it in the comments section of “Theano vs TensorFlow” and we will get back to you.

Posted in Uncategorized

Leave a Reply

Your email address will not be published.