Why KERAS
Keras is a wrapper that works on top of Theano or Tensor flow. Keras serves all basic needs as well as provides fine granular control over every thing needed.
I personally like Keras because of it’s following qualities:
1) API design
Keras is having well defined functions, with required and optional parameters. Keras is providing basic as well as advance function for all most everything. I would like to give you one example for the same.
Fit – to train small data Evaluate – to Evaluate trained model Predict – to predict using trained model predict_classes – to predict classes predict_proba – to get class probability, on which one can apply custom threshold train_on_batch – to train bigger data batch by batch, loads smaller chunks of data in main/GPU memory test_on_batch - to test bigger data batch by batch, loads smaller chunks of data in main/GPU memory predict_on_batch - to predict bigger data batch by batch, loads smaller chunks of data in main/GPU memory Generators are used to generate Train/Test data on the fly. E.g. to train images we often apply random transformations (vertical shift, horizontal shift, blur) to generate bigger set of images. These transformation are applied by generator function as and when data is requested for training instead of pre-processing all images and storing them in advance. Such three functions are provided by Keras.
a. fit_generator
b. evaluate_generator
c. predict_generator
2) Documentation is awesome
Keras is well maintained and in sync with the current development of its bases(theano & tensorflow). Documentation is near to perfect with each and every class is described properly.
3) Community Support
As Keras is in open source domain, with close to 400+ contributor on git-hub. With continuous involvement of people in it, max bugs are getting resolve as soon as encounters and offers better experience day by day.
4) Add-on development
Keras is add on friendly. Few days before I was looking for stacking Convolution on top of LSTM, but duee to diamention mis-match it was not possible, I got a custom function from community which in-turn helped me in completing the task.
With Keras one can design custom layers, custom evaluation function, custom early stopping.
In short Keras is awesome for beginners as welll as experts.
Once we choose Keras, we have another choice to make Theano OR Tensorflow ??
Both are best but still have some differences :
Theano
Pros:
It is more stable compare to Tensorflow for CNN and LSTM
Python and Numpy Support
LSTM and RNNs fit nicely without much hiccups
Supports multiple GPU
Cons:
Raw Theano is somewhat low-level
Error messages comes without much description
Large models like VGG16 (CNN) can have long compile time.
Tensorflow
Pros:
Python and Numpy Support
Much Faster compile times than Theano
It provides visualization with tensor board
Tensor board supports drag and drop network creation, really really easy
Slower than other thano
Cons:
Not many pre-trained models are provided
Computational graph is pure Python, therefore slow
No commercial support
error-prone on large software projects
We will working with Theano mostly, however upon getting any memmory error it is advisable to swich backend and then run the same code again, It really solve the error many time.
Installing and configuring Keras for CPU and GPU
You can also install Keras from PyPI:
sudo pip install keras
For network with bad SSL, you may use following command
pip install --index-url=http://pypi.python.org/simple/ --trusted-host pypi.python.org keras
you may also clone github directry and fire following commands
sudo python setup.py install
Keras by defaults install theano and take it as default back-end
To make tensorflow a back-end you need to install tensorflow first. You can follow this link https://www.tensorflow.org/install/ to install tensor flow.
To change backend
1) Go to keras config directory
cd ~/.keras
2) open keras config file keras.json with your favourite editor
nano keras.json
3) In back-end you may choose “theano” or “tensorflow”
{
"image_dim_ordering": "th",
"epsilon": 1e-07,
"floatx": "float32",
"backend": "theano"
}
Choosing GPU or CPU
If you have GPU device available and CUDA framwork is installed, keras will detect your GPU automatically and run on GPU. If GPU device is not present or CUDA framework is not installed, Keras will use CPU.
Comments