- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is a common debugging workflow while creating a model using Keras in Python?
Tensorflow is a machine learning framework that is provided by Google. It is an open-source framework used in conjunction with Python to implement algorithms, deep learning applications and much more. It is used in research and for production purposes. It has optimization techniques that help in performing complicated mathematical operations quickly.
This is because it uses NumPy and multi-dimensional arrays. These multi-dimensional arrays are also known as ‘tensors’.
The ‘TensorFlow’ package can be installed on Windows using the below line of code −
pip install tensorflow
Keras means ‘horn’ in Greek. Keras was developed as a part of the research for the project ONEIROS (Open ended Neuro-Electronic Intelligent Robot Operating System). It runs on top of the Tensorflow framework. It was built to help experiment in a quick manner. It provides essential abstractions and building blocks that are essential in developing and encapsulating machine learning solutions.
It is highly scalable, and comes with cross platform abilities. This means Keras can be run on TPU or clusters of GPUs. Keras models can also be exported to run in a web browser or a mobile phone as well.
Keras is already present within the Tensorflow package. It can be accessed using the below line of code.
import tensorflow from tensorflow import keras
We are using Google Colaboratory to run the below code. Google Colab or Colaboratory helps run Python code over the browser and requires zero configuration and free access to GPUs (Graphical Processing Units). Colaboratory has been built on top of Jupyter Notebook. Following is the code snippet −
Example
print("Creating a sequential model") model = keras.Sequential() print("Adding layers to it") model.add(keras.Input(shape=(250, 250, 3))) # 250x250 RGB images model.add(layers.Conv2D(32, 5, strides=2, activation="relu")) model.add(layers.Conv2D(32, 3, activation="relu")) model.add(layers.MaxPooling2D(3)) print("Data about the layers in the model") model.summary() print("Adding more layers to the model") model.add(layers.Conv2D(32, 3, activation="relu")) model.add(layers.Conv2D(32, 3, activation="relu")) model.add(layers.MaxPooling2D(3)) model.add(layers.Conv2D(32, 3, activation="relu")) model.add(layers.Conv2D(32, 3, activation="relu")) model.add(layers.MaxPooling2D(2)) print("Data about the layers in the model") model.summary() print("Applying golval max pooling") model.add(layers.GlobalMaxPooling2D()) print("Adding a classification layer to the model") model.add(layers.Dense(10))
Code credit − https://www.tensorflow.org/guide/keras/sequential_model
Output
Explanation
When a sequential architecture is being built, it is suggested to incrementally stack layers.
This can be done using the ‘add’ function.
This will frequently print more information about the model using the ‘summary’ method.
It also helps monitor how the stack of ‘Conv2D’ and ‘MaxPooling2D’ layers down-sample image feature maps.
- Related Articles
- How can Keras be used with a pre-trained model using Python?
- How can Keras be used for feature extraction using a sequential model using Python?
- How can Keras be used to reload a fresh model from the saved model using Python?
- How can Keras be used to remove a layer from the model using Python?
- How can Keras be used to plot the model using Python?
- How can Keras be used to train the model using Python?
- How can Keras be used to evaluate the model using Python?
- How can Keras be used to save model using hdf5 format in Python?
- How can Keras be used to plot the model using Python Program?
- How can Keras be used to train the model using Python Program?
- How can Keras be used to save the entire model using Python?
- How can Keras be used to evaluate the restored model using Python?
- Can a Keras model be treated as just a layer and invoked using Python? If yes, demonstrate it
- How can Keras be used to train a model with new callback in Python?
- How can Keras be used to save and serialize the model using Python?
