Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Model Creation | Basics of Keras
Neural Networks with TensorFlow
course content

Course Content

Neural Networks with TensorFlow

Neural Networks with TensorFlow

1. Basics of Keras
2. Regularization
3. Advanced Techniques

Model Creation

Neural Network Structure

From the previous chapter, we've seen how to create individual layers. It's important to understand that these layers become effective only when they are integrated into a cohesive model.

Sequential Model

In Keras, a straightforward way to construct a model is by using the Sequential model. It's essentially a linear stack of layers.

Note

You can use model.summary() to view the model's structure.

Method 1

Initiate a Sequential model by passing a list of layers to the constructor.

1234567891011
from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense, Activation, Input # Create a model with layers model = Sequential([ Input(shape=(2,)), Dense(units=3), Activation('relu'), ]) model.summary()
copy

Method 2

Alternatively, start with an empty Sequential model and add layers post-creation.

Note

This approach is generally more flexible, allowing for dynamic model assembly. Due to its adaptability, it's often the preferred method.

123456789101112
from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense, Activation, Input # Create a model model = Sequential() # Add layers model.add(Input(shape=(2,))) model.add(Dense(units=3)) model.add(Activation('relu')) model.summary()
copy

Both methods yield the same model.

Everything was clear?

Section 1. Chapter 2
We're sorry to hear that something went wrong. What happened?
some-alt