Keras is an open-source deep-learning library that is python based
& this high-learning API works with machine learning platforms
like TensorFlow Theano, and CNTK.
Before you start learning about Keras, you have to get a basic understanding of python and machine learning.
Why was Keras made & what purpose does it serve?
It was produced to solve machine learning problems as fast as possible and also for good research work.
Keras was designed with faster neural network implementation & experimentation in mind.
Keras gives engineers and researchers an edge and thus they can take advantage of the scalability and cross-platform capabilities of TensorFlow 2.
It prioritizes the experience of the user, the APIs are simple and consistent and thus are great at reducing cognitive load.
It is very fast and with its industry-standard level framework & scaling it is very easy.
One can run its model on TPU or large clusters of GPU, and also one can export the models to run in the browser or on a mobile phone.
The most important data structures of Keras are layers and models.
Before you start learning about Keras, you have to get a basic understanding of python and machine learning.
Why was Keras made & what purpose does it serve?
It was produced to solve machine learning problems as fast as possible and also for good research work.
Keras was designed with faster neural network implementation & experimentation in mind.
Keras gives engineers and researchers an edge and thus they can take advantage of the scalability and cross-platform capabilities of TensorFlow 2.
It prioritizes the experience of the user, the APIs are simple and consistent and thus are great at reducing cognitive load.
It is very fast and with its industry-standard level framework & scaling it is very easy.
One can run its model on TPU or large clusters of GPU, and also one can export the models to run in the browser or on a mobile phone.
The most important data structures of Keras are layers and models.
It is very easy to use as building modes in Keras are like stacking
layers or connecting graphs.
The easiest type of model in Keras is the Sequential Model which is like a linear stack of layers.
In the case of complex architectures, one should use the Keras functional API.
The Keras functional API allows one to build arbitrary graphs of layers in other words it helps one to write models all by himself from scratch via subclassing.
The easiest type of model in Keras is the Sequential Model which is like a linear stack of layers.
In the case of complex architectures, one should use the Keras functional API.
The Keras functional API allows one to build arbitrary graphs of layers in other words it helps one to write models all by himself from scratch via subclassing.
What makes Keras so unique and special amongst other frameworks and
coders?
Well, Keras is focused on user experience and since its concepts are very
easy to understand thus Keras has a large foothold in the usage of the ml
& ai industry.
It is not only multi-backend but it also is usable on multiple
platforms.
It runs fast both on CPU & GPU and it gives freedom to design
architecture.
Installation:
To install Keras use the following code
pip install keras
and you can upgrade it by using
pip install --upgrade keras
How to import keras?
from keras.models import Sequential
NOTE: I have shown the Sequential model here as it's a very simple stack
and easier to understand.
This simple stack is a linear stack of neural network layers.
Compatibility:
Keras comes along with TensorFlow 2 as tensorflow.keras. To initiate with
Keras, one should simply install TensorFlow 2.
Keras and TensorFlow are compatible with:
1. Python 3.7–3.10
2. Ubuntu 16.04 or later
3. Windows 7 or later
4. macOS 10.12.6 (Sierra) or later.
Keras and TensorFlow are compatible with:
1. Python 3.7–3.10
2. Ubuntu 16.04 or later
3. Windows 7 or later
4. macOS 10.12.6 (Sierra) or later.
Example of Keras:
add() function of Keras is generally used for stacking layers
For stacking layers on has to just use .add() function for example
Model.add( Dense (units = 64, activation = ’ value’ ) )
Model.add( Dense ( units = 10, activation = ’ value’ ) )
inpt_first = tf.keras.layers.Input(shape=(16,))
x1 = tf.keras.layers.Dense(8, activation='value')(inpt_first)
NOTE: the above code is a sample code for understanding, the above "value" can have different values in place. eg. in activation you can put "relu" or "softma".
.complile() function
When you are done with all of these things and want to compile your
query in that case use ( ) for example
In case you want to further configure your query. You can go with the further steps for example
Model.compile( loss = ’ categorial crossentropy ’ , optimizer = ‘ sgd ‘ ,metrics = [ ‘ accuracy ‘ ] )
In case you want to further configure your query. You can go with the further steps for example
Model.compile( loss = keras.losses.categorical crossentropy , optimizer = keras.optimizers.SGD ( learning rate = 0.03 , momentum = 0.8 , nesterov = True ) )
You can fit ones training data into batches using ( .fit() )
function for example
One can even test loss and metrics within the same query using ( .evaluate() ) function for example
Model.fit( X Train , Y Train , epochs = 10 , batch size = 64 )
One can even test loss and metrics within the same query using ( .evaluate() ) function for example
Loss and metrics = Model.evaluate ( X Test , Y Test , batch size = 256)
If one needs to have predictions for the data for the research work then one has to use the .predict() function for example
Classes = Model.predict ( X test , batch size = 1024)
These functions are the easiest and the most convenient way to use Keras.