Contenido del Curso
Neural Networks with TensorFlow
Neural Networks with TensorFlow
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.
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()
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.
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()
Both methods yield the same model.
¡Gracias por tus comentarios!