In a sequential model, we can add layers one by one with different arguments. So have you tried to add layers in sequential model?
So this recipe is a short example of how we can add layers sequentially to keras model.
import pandas as pd import numpy as np from keras.datasets import mnist from sklearn.model_selection import train_test_split from keras.models import Sequential from keras.layers import Dense from keras.layers import Dropout
We have imported pandas, numpy, mnist(which is the dataset), train_test_split, Sequential, Dense and Dropout. We will use these later in the recipe.
Here we have used the inbuilt mnist dataset and stored the train data in X_train and y_train. We have used X_test and y_test to store the test data.
(X_train, y_train), (X_test, y_test) = mnist.load_data()
We have created an object model for the sequential model. We can use two args i.e layers and name.
model = Sequential()Now, We are adding the layers by using 'add'. We can specify the type of layer, activation function to be used and many other things while adding the layer.
model.add(Dense(512)) model.add(Dropout(0.3)) model.add(Dense(256, activation='relu')) model.add(Dropout(0.2))