- Hands-On Deep Learning Architectures with Python
- Yuxi (Hayden) Liu Saransh Mehta
- 138字
- 2025-04-04 14:23:29
Sequential API
The model architecture in Keras can be built simply by stacking the layers one after the other. This is called the sequential approach in Keras and is the most common one:
from keras.models import Sequential. # importing the Sequential class
from keras.layers import Dense. #importing the Deep Learning layers
model = Sequential() #making an object of Sequential class
#adding the first Dense layer. You have to mention input dimensions to the first
#layer of model.
model.add(Dense(units=128, input_dims = 100, activation = 'relu))
model.add(Dense(units = 4, activation = 'softmax'))
When the model architecture is done, Keras uses a model.compile method to build the graph with the required loss function and optimizer and model.fit to train the model with inputs. If you're not getting what loss function is, don't worry! We will discuss all that in subsequent chapters.