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

Cursusinhoud

Neural Networks with TensorFlow

Neural Networks with TensorFlow

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

book
Model Creation

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.

Keras offers two main ways to build models: the sequential API, which is simple and ideal for linear stacks of layers, and the functional API, which is more flexible and suited for complex architectures, such as models with multiple inputs, outputs, or shared layers.

With the sequential API, the code is quite straightforward:

python

With the functional API, the code is a bit more explicit and flexible:

python

Sequential Model

In this course, we will mostly use the Sequential API, which involves using the Sequential class. It's essentially a linear stack of layers. You can also view the resulting model's structure by calling the summary() method.

There are two ways to create such a model, but both come down to simply specifying the layers of the model and yield the same model. Below is the model we will create:

Method 1

The first approach is to create a Sequential model by passing a list of layers to its constructor:

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

Method 2

Alternatively, you can start with an empty Sequential model and add layers afterward using the model's add() method.

123456789101112
from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense, Activation, Input # Creating a model model = Sequential() # Adding layers model.add(Input(shape=(2,))) model.add(Dense(3)) model.add(Activation('relu')) model.summary()
copy
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 3
Onze excuses dat er iets mis is gegaan. Wat is er gebeurd?
some-alt