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

Contenido del Curso

Neural Networks with TensorFlow

Neural Networks with TensorFlow

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

bookModel 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.

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 2
some-alt