Why Keras Deep Learning Is So Popular And Implmentation Using Tensorflow

Posted By : Dipen Chawla | 28-May-2018

Keras is being hailed as the eventual fate of building neural systems. Here is a portion of the explanations behind its popularity: 

Light-weight and snappy: Keras is intended to evacuate standard code. Hardly any lines of keras code will accomplish far beyond local Tensorflow code. You can without much of a stretch plan both CNN and RNNs and can run them on either GPU or CPU. 

Developing conceivable victor: Keras is an API which keeps running over a back-end. This back-end could be either Tensorflow or Theano. Microsoft is likewise attempting to give CNTK as a back-end to Keras. At present, the universe of Neural Network is extremely divided and developing quick. Take a gander at this tweet by Karpathy:

Keras is being hailed as the eventual fate of building neural systems. Here is a portion of the purposes behind its prominence: 

Light-weight and brisk: Keras is intended to evacuate standard code. Barely any lines of keras code will accomplish far beyond local Tensorflow code. You can undoubtedly outline both CNN and RNNs and can run them on either saving and reestablish pre-prepared weights utilizing Keras: 

HDF5 Binary arrangement: 

When you are finished with preparing to utilize Keras, you can spare your system weights in HDF5 double information organize. So as to utilize this, you should have the h5py bundle introduced, which we did amid establishment. The HDF5 arrange is extraordinary to store a tremendous measure of numerical information and control this information from numpy. For instance, it's effectively conceivable to cut multi-terabyte datasets put away on a plate as though they were genuine numpy clusters. You can likewise store various datasets in a solitary record, repeat over them or look at the .shape and .dtype characteristics. 

On the off chance that it gives you a kick, even NASA stores information utilizing HDF organize. h5py lays on a question arranged Python wrapping of the HDF5 C API. Nearly anything you can do from C in HDF5, you can do from h5py. GPU or CPU. 

Developing conceivable victor: Keras is an API which keeps running over a back-end. This back-end could be either Tensorflow or Theano. Microsoft is likewise attempting to give CNTK as a back-end to Keras. Presently, the universe of Neural Network is exceptionally divided and developing quick. Take a gander at this tweet by Karpathy:

Install Keras with Tensorflow:

1. pip install h5py
2. pip install numpy scipy
3. pip install pillow
4. pip install numpy scipy
5. pip install pillow

 Keras layers on TensorFlow tensors :

 Keras will use the session :

import tensorflow as tf
sess = tf.Session()

from keras import backend as K
K.set_session(sess)

Keras layers to speed up the model definition process:

from keras.layers import Dense

# Keras layers can be called on TensorFlow tensors:
x = Dense(128, activation='relu')(img)  # fully-connected layer with 128 units and ReLU activation
x = Dense(128, activation='relu')(x)
preds = Dense(10, activation='softmax')(x)  

Train the Model:

rom tensorflow.examples.tutorials.mnist import input_data
mnist_data = input_data.read_data_sets('MNIST_data', one_hot=True)

train_step = tf.train.GradientDescentOptimizer(0.5).minimize(loss)

# Initialize all variables
init_op = tf.global_variables_initializer()
sess.run(init_op)

# Run training loop
with sess.as_default():
    for i in range(100):
        batch = mnist_data.train.next_batch(50)
        train_step.run(feed_dict={img: batch[0],
                                  labels: batch[1]})

Evaluate the Model:

from keras.metrics import categorical_accuracy as accuracy

acc_value = accuracy(labels, preds)
with sess.as_default():
    print acc_value.eval(feed_dict={img: mnist_data.test.images,
                                    labels: mnist_data.test.labels})

 

 

 

 

 

 

About Author

Author Image
Dipen Chawla

Dipen is Java Developer and his keen interest is in Spring, Hibernate, Rest web-services, AngularJS and he is a self motivated person and loves to work in a team.

Request for Proposal

Name is required

Comment is required

Sending message..