- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions

# How can Tensorflow be used to create a sequential model using Python?

A sequential model can be created using the ‘Sequential’ API that uses the ‘ **layers.experimental.preprocessing.Rescaling**’ method. The other layers are specified while created the model.

**Read More:**
What is TensorFlow and how Keras work with TensorFlow to create Neural Networks?

We will use the Keras Sequential API, which is helpful in building a sequential model that is used to work with a plain stack of layers, where every layer has exactly one input tensor and one output tensor.

We are using the 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.

print("Sequential model is being created") num_classes = 5 model = Sequential([ layers.experimental.preprocessing.Rescaling(1./255, input_shape=(img_height, img_width, 3)), layers.Conv2D(16, 3, padding='same', activation='relu'), layers.MaxPooling2D(), layers.Conv2D(32, 3, padding='same', activation='relu'), layers.MaxPooling2D(), layers.Conv2D(64, 3, padding='same', activation='relu'), layers.MaxPooling2D(), layers.Flatten(), layers.Dense(128, activation='relu'), layers.Dense(num_classes) ])

Code credit: https://www.tensorflow.org/tutorials/images/classification

## Output

Sequential model is being created

## Explanation

- The model contains three convolution blocks and a max pool layer in each of them.
- It also has a fully connected layer with 128 units on top of it.
- This gets activated by a relu activation function.
- This model isn't tuned for high accuracy.
- A sequential model with three layers is created.

- Related Articles
- How can Tensorflow be used with abalone dataset to build a sequential model?
- How can TensorFlow be used with keras.Model to track the variables defined using sequential model?
- How can a sequential model be built on Auto MPG using TensorFlow?
- How can Tensorflow be used to evaluate a CNN model using Python?
- How can a sequential model be created incrementally with Tensorflow in Python?
- How can Tensorflow be used to compile the model using Python?
- How can Tensorflow be used to train the model using Python?
- How can Keras be used for feature extraction using a sequential model using Python?
- How can a sequential model be built on Auto MPG dataset using TensorFlow?
- How can Tensorflow be used to export the model built using Python?
- How can Tensorflow be used to export the built model using Python?
- How can Tensorflow be used to compile the exported model using Python?
- Explain how a sequential model (Dense Layer) be built in Tensorflow using Python
- How can Tensorflow and pre-trained model be used to compile the model using Python?
- How can Tensorflow be used to create a convolutional base using Python?