Home > database >  Have trouble with verification result in Jupyter when run Python
Have trouble with verification result in Jupyter when run Python

Time:07-21

Ι have problem when type :

    import tensorflow as tf
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
model = tf.keras.models.Sequential([
 tf.keras.layers.Flatten(input_shape=(28, 28)),
 tf.keras.layers.Dense(128, activation='relu'),
 tf.keras.layers.Dropout(0.2),
 tf.keras.layers.Dense(10, activation='softmax')])
model.compile(optimizer='adam',
 loss='sparse_categorical_crossentropy',
 metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test)

The result should be like this : Using Google Collab

But when I try using Jupyter notebook the result become like this: Jupyter ss1 Jupyter ss2jupyter 3jupyter4

CodePudding user response:

If I'm interpreting this correctly, you want to produce the exact loss and accuracy of the other model shown. Just FYI, this doesn't mean there is a problem with your model (evidently by your loss and accuracy values it is working rather well); no two models are likely to yield the same results, due to the optimising process of generating random weights and optimising them over a given number of iterations using your desired method.

As a previous answer has said, you can set a seed to reproduce the same results every time, using tf.random.set_seed(<your_seed>). However, the original model you have included does not not include this line, so you won't be able to reproduce those exactly.

  • Related