I am trying to replicate the results of my model. But each time i run it, the results are different (even with restarting the google colab's runtime). Here's the model
# set random seed
tf.random.set_seed(42)
# 1. Create the model
model_1 = tf.keras.models.Sequential([
tf.keras.layers.Dense(1, input_shape=[1])
])
# 2. Compile the model
model_1.compile(loss=tf.keras.losses.mae,
optimizer=tf.keras.optimizers.SGD(),
metrics=["mae"])
# 3. Fit the model
model_1.fit(X_train, y_train, epochs=100)
X_train
and y_train
are two tensors each with shape=(40,)
, and dtype=int32
# 4. make a prediction
y_pred = model.predict(X_test)
# 5. mean absolute error
mae = tf.metrics.mean_absolute_error(y_true=y_test,
y_pred=tf.squeeze(tf.constant(y_pred)))
X_test
and y_test
are two tensors each with shape=(10,)
, and dtype=int32
Now every time i run the above code i get a different value for mae
, for example:
8.63, 21.26, 14.96, 14.93, 14,84, ...
I had expected to get identical runs, because i set the random seed before building and training the model.
How can i exactly reproduce my model's performance?