# | Likes | Tech tags | Title | Creator | Created date |
---|---|---|---|---|---|
1 | 0 |
TensorFlow
Keras
|
2022-10-01 23:28
|
Trains a model with the RMSprop optimizer, categorical crossentropy loss function and with batching and validation.
You first need to have constructed and compiled the neural network. Example:
Construct a Feedforward Neural Network: Python, TensorFlow Keras - algoteka.com
# ...
# Construct your model
# The optimizer and loss function are defined in the compile method of the model
some_model.compile(
optimizer=keras.optimizers.RMSprop(learning_rate=1e-3),
loss=keras.losses.CategoricalCrossentropy(),
metrics=["acc"]
)
def train_model(model, x_train, y_train):
# model - An object of type keras.Model corresponding to our neural network
# x_train - A numpy array of our training data inputs
# y_train - A numpy array of our training data labels
model.fit(x_train, y_train, batch_size=64, epochs=2, validation_split=0.2)
Once the neural network has been built, the following sample shows how you can make predictions with it:
Predict with a Neural Network - algoteka.com
You can read up on the theory from the following links:
Neural Networks: Lecture 5: Back-propagation slides - courses.cs.ut.ee
Neural Networks: Lecture 5: Back-propagation video - courses.cs.ut.ee
Neural Networks: Lecture 6: Optimization & regularization slides - courses.cs.ut.ee
Neural Networks: Lecture 6: Optimization & regularization video - courses.cs.ut.ee
functions | |
tensorflow.keras.Model.compile |
tensorflow.org |
tensorflow.keras.Model.fit |
tensorflow.org |
Train some neural network on some given data. Samples should strive for simplicity.