How to use weights from a specific epoc in Keras? - python

I am running 50 epocs for a Neural Network using Keras.
Here's my verbose response to it.
You can see that Epoc 47 (loss: 0.0065 - acc: 0.9980) has a much higher Accuracy and lesser cost that the last epoc and thus more suitable.
I am new to Keras, and would like to know if it is possible to use the instance of the model model in a particular epoc (in this case, epoc 47) instead of the final one?
EDIT: I do not want to run the training again with epoc = 47, that seems like a waste of time and resource.
Epoch 1/50
- 32s - loss: 0.4603 - acc: 0.8541
Epoch 2/50
- 31s - loss: 0.1140 - acc: 0.9655
Epoch 3/50
- 31s - loss: 0.0805 - acc: 0.9754
Epoch 4/50
- 38s - loss: 0.0663 - acc: 0.9792
Epoch 5/50
- 47s - loss: 0.0551 - acc: 0.9829
Epoch 6/50
- 39s - loss: 0.0487 - acc: 0.9846
Epoch 7/50
- 38s - loss: 0.0454 - acc: 0.9853
Epoch 8/50
- 37s - loss: 0.0399 - acc: 0.9873
Epoch 9/50
- 42s - loss: 0.0376 - acc: 0.9881
Epoch 10/50
- 42s - loss: 0.0332 - acc: 0.9896
Epoch 11/50
- 41s - loss: 0.0333 - acc: 0.9893
Epoch 12/50
- 39s - loss: 0.0286 - acc: 0.9911
Epoch 13/50
- 36s - loss: 0.0281 - acc: 0.9905
Epoch 14/50
- 35s - loss: 0.0258 - acc: 0.9918
Epoch 15/50
- 37s - loss: 0.0250 - acc: 0.9915
Epoch 16/50
- 35s - loss: 0.0236 - acc: 0.9920
Epoch 17/50
- 41s - loss: 0.0212 - acc: 0.9932
Epoch 18/50
- 33s - loss: 0.0219 - acc: 0.9928
Epoch 19/50
- 36s - loss: 0.0198 - acc: 0.9935
Epoch 20/50
- 37s - loss: 0.0172 - acc: 0.9941
Epoch 21/50
- 35s - loss: 0.0187 - acc: 0.9938
Epoch 22/50
- 38s - loss: 0.0182 - acc: 0.9939
Epoch 23/50
- 33s - loss: 0.0163 - acc: 0.9945
Epoch 24/50
- 35s - loss: 0.0148 - acc: 0.9949
Epoch 25/50
- 33s - loss: 0.0148 - acc: 0.9951
Epoch 26/50
- 37s - loss: 0.0143 - acc: 0.9951
Epoch 27/50
- 36s - loss: 0.0143 - acc: 0.9949
Epoch 28/50
- 34s - loss: 0.0129 - acc: 0.9958
Epoch 29/50
- 36s - loss: 0.0112 - acc: 0.9962
Epoch 30/50
- 34s - loss: 0.0112 - acc: 0.9961
Epoch 31/50
- 34s - loss: 0.0144 - acc: 0.9954
Epoch 32/50
- 40s - loss: 0.0132 - acc: 0.9952
Epoch 33/50
- 40s - loss: 0.0107 - acc: 0.9964
Epoch 34/50
- 43s - loss: 0.0118 - acc: 0.9958
Epoch 35/50
- 36s - loss: 0.0113 - acc: 0.9961
Epoch 36/50
- 34s - loss: 0.0101 - acc: 0.9963
Epoch 37/50
- 37s - loss: 0.0102 - acc: 0.9966
Epoch 38/50
- 37s - loss: 0.0098 - acc: 0.9965
Epoch 39/50
- 35s - loss: 0.0097 - acc: 0.9966
Epoch 40/50
- 35s - loss: 0.0102 - acc: 0.9963
Epoch 41/50
- 34s - loss: 0.0081 - acc: 0.9972
Epoch 42/50
- 36s - loss: 0.0075 - acc: 0.9976
Epoch 43/50
- 32s - loss: 0.0075 - acc: 0.9975
Epoch 44/50
- 32s - loss: 0.0088 - acc: 0.9971
Epoch 45/50
- 31s - loss: 0.0107 - acc: 0.9968
Epoch 46/50
- 32s - loss: 0.0089 - acc: 0.9970
Epoch 47/50
- 33s - loss: 0.0065 - acc: 0.9980
Epoch 48/50
- 30s - loss: 0.0076 - acc: 0.9975
Epoch 49/50
- 30s - loss: 0.0073 - acc: 0.9978
Epoch 50/50
- 30s - loss: 0.0090 - acc: 0.9971

Related

Keras model accuracy is not increasing after fine tunning

I am trying to fine-tune a pre-trained keras model. When I train my model with base_model.trainable = False freezing base model, the model somehow performs good as this is noise labeled-data.
Training
base_model = tf.keras.applications.xception.Xception(
weights='imagenet', # Load weights pre-trained on ImageNet.
input_shape=(71, 71, 3),
include_top=False)
inputs = keras.Input(shape=(71, 71, 3))
# We make sure that the base_model is running in inference mode here,
# by passing `training=False`. This is important for fine-tuning, as you will
# learn in a few paragraphs.
x = base_model(inputs, training=False)
# Convert features of shape `base_model.output_shape[1:]` to vectors
x = keras.layers.GlobalAveragePooling2D()(x)
# A Dense classifier with a single unit (binary classification)
outputs = keras.layers.Dense(100, activation='softmax')(x)
model = keras.Model(inputs, outputs)
opt = 'adam'
from keras import optimizers
# All parameter gradients will be clipped to
# a maximum value of 0.5 and
# a minimum value of -0.5.
sgd = optimizers.SGD(learning_rate=0.1)
model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
EPOCHS=80
batch_size=50
history = model.fit(train_generator,
epochs=EPOCHS,
validation_data=test_generator
)
Epoch 1/80
254/254 [==============================] - 2003s 8s/step - loss: 5.0831 - accuracy: 0.1382 - val_loss: 4.9958 - val_accuracy: 0.1553
Epoch 2/80
254/254 [==============================] - 37s 147ms/step - loss: 4.0021 - accuracy: 0.2209 - val_loss: 4.3061 - val_accuracy: 0.1823
Epoch 3/80
254/254 [==============================] - 38s 151ms/step - loss: 3.6878 - accuracy: 0.2658 - val_loss: 4.0236 - val_accuracy: 0.2136
Epoch 4/80
254/254 [==============================] - 37s 146ms/step - loss: 3.4906 - accuracy: 0.2802 - val_loss: 4.0162 - val_accuracy: 0.2311
Epoch 5/80
254/254 [==============================] - 38s 148ms/step - loss: 3.4181 - accuracy: 0.2992 - val_loss: 3.9218 - val_accuracy: 0.2576
Epoch 6/80
254/254 [==============================] - 37s 147ms/step - loss: 3.2562 - accuracy: 0.3239 - val_loss: 4.9404 - val_accuracy: 0.2067
Epoch 7/80
254/254 [==============================] - 38s 149ms/step - loss: 3.1829 - accuracy: 0.3265 - val_loss: 4.0481 - val_accuracy: 0.2379
Epoch 8/80
254/254 [==============================] - 38s 148ms/step - loss: 3.1376 - accuracy: 0.3377 - val_loss: 4.1134 - val_accuracy: 0.2533
Epoch 9/80
254/254 [==============================] - 38s 151ms/step - loss: 3.1106 - accuracy: 0.3471 - val_loss: 3.9105 - val_accuracy: 0.2576
Epoch 10/80
254/254 [==============================] - 37s 147ms/step - loss: 3.0804 - accuracy: 0.3493 - val_loss: 3.9946 - val_accuracy: 0.2485
Epoch 11/80
254/254 [==============================] - 38s 150ms/step - loss: 2.9805 - accuracy: 0.3646 - val_loss: 4.0945 - val_accuracy: 0.2533
Epoch 12/80
254/254 [==============================] - 37s 147ms/step - loss: 2.9449 - accuracy: 0.3678 - val_loss: 3.8677 - val_accuracy: 0.2666
Epoch 13/80
254/254 [==============================] - 37s 147ms/step - loss: 2.8806 - accuracy: 0.3805 - val_loss: 4.0724 - val_accuracy: 0.2565
Epoch 14/80
254/254 [==============================] - 38s 148ms/step - loss: 2.8634 - accuracy: 0.3815 - val_loss: 4.2235 - val_accuracy: 0.2401
Epoch 15/80
254/254 [==============================] - 38s 149ms/step - loss: 2.8797 - accuracy: 0.3844 - val_loss: 4.2314 - val_accuracy: 0.2496
Epoch 16/80
254/254 [==============================] - 39s 152ms/step - loss: 2.7690 - accuracy: 0.3918 - val_loss: 3.9585 - val_accuracy: 0.2538
Epoch 17/80
254/254 [==============================] - 38s 148ms/step - loss: 2.7139 - accuracy: 0.4044 - val_loss: 4.0631 - val_accuracy: 0.2655
Epoch 18/80
254/254 [==============================] - 38s 149ms/step - loss: 2.7524 - accuracy: 0.4007 - val_loss: 4.1265 - val_accuracy: 0.2507
Epoch 19/80
254/254 [==============================] - 38s 150ms/step - loss: 2.7846 - accuracy: 0.4060 - val_loss: 4.1827 - val_accuracy: 0.2745
Epoch 20/80
254/254 [==============================] - 38s 148ms/step - loss: 2.6704 - accuracy: 0.4096 - val_loss: 4.1165 - val_accuracy: 0.2724
Epoch 21/80
254/254 [==============================] - 38s 148ms/step - loss: 2.6919 - accuracy: 0.4085 - val_loss: 4.0298 - val_accuracy: 0.2724
Epoch 22/80
254/254 [==============================] - 39s 152ms/step - loss: 2.6464 - accuracy: 0.4281 - val_loss: 4.2831 - val_accuracy: 0.2560
Epoch 23/80
254/254 [==============================] - 38s 148ms/step - loss: 2.6559 - accuracy: 0.4106 - val_loss: 4.1969 - val_accuracy: 0.2708
Epoch 24/80
254/254 [==============================] - 38s 148ms/step - loss: 2.6277 - accuracy: 0.4183 - val_loss: 4.0792 - val_accuracy: 0.2655
Epoch 25/80
254/254 [==============================] - 37s 147ms/step - loss: 2.6172 - accuracy: 0.4198 - val_loss: 4.2355 - val_accuracy: 0.2470
Epoch 26/80
254/254 [==============================] - 37s 146ms/step - loss: 2.5797 - accuracy: 0.4262 - val_loss: 4.1912 - val_accuracy: 0.2729
Epoch 27/80
254/254 [==============================] - 38s 148ms/step - loss: 2.6099 - accuracy: 0.4245 - val_loss: 4.1026 - val_accuracy: 0.2655
Epoch 28/80
254/254 [==============================] - 38s 151ms/step - loss: 2.6076 - accuracy: 0.4295 - val_loss: 4.0800 - val_accuracy: 0.2766
Epoch 29/80
254/254 [==============================] - 37s 147ms/step - loss: 2.5052 - accuracy: 0.4472 - val_loss: 4.2279 - val_accuracy: 0.2719
Epoch 30/80
254/254 [==============================] - 37s 147ms/step - loss: 2.5740 - accuracy: 0.4274 - val_loss: 4.3939 - val_accuracy: 0.2501
Epoch 31/80
254/254 [==============================] - 37s 147ms/step - loss: 2.5229 - accuracy: 0.4436 - val_loss: 4.2375 - val_accuracy: 0.2491
Epoch 32/80
254/254 [==============================] - 38s 148ms/step - loss: 2.5219 - accuracy: 0.4474 - val_loss: 4.2442 - val_accuracy: 0.2618
Epoch 33/80
254/254 [==============================] - 37s 147ms/step - loss: 2.4840 - accuracy: 0.4426 - val_loss: 4.4318 - val_accuracy: 0.2565
Epoch 34/80
254/254 [==============================] - 38s 149ms/step - loss: 2.5860 - accuracy: 0.4371 - val_loss: 4.3327 - val_accuracy: 0.2528
Epoch 35/80
254/254 [==============================] - 38s 148ms/step - loss: 2.4185 - accuracy: 0.4572 - val_loss: 4.1556 - val_accuracy: 0.2560
Epoch 36/80
254/254 [==============================] - 37s 147ms/step - loss: 2.4237 - accuracy: 0.4537 - val_loss: 4.0573 - val_accuracy: 0.2750
Epoch 37/80
254/254 [==============================] - 37s 146ms/step - loss: 2.4385 - accuracy: 0.4570 - val_loss: 4.2088 - val_accuracy: 0.2798
Epoch 38/80
254/254 [==============================] - 37s 147ms/step - loss: 2.4071 - accuracy: 0.4554 - val_loss: 4.2039 - val_accuracy: 0.2650
Epoch 39/80
254/254 [==============================] - 37s 146ms/step - loss: 2.4262 - accuracy: 0.4514 - val_loss: 4.3580 - val_accuracy: 0.2560
Epoch 40/80
254/254 [==============================] - 38s 148ms/step - loss: 2.4693 - accuracy: 0.4482 - val_loss: 4.2222 - val_accuracy: 0.2618
Epoch 41/80
254/254 [==============================] - 38s 150ms/step - loss: 2.4200 - accuracy: 0.4620 - val_loss: 4.2950 - val_accuracy: 0.2697
Epoch 42/80
254/254 [==============================] - 37s 146ms/step - loss: 2.4143 - accuracy: 0.4542 - val_loss: 4.4336 - val_accuracy: 0.2523
Epoch 43/80
254/254 [==============================] - 37s 147ms/step - loss: 2.4139 - accuracy: 0.4581 - val_loss: 4.1720 - val_accuracy: 0.2666
Epoch 44/80
254/254 [==============================] - 37s 147ms/step - loss: 2.3540 - accuracy: 0.4667 - val_loss: 4.2369 - val_accuracy: 0.2623
Epoch 45/80
254/254 [==============================] - 37s 147ms/step - loss: 2.3607 - accuracy: 0.4626 - val_loss: 4.1551 - val_accuracy: 0.2692
Epoch 46/80
254/254 [==============================] - 38s 148ms/step - loss: 2.3779 - accuracy: 0.4685 - val_loss: 4.2584 - val_accuracy: 0.2782
Epoch 47/80
254/254 [==============================] - 38s 150ms/step - loss: 2.3444 - accuracy: 0.4715 - val_loss: 4.1775 - val_accuracy: 0.2687
Epoch 48/80
254/254 [==============================] - 38s 149ms/step - loss: 2.3507 - accuracy: 0.4691 - val_loss: 4.4818 - val_accuracy: 0.2528
Epoch 49/80
254/254 [==============================] - 38s 148ms/step - loss: 2.3147 - accuracy: 0.4776 - val_loss: 4.3711 - val_accuracy: 0.2634
Epoch 50/80
254/254 [==============================] - 37s 147ms/step - loss: 2.3591 - accuracy: 0.4774 - val_loss: 4.2408 - val_accuracy: 0.2825
Epoch 51/80
254/254 [==============================] - 38s 149ms/step - loss: 2.3612 - accuracy: 0.4685 - val_loss: 4.1840 - val_accuracy: 0.2660
Epoch 52/80
254/254 [==============================] - 37s 147ms/step - loss: 2.2596 - accuracy: 0.4903 - val_loss: 4.4588 - val_accuracy: 0.2496
Epoch 53/80
254/254 [==============================] - 38s 150ms/step - loss: 2.2877 - accuracy: 0.4819 - val_loss: 4.2483 - val_accuracy: 0.2761
Epoch 54/80
254/254 [==============================] - 38s 148ms/step - loss: 2.3550 - accuracy: 0.4749 - val_loss: 4.3342 - val_accuracy: 0.2544
Epoch 55/80
254/254 [==============================] - 37s 147ms/step - loss: 2.2746 - accuracy: 0.4871 - val_loss: 4.2665 - val_accuracy: 0.2666
Epoch 56/80
254/254 [==============================] - 37s 147ms/step - loss: 2.2539 - accuracy: 0.4859 - val_loss: 4.7657 - val_accuracy: 0.2528
Epoch 57/80
254/254 [==============================] - 37s 146ms/step - loss: 2.3627 - accuracy: 0.4696 - val_loss: 4.5694 - val_accuracy: 0.2644
Epoch 58/80
254/254 [==============================] - 37s 146ms/step - loss: 2.2716 - accuracy: 0.4909 - val_loss: 4.3457 - val_accuracy: 0.2893
Epoch 59/80
254/254 [==============================] - 38s 149ms/step - loss: 2.2598 - accuracy: 0.4865 - val_loss: 4.3855 - val_accuracy: 0.2756
Epoch 60/80
254/254 [==============================] - 39s 152ms/step - loss: 2.2611 - accuracy: 0.4879 - val_loss: 4.2370 - val_accuracy: 0.2708
Epoch 61/80
254/254 [==============================] - 37s 146ms/step - loss: 2.2647 - accuracy: 0.4879 - val_loss: 4.3294 - val_accuracy: 0.2835
Epoch 62/80
254/254 [==============================] - 38s 148ms/step - loss: 2.2475 - accuracy: 0.4923 - val_loss: 4.4982 - val_accuracy: 0.2729
Epoch 63/80
254/254 [==============================] - 37s 146ms/step - loss: 2.2618 - accuracy: 0.4955 - val_loss: 4.3598 - val_accuracy: 0.2761
Epoch 64/80
254/254 [==============================] - 38s 149ms/step - loss: 2.2395 - accuracy: 0.4909 - val_loss: 4.2726 - val_accuracy: 0.2787
Epoch 65/80
254/254 [==============================] - 38s 149ms/step - loss: 2.2310 - accuracy: 0.4997 - val_loss: 4.5172 - val_accuracy: 0.2655
Epoch 66/80
254/254 [==============================] - 37s 147ms/step - loss: 2.2370 - accuracy: 0.4919 - val_loss: 4.3850 - val_accuracy: 0.2666
Epoch 67/80
254/254 [==============================] - 38s 151ms/step - loss: 2.2082 - accuracy: 0.5052 - val_loss: 4.5286 - val_accuracy: 0.2512
Epoch 68/80
254/254 [==============================] - 37s 147ms/step - loss: 2.2468 - accuracy: 0.4960 - val_loss: 4.4056 - val_accuracy: 0.2713
Epoch 69/80
254/254 [==============================] - 37s 146ms/step - loss: 2.2392 - accuracy: 0.4970 - val_loss: 4.3692 - val_accuracy: 0.2787
Epoch 70/80
254/254 [==============================] - 37s 147ms/step - loss: 2.2119 - accuracy: 0.4986 - val_loss: 4.6359 - val_accuracy: 0.2660
Epoch 71/80
254/254 [==============================] - 37s 146ms/step - loss: 2.2090 - accuracy: 0.5030 - val_loss: 4.5131 - val_accuracy: 0.2613
Epoch 72/80
254/254 [==============================] - 37s 146ms/step - loss: 2.2116 - accuracy: 0.5022 - val_loss: 5.0494 - val_accuracy: 0.2464
Epoch 73/80
254/254 [==============================] - 38s 148ms/step - loss: 2.1588 - accuracy: 0.5055 - val_loss: 4.3195 - val_accuracy: 0.2666
Epoch 74/80
254/254 [==============================] - 38s 149ms/step - loss: 2.1788 - accuracy: 0.5075 - val_loss: 4.6717 - val_accuracy: 0.2565
Epoch 75/80
254/254 [==============================] - 37s 146ms/step - loss: 2.2094 - accuracy: 0.4992 - val_loss: 4.2996 - val_accuracy: 0.2809
Epoch 76/80
254/254 [==============================] - 37s 147ms/step - loss: 2.2178 - accuracy: 0.4927 - val_loss: 4.4637 - val_accuracy: 0.2756
Epoch 77/80
254/254 [==============================] - 37s 145ms/step - loss: 2.2052 - accuracy: 0.5008 - val_loss: 4.4615 - val_accuracy: 0.2793
Epoch 78/80
254/254 [==============================] - 37s 147ms/step - loss: 2.1602 - accuracy: 0.5068 - val_loss: 4.5584 - val_accuracy: 0.2639
Epoch 79/80
254/254 [==============================] - 37s 146ms/step - loss: 2.2296 - accuracy: 0.5039 - val_loss: 4.3287 - val_accuracy: 0.2825
Epoch 80/80
254/254 [==============================] - 37s 145ms/step - loss: 2.1774 - accuracy: 0.5104 - val_loss: 4.6832 - val_accuracy: 0.2793
However after training when I fine-tune the model base_model.trainable = True, the model performs very poor.
Even 2-3 days earlier I noted that the model was performing very good with base_model.trainable = True
base_model.trainable = True
opt = 'adam'
from keras import optimizers
# All parameter gradients will be clipped to
sgd = optimizers.SGD(learning_rate=0.1)
model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
EPOCHS=40
batch_size=50
history = model.fit(train_generator,
epochs=EPOCHS,
validation_data=test_generator
)
Epoch 1/40
254/254 [==============================] - 46s 162ms/step - loss: nan - accuracy: 0.0112 - val_loss: nan - val_accuracy: 0.0127
Epoch 2/40
254/254 [==============================] - 40s 156ms/step - loss: nan - accuracy: 0.0094 - val_loss: nan - val_accuracy: 0.0127
Epoch 3/40
254/254 [==============================] - 40s 157ms/step - loss: nan - accuracy: 0.0094 - val_loss: nan - val_accuracy: 0.0127
Epoch 4/40
254/254 [==============================] - 41s 160ms/step - loss: nan - accuracy: 0.0094 - val_loss: nan - val_accuracy: 0.0127
Epoch 5/40
254/254 [==============================] - 40s 157ms/step - loss: nan - accuracy: 0.0094 - val_loss: nan - val_accuracy: 0.0127
Epoch 6/40
254/254 [==============================] - 40s 159ms/step - loss: nan - accuracy: 0.0094 - val_loss: nan - val_accuracy: 0.0127
Epoch 7/40
254/254 [==============================] - 40s 157ms/step - loss: nan - accuracy: 0.0094 - val_loss: nan - val_accuracy: 0.0127
Epoch 8/40
254/254 [==============================] - 40s 156ms/step - loss: nan - accuracy: 0.0094 - val_loss: nan - val_accuracy: 0.0127
Epoch 9/40
254/254 [==============================] - 40s 158ms/step - loss: nan - accuracy: 0.0094 - val_loss: nan - val_accuracy: 0.0127
Epoch 10/40
254/254 [==============================] - 40s 156ms/step - loss: nan - accuracy: 0.0094 - val_loss: nan - val_accuracy: 0.0127
Epoch 11/40
254/254 [==============================] - 41s 161ms/step - loss: nan - accuracy: 0.0094 - val_loss: nan - val_accuracy: 0.0127
Epoch 12/40
254/254 [==============================] - 40s 157ms/step - loss: nan - accuracy: 0.0094 - val_loss: nan - val_accuracy: 0.0127
Epoch 13/40
254/254 [==============================] - 40s 157ms/step - loss: nan - accuracy: 0.0094 - val_loss: nan - val_accuracy: 0.0127
Epoch 14/40
254/254 [==============================] - 40s 158ms/step - loss: nan - accuracy: 0.0094 - val_loss: nan - val_accuracy: 0.0127
Epoch 15/40
254/254 [==============================] - 40s 158ms/step - loss: nan - accuracy: 0.0094 - val_loss: nan - val_accuracy: 0.0127
Epoch 16/40
254/254 [==============================] - 40s 157ms/step - loss: nan - accuracy: 0.0094 - val_loss: nan - val_accuracy: 0.0127
Epoch 17/40
254/254 [==============================] - 41s 160ms/step - loss: nan - accuracy: 0.0094 - val_loss: nan - val_accuracy: 0.0127
Epoch 18/40
254/254 [==============================] - 40s 158ms/step - loss: nan - accuracy: 0.0094 - val_loss: nan - val_accuracy: 0.0127
Epoch 19/40
254/254 [==============================] - 40s 158ms/step - loss: nan - accuracy: 0.0094 - val_loss: nan - val_accuracy: 0.0127

How do I update my model acc and val_acc?

I am currently working on a project to create a word prediction model. There are 800,000 datasets, but 0.5% is used separately as a prototype, and the training data size is as follows.
I want to know why loss and val_loss decrease during training, but acc and val_acc remain the same.
Train Data Set : 31471
my model's parameters
epochs=0
optimizer = tensorflow.keras.optimizers.SGD(lr=0.01)
loss_func = 'categorical_crossentropy'
hidden_1_neural = 128
hidden_2_neural = 64
hidden_1_dropout = 0.1
hidden_2_dropout = 0
activation = 'relu'
out_put_activation='softmax'
embedding_dim = 10
Training : optimizer=SGD
Epoch 1/100
1259/1259 [==============================] - 15s 12ms/step - loss: 8.6827 - accuracy: 0.1164 - val_loss: 8.3275 - val_accuracy: 0.1300
Epoch 2/100
1259/1259 [==============================] - 12s 10ms/step - loss: 8.3446 - accuracy: 0.1178 - val_loss: 8.1969 - val_accuracy: 0.1300
Epoch 3/100
1259/1259 [==============================] - 13s 10ms/step - loss: 8.2007 - accuracy: 0.1178 - val_loss: 8.0654 - val_accuracy: 0.1300
Epoch 4/100
1259/1259 [==============================] - 13s 10ms/step - loss: 8.0747 - accuracy: 0.1178 - val_loss: 7.9659 - val_accuracy: 0.1300
Epoch 5/100
1259/1259 [==============================] - 12s 10ms/step - loss: 7.9752 - accuracy: 0.1178 - val_loss: 7.8901 - val_accuracy: 0.1300
Epoch 6/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.8923 - accuracy: 0.1178 - val_loss: 7.8225 - val_accuracy: 0.1300
Epoch 7/100
1259/1259 [==============================] - 13s 11ms/step - loss: 7.8232 - accuracy: 0.1178 - val_loss: 7.7742 - val_accuracy: 0.1300
Epoch 8/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.7664 - accuracy: 0.1178 - val_loss: 7.7329 - val_accuracy: 0.1300
Epoch 9/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.7186 - accuracy: 0.1178 - val_loss: 7.7037 - val_accuracy: 0.1300
Epoch 10/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.6785 - accuracy: 0.1178 - val_loss: 7.6797 - val_accuracy: 0.1300
Epoch 11/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.6450 - accuracy: 0.1178 - val_loss: 7.6598 - val_accuracy: 0.1300
Epoch 12/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.6165 - accuracy: 0.1178 - val_loss: 7.6524 - val_accuracy: 0.1300
Epoch 13/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.5922 - accuracy: 0.1178 - val_loss: 7.6367 - val_accuracy: 0.1300
Epoch 14/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.5712 - accuracy: 0.1178 - val_loss: 7.6332 - val_accuracy: 0.1300
Epoch 15/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.5534 - accuracy: 0.1178 - val_loss: 7.6280 - val_accuracy: 0.1300
Epoch 16/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.5373 - accuracy: 0.1178 - val_loss: 7.6238 - val_accuracy: 0.1300
Epoch 17/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.5234 - accuracy: 0.1178 - val_loss: 7.6239 - val_accuracy: 0.1300
Epoch 18/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.5107 - accuracy: 0.1178 - val_loss: 7.6246 - val_accuracy: 0.1300
Epoch 19/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.4995 - accuracy: 0.1178 - val_loss: 7.6208 - val_accuracy: 0.1300
Epoch 20/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.4893 - accuracy: 0.1178 - val_loss: 7.6222 - val_accuracy: 0.1300
Epoch 21/100
1259/1259 [==============================] - 12s 10ms/step - loss: 7.4798 - accuracy: 0.1178 - val_loss: 7.6239 - val_accuracy: 0.1300
Epoch 22/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.4710 - accuracy: 0.1178 - val_loss: 7.6246 - val_accuracy: 0.1300
Epoch 23/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.4634 - accuracy: 0.1178 - val_loss: 7.6286 - val_accuracy: 0.1300
Epoch 24/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.4561 - accuracy: 0.1178 - val_loss: 7.6315 - val_accuracy: 0.1300
Epoch 25/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.4492 - accuracy: 0.1178 - val_loss: 7.6363 - val_accuracy: 0.1300
Epoch 26/100
1259/1259 [==============================] - 13s 11ms/step - loss: 7.4432 - accuracy: 0.1178 - val_loss: 7.6363 - val_accuracy: 0.1300
Epoch 27/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.4370 - accuracy: 0.1178 - val_loss: 7.6396 - val_accuracy: 0.1300
Epoch 28/100
1259/1259 [==============================] - 12s 10ms/step - loss: 7.4321 - accuracy: 0.1178 - val_loss: 7.6433 - val_accuracy: 0.1300
Epoch 29/100
1259/1259 [==============================] - 12s 10ms/step - loss: 7.4264 - accuracy: 0.1178 - val_loss: 7.6484 - val_accuracy: 0.1300
Epoch 30/100
1259/1259 [==============================] - 12s 10ms/step - loss: 7.4214 - accuracy: 0.1178 - val_loss: 7.6568 - val_accuracy: 0.1300
Epoch 31/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.4173 - accuracy: 0.1178 - val_loss: 7.6591 - val_accuracy: 0.1300
Epoch 32/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.4122 - accuracy: 0.1178 - val_loss: 7.6672 - val_accuracy: 0.1300
Epoch 33/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.4084 - accuracy: 0.1178 - val_loss: 7.6637 - val_accuracy: 0.1300
Epoch 34/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.4047 - accuracy: 0.1178 - val_loss: 7.6674 - val_accuracy: 0.1300
Epoch 35/100
1259/1259 [==============================] - 13s 11ms/step - loss: 7.4007 - accuracy: 0.1178 - val_loss: 7.6710 - val_accuracy: 0.1300
Epoch 36/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3977 - accuracy: 0.1178 - val_loss: 7.6747 - val_accuracy: 0.1300
Epoch 37/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.3936 - accuracy: 0.1178 - val_loss: 7.6788 - val_accuracy: 0.1300
Epoch 38/100
1259/1259 [==============================] - 13s 11ms/step - loss: 7.3905 - accuracy: 0.1178 - val_loss: 7.6854 - val_accuracy: 0.1300
Epoch 39/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3874 - accuracy: 0.1178 - val_loss: 7.6879 - val_accuracy: 0.1300
Epoch 40/100
1259/1259 [==============================] - 13s 11ms/step - loss: 7.3848 - accuracy: 0.1178 - val_loss: 7.6914 - val_accuracy: 0.1300
Epoch 41/100
1259/1259 [==============================] - 13s 11ms/step - loss: 7.3819 - accuracy: 0.1178 - val_loss: 7.6973 - val_accuracy: 0.1300
Epoch 42/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.3787 - accuracy: 0.1178 - val_loss: 7.6993 - val_accuracy: 0.1300
Epoch 43/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.3762 - accuracy: 0.1178 - val_loss: 7.7056 - val_accuracy: 0.1300
Epoch 44/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3737 - accuracy: 0.1178 - val_loss: 7.7069 - val_accuracy: 0.1300
Epoch 45/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3711 - accuracy: 0.1178 - val_loss: 7.7115 - val_accuracy: 0.1300
Epoch 46/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3683 - accuracy: 0.1178 - val_loss: 7.7161 - val_accuracy: 0.1300
Epoch 47/100
1259/1259 [==============================] - 13s 11ms/step - loss: 7.3662 - accuracy: 0.1178 - val_loss: 7.7211 - val_accuracy: 0.1300
Epoch 48/100
1259/1259 [==============================] - 12s 10ms/step - loss: 7.3643 - accuracy: 0.1178 - val_loss: 7.7230 - val_accuracy: 0.1300
Epoch 49/100
1259/1259 [==============================] - 12s 10ms/step - loss: 7.3619 - accuracy: 0.1178 - val_loss: 7.7278 - val_accuracy: 0.1300
Epoch 50/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.3597 - accuracy: 0.1178 - val_loss: 7.7334 - val_accuracy: 0.1300
Epoch 51/100
1259/1259 [==============================] - 13s 11ms/step - loss: 7.3579 - accuracy: 0.1178 - val_loss: 7.7357 - val_accuracy: 0.1300
Epoch 52/100
1259/1259 [==============================] - 13s 11ms/step - loss: 7.3560 - accuracy: 0.1178 - val_loss: 7.7445 - val_accuracy: 0.1300
Epoch 53/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3541 - accuracy: 0.1178 - val_loss: 7.7450 - val_accuracy: 0.1300
Epoch 54/100
1259/1259 [==============================] - 13s 11ms/step - loss: 7.3518 - accuracy: 0.1178 - val_loss: 7.7577 - val_accuracy: 0.1300
Epoch 55/100
1259/1259 [==============================] - 13s 11ms/step - loss: 7.3504 - accuracy: 0.1178 - val_loss: 7.7527 - val_accuracy: 0.1300
Epoch 56/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3485 - accuracy: 0.1178 - val_loss: 7.7569 - val_accuracy: 0.1300
Epoch 57/100
1259/1259 [==============================] - 13s 11ms/step - loss: 7.3472 - accuracy: 0.1178 - val_loss: 7.7567 - val_accuracy: 0.1300
Epoch 58/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3462 - accuracy: 0.1178 - val_loss: 7.7610 - val_accuracy: 0.1300
Epoch 59/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3444 - accuracy: 0.1178 - val_loss: 7.7650 - val_accuracy: 0.1300
Epoch 60/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3426 - accuracy: 0.1178 - val_loss: 7.7676 - val_accuracy: 0.1300
Epoch 61/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3406 - accuracy: 0.1178 - val_loss: 7.7711 - val_accuracy: 0.1300
Epoch 62/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3398 - accuracy: 0.1178 - val_loss: 7.7753 - val_accuracy: 0.1300
Epoch 63/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3381 - accuracy: 0.1178 - val_loss: 7.7841 - val_accuracy: 0.1300
Epoch 64/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3375 - accuracy: 0.1178 - val_loss: 7.7857 - val_accuracy: 0.1300
Epoch 65/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3359 - accuracy: 0.1178 - val_loss: 7.7862 - val_accuracy: 0.1300
Epoch 66/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3345 - accuracy: 0.1178 - val_loss: 7.7889 - val_accuracy: 0.1300
Epoch 67/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3336 - accuracy: 0.1178 - val_loss: 7.7951 - val_accuracy: 0.1300
Epoch 68/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3321 - accuracy: 0.1178 - val_loss: 7.7976 - val_accuracy: 0.1300
Epoch 69/100
1259/1259 [==============================] - 13s 11ms/step - loss: 7.3309 - accuracy: 0.1178 - val_loss: 7.7996 - val_accuracy: 0.1300
Epoch 70/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.3297 - accuracy: 0.1178 - val_loss: 7.8092 - val_accuracy: 0.1300
Epoch 71/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.3286 - accuracy: 0.1178 - val_loss: 7.8060 - val_accuracy: 0.1300
Epoch 72/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.3279 - accuracy: 0.1178 - val_loss: 7.8098 - val_accuracy: 0.1300
Epoch 73/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.3261 - accuracy: 0.1178 - val_loss: 7.8125 - val_accuracy: 0.1300
Epoch 74/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.3249 - accuracy: 0.1178 - val_loss: 7.8165 - val_accuracy: 0.1300
Epoch 75/100
1259/1259 [==============================] - 15s 12ms/step - loss: 7.3244 - accuracy: 0.1178 - val_loss: 7.8197 - val_accuracy: 0.1300
Epoch 76/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.3239 - accuracy: 0.1178 - val_loss: 7.8224 - val_accuracy: 0.1300
Epoch 77/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.3226 - accuracy: 0.1178 - val_loss: 7.8259 - val_accuracy: 0.1300
Epoch 78/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.3217 - accuracy: 0.1178 - val_loss: 7.8311 - val_accuracy: 0.1300
Epoch 79/100
1259/1259 [==============================] - 13s 11ms/step - loss: 7.3206 - accuracy: 0.1178 - val_loss: 7.8353 - val_accuracy: 0.1300
Epoch 80/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.3197 - accuracy: 0.1178 - val_loss: 7.8423 - val_accuracy: 0.1300
Epoch 81/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.3193 - accuracy: 0.1178 - val_loss: 7.8391 - val_accuracy: 0.1300
Epoch 82/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.3180 - accuracy: 0.1178 - val_loss: 7.8399 - val_accuracy: 0.1300
Epoch 83/100
1259/1259 [==============================] - 13s 11ms/step - loss: 7.3172 - accuracy: 0.1178 - val_loss: 7.8495 - val_accuracy: 0.1300
Epoch 84/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3165 - accuracy: 0.1178 - val_loss: 7.8492 - val_accuracy: 0.1300
Epoch 85/100
1259/1259 [==============================] - 13s 11ms/step - loss: 7.3151 - accuracy: 0.1178 - val_loss: 7.8505 - val_accuracy: 0.1300
Epoch 86/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.3150 - accuracy: 0.1178 - val_loss: 7.8527 - val_accuracy: 0.1300
Epoch 87/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.3143 - accuracy: 0.1178 - val_loss: 7.8555 - val_accuracy: 0.1300
Epoch 88/100
1259/1259 [==============================] - 16s 13ms/step - loss: 7.3132 - accuracy: 0.1178 - val_loss: 7.8578 - val_accuracy: 0.1300
Epoch 89/100
1259/1259 [==============================] - 15s 12ms/step - loss: 7.3128 - accuracy: 0.1178 - val_loss: 7.8605 - val_accuracy: 0.1300
Epoch 90/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3125 - accuracy: 0.1178 - val_loss: 7.8639 - val_accuracy: 0.1300
Epoch 91/100
1259/1259 [==============================] - 12s 10ms/step - loss: 7.3114 - accuracy: 0.1178 - val_loss: 7.8733 - val_accuracy: 0.1300
Epoch 92/100
1259/1259 [==============================] - 12s 10ms/step - loss: 7.3108 - accuracy: 0.1178 - val_loss: 7.8717 - val_accuracy: 0.1300
Epoch 93/100
1259/1259 [==============================] - 12s 10ms/step - loss: 7.3097 - accuracy: 0.1178 - val_loss: 7.8742 - val_accuracy: 0.1300
Epoch 94/100
1259/1259 [==============================] - 12s 10ms/step - loss: 7.3095 - accuracy: 0.1178 - val_loss: 7.8750 - val_accuracy: 0.1300
Epoch 95/100
1259/1259 [==============================] - 12s 10ms/step - loss: 7.3086 - accuracy: 0.1178 - val_loss: 7.8805 - val_accuracy: 0.1300
Epoch 96/100
1259/1259 [==============================] - 12s 10ms/step - loss: 7.3083 - accuracy: 0.1178 - val_loss: 7.8804 - val_accuracy: 0.1300
Epoch 97/100
1259/1259 [==============================] - 12s 10ms/step - loss: 7.3077 - accuracy: 0.1178 - val_loss: 7.8858 - val_accuracy: 0.1300
Epoch 98/100
1259/1259 [==============================] - 14s 11ms/step - loss: 7.3070 - accuracy: 0.1178 - val_loss: 7.8868 - val_accuracy: 0.1300
Epoch 99/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3062 - accuracy: 0.1178 - val_loss: 7.8913 - val_accuracy: 0.1300
Epoch 100/100
1259/1259 [==============================] - 13s 10ms/step - loss: 7.3059 - accuracy: 0.1178 - val_loss: 7.8924 - val_accuracy: 0.1300
If I use adam as the optimizer, loss decreases and acc increases, but val_loss and val_acc increase.
#1 add context
model summary :
Model: "functional_23"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_12 (InputLayer) [(None, 2)] 0
_________________________________________________________________
embedding_11 (Embedding) (None, 2, 10) 104270
_________________________________________________________________
lstm_22 (LSTM) (None, 2, 128) 71168
_________________________________________________________________
lstm_23 (LSTM) (None, 64) 49408
_________________________________________________________________
dense_11 (Dense) (None, 10427) 677755
=================================================================
Total params: 902,601
Trainable params: 902,601
Non-trainable params: 0
_________________________________________________________________
training : optimizer = Adam
Epoch 1/100
1259/1259 [==============================] - 11s 9ms/step - loss: 8.0481 - accuracy: 0.1177 - val_loss: 7.6862 - val_accuracy: 0.1300
Epoch 2/100
1259/1259 [==============================] - 10s 8ms/step - loss: 7.2587 - accuracy: 0.1178 - val_loss: 8.0457 - val_accuracy: 0.1300
Epoch 3/100
1259/1259 [==============================] - 12s 9ms/step - loss: 7.0693 - accuracy: 0.1178 - val_loss: 8.3413 - val_accuracy: 0.1300
Epoch 4/100
1259/1259 [==============================] - 10s 8ms/step - loss: 6.9767 - accuracy: 0.1178 - val_loss: 8.4930 - val_accuracy: 0.1300
Epoch 5/100
1259/1259 [==============================] - 10s 8ms/step - loss: 6.8866 - accuracy: 0.1178 - val_loss: 9.0810 - val_accuracy: 0.1300
Epoch 6/100
1259/1259 [==============================] - 10s 8ms/step - loss: 6.7718 - accuracy: 0.1178 - val_loss: 9.5166 - val_accuracy: 0.1303
Epoch 7/100
1259/1259 [==============================] - 12s 9ms/step - loss: 6.6101 - accuracy: 0.1204 - val_loss: 10.2690 - val_accuracy: 0.1385
Epoch 8/100
1259/1259 [==============================] - 11s 9ms/step - loss: 6.4294 - accuracy: 0.1291 - val_loss: 10.5882 - val_accuracy: 0.1405
Epoch 9/100
1259/1259 [==============================] - 11s 9ms/step - loss: 6.2603 - accuracy: 0.1316 - val_loss: 10.7328 - val_accuracy: 0.1395
Epoch 10/100
1259/1259 [==============================] - 12s 9ms/step - loss: 6.1231 - accuracy: 0.1351 - val_loss: 11.0442 - val_accuracy: 0.1405
Epoch 11/100
1259/1259 [==============================] - 11s 9ms/step - loss: 6.0100 - accuracy: 0.1366 - val_loss: 11.2861 - val_accuracy: 0.1401
Epoch 12/100
1259/1259 [==============================] - 11s 9ms/step - loss: 5.8962 - accuracy: 0.1378 - val_loss: 11.4858 - val_accuracy: 0.1366
Epoch 13/100
1259/1259 [==============================] - 12s 9ms/step - loss: 5.7899 - accuracy: 0.1389 - val_loss: 11.5724 - val_accuracy: 0.1379
Epoch 14/100
1259/1259 [==============================] - 11s 9ms/step - loss: 5.6857 - accuracy: 0.1397 - val_loss: 12.1945 - val_accuracy: 0.1392
Epoch 15/100
1259/1259 [==============================] - 12s 9ms/step - loss: 5.5770 - accuracy: 0.1416 - val_loss: 12.4677 - val_accuracy: 0.1389
Epoch 16/100
1259/1259 [==============================] - 11s 9ms/step - loss: 5.4650 - accuracy: 0.1436 - val_loss: 13.1879 - val_accuracy: 0.1398
Epoch 17/100
1259/1259 [==============================] - 12s 10ms/step - loss: 5.3608 - accuracy: 0.1448 - val_loss: 13.3614 - val_accuracy: 0.1392
Epoch 18/100
1259/1259 [==============================] - 11s 9ms/step - loss: 5.2428 - accuracy: 0.1468 - val_loss: 13.8756 - val_accuracy: 0.1373
Epoch 19/100
1259/1259 [==============================] - 11s 9ms/step - loss: 5.1173 - accuracy: 0.1506 - val_loss: 14.5616 - val_accuracy: 0.1344
Epoch 20/100
1259/1259 [==============================] - 10s 8ms/step - loss: 4.9850 - accuracy: 0.1519 - val_loss: 15.1821 - val_accuracy: 0.1322
Epoch 21/100
1259/1259 [==============================] - 11s 9ms/step - loss: 4.8699 - accuracy: 0.1563 - val_loss: 15.8595 - val_accuracy: 0.1246
Epoch 22/100
1259/1259 [==============================] - 10s 8ms/step - loss: 4.7625 - accuracy: 0.1609 - val_loss: 16.9606 - val_accuracy: 0.1274
Epoch 23/100
1259/1259 [==============================] - 11s 9ms/step - loss: 4.6529 - accuracy: 0.1648 - val_loss: 17.2735 - val_accuracy: 0.1255
Epoch 24/100
1259/1259 [==============================] - 11s 8ms/step - loss: 4.5586 - accuracy: 0.1665 - val_loss: 17.6336 - val_accuracy: 0.1268
Epoch 25/100
1259/1259 [==============================] - 11s 8ms/step - loss: 4.4696 - accuracy: 0.1719 - val_loss: 18.8503 - val_accuracy: 0.1239
Epoch 26/100
1259/1259 [==============================] - 11s 9ms/step - loss: 4.3908 - accuracy: 0.1768 - val_loss: 18.8996 - val_accuracy: 0.1271
Epoch 27/100
1259/1259 [==============================] - 15s 12ms/step - loss: 4.3114 - accuracy: 0.1809 - val_loss: 20.1614 - val_accuracy: 0.1271
Epoch 28/100
1259/1259 [==============================] - 11s 9ms/step - loss: 4.2313 - accuracy: 0.1856 - val_loss: 19.8104 - val_accuracy: 0.1239
Epoch 29/100
1259/1259 [==============================] - 15s 12ms/step - loss: 4.1639 - accuracy: 0.1898 - val_loss: 21.2305 - val_accuracy: 0.1268
Epoch 30/100
1259/1259 [==============================] - 11s 9ms/step - loss: 4.0977 - accuracy: 0.1964 - val_loss: 22.0776 - val_accuracy: 0.1290
Epoch 31/100
1259/1259 [==============================] - 12s 9ms/step - loss: 4.0339 - accuracy: 0.2020 - val_loss: 22.2132 - val_accuracy: 0.1284
Epoch 32/100
1259/1259 [==============================] - 11s 9ms/step - loss: 3.9690 - accuracy: 0.2041 - val_loss: 22.7188 - val_accuracy: 0.1303
Epoch 33/100
1259/1259 [==============================] - 11s 9ms/step - loss: 3.9047 - accuracy: 0.2060 - val_loss: 23.6534 - val_accuracy: 0.1277
Epoch 34/100
1259/1259 [==============================] - 12s 10ms/step - loss: 3.8326 - accuracy: 0.2119 - val_loss: 24.6426 - val_accuracy: 0.1255
Epoch 35/100
1259/1259 [==============================] - 11s 9ms/step - loss: 3.7886 - accuracy: 0.2203 - val_loss: 23.4429 - val_accuracy: 0.1214
Epoch 36/100
1259/1259 [==============================] - 11s 9ms/step - loss: 3.7441 - accuracy: 0.2277 - val_loss: 23.9890 - val_accuracy: 0.1246
Epoch 37/100
1259/1259 [==============================] - 11s 9ms/step - loss: 3.6865 - accuracy: 0.2305 - val_loss: 25.8336 - val_accuracy: 0.1262
Epoch 38/100
1259/1259 [==============================] - 11s 9ms/step - loss: 3.6346 - accuracy: 0.2368 - val_loss: 26.5063 - val_accuracy: 0.1195
Epoch 39/100
1259/1259 [==============================] - 11s 9ms/step - loss: 3.5873 - accuracy: 0.2434 - val_loss: 26.5917 - val_accuracy: 0.1249
Epoch 40/100
1259/1259 [==============================] - 11s 9ms/step - loss: 3.5522 - accuracy: 0.2452 - val_loss: 26.5287 - val_accuracy: 0.1214
Epoch 41/100
1259/1259 [==============================] - 11s 9ms/step - loss: 3.4908 - accuracy: 0.2509 - val_loss: 27.0090 - val_accuracy: 0.1255
Epoch 42/100
1259/1259 [==============================] - 11s 9ms/step - loss: 3.4511 - accuracy: 0.2560 - val_loss: 27.7853 - val_accuracy: 0.1201
Epoch 43/100
1259/1259 [==============================] - 11s 9ms/step - loss: 3.4017 - accuracy: 0.2629 - val_loss: 27.8698 - val_accuracy: 0.1169
Epoch 44/100
1259/1259 [==============================] - 11s 9ms/step - loss: 3.3732 - accuracy: 0.2718 - val_loss: 28.2814 - val_accuracy: 0.1230
Epoch 45/100
1259/1259 [==============================] - 11s 9ms/step - loss: 3.3030 - accuracy: 0.2763 - val_loss: 29.2292 - val_accuracy: 0.1227
Epoch 46/100
1259/1259 [==============================] - 11s 9ms/step - loss: 3.2584 - accuracy: 0.2841 - val_loss: 28.8271 - val_accuracy: 0.1211
Epoch 47/100
1259/1259 [==============================] - 11s 9ms/step - loss: 3.2145 - accuracy: 0.2907 - val_loss: 30.1880 - val_accuracy: 0.1220
Epoch 48/100
1259/1259 [==============================] - 11s 9ms/step - loss: 3.1666 - accuracy: 0.3000 - val_loss: 29.0877 - val_accuracy: 0.1150
Epoch 49/100
1259/1259 [==============================] - 12s 9ms/step - loss: 3.1291 - accuracy: 0.3031 - val_loss: 30.4579 - val_accuracy: 0.1265
Epoch 50/100
1259/1259 [==============================] - 11s 9ms/step - loss: 3.0989 - accuracy: 0.3113 - val_loss: 30.1047 - val_accuracy: 0.1109
Epoch 51/100
1259/1259 [==============================] - 11s 9ms/step - loss: 3.0430 - accuracy: 0.3180 - val_loss: 30.4653 - val_accuracy: 0.1207
Epoch 52/100
1259/1259 [==============================] - 12s 9ms/step - loss: 3.0016 - accuracy: 0.3242 - val_loss: 29.9269 - val_accuracy: 0.1207
Epoch 53/100
1259/1259 [==============================] - 12s 9ms/step - loss: 2.9472 - accuracy: 0.3358 - val_loss: 30.7540 - val_accuracy: 0.1115
Epoch 54/100
1259/1259 [==============================] - 12s 9ms/step - loss: 2.9289 - accuracy: 0.3397 - val_loss: 31.4299 - val_accuracy: 0.1147
Epoch 55/100
1259/1259 [==============================] - 12s 9ms/step - loss: 2.8597 - accuracy: 0.3513 - val_loss: 31.6839 - val_accuracy: 0.1195
Epoch 56/100
1259/1259 [==============================] - 12s 9ms/step - loss: 2.8454 - accuracy: 0.3586 - val_loss: 32.0642 - val_accuracy: 0.1192
Epoch 57/100
1259/1259 [==============================] - 11s 9ms/step - loss: 2.8153 - accuracy: 0.3668 - val_loss: 32.8230 - val_accuracy: 0.1099
Epoch 58/100
1259/1259 [==============================] - 11s 9ms/step - loss: 2.7687 - accuracy: 0.3722 - val_loss: 33.0815 - val_accuracy: 0.1052
Epoch 59/100
1259/1259 [==============================] - 12s 10ms/step - loss: 2.7297 - accuracy: 0.3837 - val_loss: 32.4366 - val_accuracy: 0.1071
Epoch 60/100
1259/1259 [==============================] - 12s 9ms/step - loss: 2.7077 - accuracy: 0.3884 - val_loss: 32.3653 - val_accuracy: 0.1182
Epoch 61/100
1259/1259 [==============================] - 12s 9ms/step - loss: 2.6574 - accuracy: 0.3970 - val_loss: 32.7342 - val_accuracy: 0.1153
Epoch 62/100
1259/1259 [==============================] - 11s 9ms/step - loss: 2.6173 - accuracy: 0.4048 - val_loss: 33.3435 - val_accuracy: 0.1106
Epoch 63/100
1259/1259 [==============================] - 11s 9ms/step - loss: 2.6145 - accuracy: 0.4094 - val_loss: 32.7989 - val_accuracy: 0.1119
Epoch 64/100
1259/1259 [==============================] - 12s 9ms/step - loss: 2.5724 - accuracy: 0.4115 - val_loss: 32.9530 - val_accuracy: 0.1080
Epoch 65/100
1259/1259 [==============================] - 11s 9ms/step - loss: 2.5247 - accuracy: 0.4273 - val_loss: 33.1921 - val_accuracy: 0.1020
Epoch 66/100
1259/1259 [==============================] - 11s 9ms/step - loss: 2.4935 - accuracy: 0.4287 - val_loss: 33.1907 - val_accuracy: 0.1131
Epoch 67/100
1259/1259 [==============================] - 12s 9ms/step - loss: 2.4738 - accuracy: 0.4344 - val_loss: 33.8599 - val_accuracy: 0.1099
Epoch 68/100
1259/1259 [==============================] - 12s 9ms/step - loss: 2.4751 - accuracy: 0.4383 - val_loss: 34.0607 - val_accuracy: 0.1065
Epoch 69/100
1259/1259 [==============================] - 12s 9ms/step - loss: 2.4106 - accuracy: 0.4451 - val_loss: 33.5866 - val_accuracy: 0.1144
Epoch 70/100
1259/1259 [==============================] - 12s 9ms/step - loss: 2.3821 - accuracy: 0.4553 - val_loss: 33.7491 - val_accuracy: 0.1163
Epoch 71/100
1259/1259 [==============================] - 12s 9ms/step - loss: 2.3647 - accuracy: 0.4584 - val_loss: 34.5417 - val_accuracy: 0.1084
Epoch 72/100
1259/1259 [==============================] - 12s 9ms/step - loss: 2.3422 - accuracy: 0.4631 - val_loss: 34.1619 - val_accuracy: 0.1109
Epoch 73/100
1259/1259 [==============================] - 12s 9ms/step - loss: 2.3076 - accuracy: 0.4702 - val_loss: 34.0050 - val_accuracy: 0.1084
Epoch 74/100
1259/1259 [==============================] - 12s 9ms/step - loss: 2.3071 - accuracy: 0.4740 - val_loss: 34.2133 - val_accuracy: 0.1147
Epoch 75/100
1259/1259 [==============================] - 12s 9ms/step - loss: 2.2503 - accuracy: 0.4759 - val_loss: 33.9111 - val_accuracy: 0.1058
Epoch 76/100
1259/1259 [==============================] - 12s 9ms/step - loss: 2.2167 - accuracy: 0.4925 - val_loss: 35.0675 - val_accuracy: 0.1125
Epoch 77/100
1259/1259 [==============================] - 12s 10ms/step - loss: 2.2121 - accuracy: 0.4908 - val_loss: 35.0796 - val_accuracy: 0.1071
Epoch 78/100
1259/1259 [==============================] - 11s 9ms/step - loss: 2.1943 - accuracy: 0.4936 - val_loss: 34.2224 - val_accuracy: 0.1084
Epoch 79/100
1259/1259 [==============================] - 13s 11ms/step - loss: 2.1579 - accuracy: 0.5009 - val_loss: 34.5191 - val_accuracy: 0.1077
Epoch 80/100
1259/1259 [==============================] - 13s 10ms/step - loss: 2.1489 - accuracy: 0.5049 - val_loss: 35.8632 - val_accuracy: 0.1090
Epoch 81/100
1259/1259 [==============================] - 12s 10ms/step - loss: 2.1266 - accuracy: 0.5052 - val_loss: 34.8432 - val_accuracy: 0.1074
Epoch 82/100
1259/1259 [==============================] - 12s 9ms/step - loss: 2.0830 - accuracy: 0.5130 - val_loss: 35.7247 - val_accuracy: 0.1033
Epoch 83/100
1259/1259 [==============================] - 13s 11ms/step - loss: 2.0682 - accuracy: 0.5209 - val_loss: 35.3208 - val_accuracy: 0.1065
Epoch 84/100
1259/1259 [==============================] - 12s 9ms/step - loss: 2.0702 - accuracy: 0.5256 - val_loss: 35.3447 - val_accuracy: 0.1061
Epoch 85/100
1259/1259 [==============================] - 11s 9ms/step - loss: 2.0445 - accuracy: 0.5174 - val_loss: 34.5911 - val_accuracy: 0.1077

How to know my neural network model's accuracy?

I have trained my neural network model. I want to know my model's accuracy from this training epoch. Do I have to get the average or just the last one?
here's my output
25/25 - 12s - loss: 1.3415 - accuracy: 0.3800 - val_loss: 1.0626 - val_accuracy: 0.5000
Epoch 2/20
25/25 - 12s - loss: 1.0254 - accuracy: 0.5000 - val_loss: 1.1129 - val_accuracy: 0.4000
Epoch 3/20
25/25 - 12s - loss: 0.9160 - accuracy: 0.6500 - val_loss: 0.8640 - val_accuracy: 0.7000
Epoch 4/20
25/25 - 12s - loss: 0.8237 - accuracy: 0.6300 - val_loss: 0.8494 - val_accuracy: 0.6000
Epoch 5/20
25/25 - 11s - loss: 0.7411 - accuracy: 0.7320 - val_loss: 0.7320 - val_accuracy: 0.8000
Epoch 6/20
25/25 - 12s - loss: 0.7625 - accuracy: 0.6600 - val_loss: 1.0259 - val_accuracy: 0.6000
Epoch 7/20
25/25 - 12s - loss: 0.8317 - accuracy: 0.6800 - val_loss: 0.5907 - val_accuracy: 0.7500
Epoch 8/20
25/25 - 12s - loss: 0.5557 - accuracy: 0.8100 - val_loss: 0.4630 - val_accuracy: 0.9000
Epoch 9/20
25/25 - 11s - loss: 0.6640 - accuracy: 0.7629 - val_loss: 0.3308 - val_accuracy: 0.9500
Epoch 10/20
25/25 - 12s - loss: 0.5674 - accuracy: 0.8200 - val_loss: 0.5039 - val_accuracy: 0.8000
Epoch 11/20
25/25 - 12s - loss: 0.5566 - accuracy: 0.8200 - val_loss: 0.2161 - val_accuracy: 0.9500
Epoch 12/20
25/25 - 16s - loss: 0.5190 - accuracy: 0.8400 - val_loss: 0.3210 - val_accuracy: 0.8500
Epoch 13/20
25/25 - 12s - loss: 0.5437 - accuracy: 0.7800 - val_loss: 0.7253 - val_accuracy: 0.6500
Epoch 14/20
25/25 - 12s - loss: 0.5035 - accuracy: 0.8300 - val_loss: 0.4291 - val_accuracy: 0.8500
Epoch 15/20
25/25 - 11s - loss: 0.4276 - accuracy: 0.8600 - val_loss: 0.2902 - val_accuracy: 0.8500
Epoch 16/20
25/25 - 11s - loss: 0.4913 - accuracy: 0.8000 - val_loss: 0.3027 - val_accuracy: 0.9000
Epoch 17/20
25/25 - 11s - loss: 0.2931 - accuracy: 0.9100 - val_loss: 0.2718 - val_accuracy: 0.9000
Epoch 18/20
25/25 - 11s - loss: 0.4554 - accuracy: 0.8500 - val_loss: 0.4412 - val_accuracy: 0.8000
Epoch 19/20
25/25 - 11s - loss: 0.3803 - accuracy: 0.8400 - val_loss: 0.2479 - val_accuracy: 1.0000
Epoch 20/20
25/25 - 12s - loss: 0.2692 - accuracy: 0.9200 - val_loss: 0.1805 - val_accuracy: 1.0000
<tensorflow.python.keras.callbacks.History at 0x7f64eec7ada0>```
Assuming you train your model like this:
history = model.fit(...)
you can access accuracy through history.history['acc']. Other useful metrics:
loss - loss
val_acc - validation accuracy
val_loss - validation loss
Last two are present only if you have validation set.

Loss doesn't decrease on Google App Engine, but it does on Jupyter Notebook

I am running the same lines of code w/ the same source files on both Google App Engine and Jupyter notebook:
model = load_model("test.h5")
model.compile(optimizer=Adam(lr=1e-2, decay=0), loss="binary_crossentropy", metrics=['accuracy'])
with open("data.json", 'r') as f:
data = json.load(f)
X = data[0]
y = data[1]
history = model.fit(X, y, validation_split=0, epochs=50, batch_size=10)
The output of GAE is as follows:
Epoch 1/50
2/2 [==============================] - 1s 316ms/step - loss: 8.0590 - acc: 0.5000
Epoch 2/50
2/2 [==============================] - 0s 50ms/step - loss: 8.0590 - acc: 0.5000
Epoch 3/50
2/2 [==============================] - 0s 40ms/step - loss: 8.0590 - acc: 0.5000
Epoch 4/50
2/2 [==============================] - 0s 37ms/step - loss: 8.0590 - acc: 0.5000
Epoch 5/50
2/2 [==============================] - 0s 34ms/step - loss: 8.0590 - acc: 0.5000
Epoch 6/50
2/2 [==============================] - 0s 40ms/step - loss: 8.0590 - acc: 0.5000
Epoch 7/50
2/2 [==============================] - 0s 44ms/step - loss: 8.0590 - acc: 0.5000
Epoch 8/50
2/2 [==============================] - 0s 40ms/step - loss: 8.0590 - acc: 0.5000
Epoch 9/50
2/2 [==============================] - 0s 31ms/step - loss: 8.0590 - acc: 0.5000
Epoch 10/50
2/2 [==============================] - 0s 40ms/step - loss: 8.0590 - acc: 0.5000
...
Epoch 50/50
2/2 [==============================] - 0s 45ms/step - loss: 8.0590 - acc: 0.5000
Whereas Jupyter Notebook is:
Epoch 1/50
2/2 [==============================] - 0s 164ms/step - loss: 952036.8125 - accuracy: 0.5000
Epoch 2/50
2/2 [==============================] - 0s 39ms/step - loss: 393826.0000 - accuracy: 0.5000
Epoch 3/50
2/2 [==============================] - 0s 38ms/step - loss: 99708.9375 - accuracy: 0.5000
Epoch 4/50
2/2 [==============================] - 0s 39ms/step - loss: 8989.7822 - accuracy: 0.5000
Epoch 5/50
2/2 [==============================] - 0s 39ms/step - loss: 8760.8223 - accuracy: 0.5000
Epoch 6/50
2/2 [==============================] - 0s 40ms/step - loss: 3034.8613 - accuracy: 0.5000
Epoch 7/50
2/2 [==============================] - 0s 40ms/step - loss: 167.2695 - accuracy: 0.0000e+00
Epoch 8/50
2/2 [==============================] - 0s 39ms/step - loss: 0.6670 - accuracy: 1.0000
Epoch 9/50
2/2 [==============================] - 0s 41ms/step - loss: 0.6619 - accuracy: 1.0000
Epoch 10/50
2/2 [==============================] - 0s 40ms/step - loss: 0.6551 - accuracy: 1.0000
...
Epoch 50/50
2/2 [==============================] - 0s 42ms/step - loss: 0.3493 - accuracy: 1.0000
Why might this be the case? I'm pretty lost at this point. Both machines have keras==2.2.4 and tensorflow==1.14.0 installed.

Keras prints out result of every batch in a single epoch, why is that?

As described in Keras documentation, the verbose=1 asks the keras to print out results in a progress bar. But sometimes keras prints out the results of every batch, which makes a very messy printout report (see below). I wonder why is that? I mean, the only setup is the parameter of verbose, isn't it?
My code is simple:
history = model.fit(X_shuffle, y_scores_one_hot,
validation_split=0.2, verbose = 1,
epochs = 100, batch_size = 50)
Wrong printout:
Epoch 1/100
5750/8107 [====================>.........] - ETA: 5:03 - loss: 1.3690 - acc: 0.520 - ETA: 1:42 - loss: 1.3600 - acc: 0.533 - ETA: 1:02 - loss: 1.3994 - acc: 0.500 - ETA: 39s - loss: 1.4173 - acc: 0.482 - ETA: 29s - loss: 1.4189 - acc: 0.47 - ETA: 23s - loss: 1.4320 - acc: 0.46 - ETA: 19s - loss: 1.4432 - acc: 0.46 - ETA: 16s - loss: 1.4373 - acc: 0.46 - ETA: 14s - loss: 1.4318 - acc: 0.46 - ETA: 12s - loss: 1.4322 - acc: 0.46 - ETA: 11s - loss: 1.4314 - acc: 0.46 - ETA: 10s - loss: 1.4342 - acc: 0.46 - ETA: 10s - loss: 1.4386 - acc: 0.45 - ETA: 9s - loss: 1.4399 - acc: 0.4557 - ETA: 8s - loss: 1.4373 - acc: 0.458 - ETA: 7s - loss: 1.4418 - acc: 0.453 - ETA: 7s - loss: 1.4419 - acc: 0.454 - ETA: 6s - loss: 1.4435 - acc: 0.453 - ETA: 6s - loss: 1.4421 - acc: 0.453 - ETA: 6s - loss: 1.4439 - acc: 0.451 - ETA: 5s - loss: 1.4437 - acc: 0.452 - ETA: 5s - loss: 1.4388 - acc: 0.456 - ETA: 5s - loss: 1.4430 - acc: 0.453 - ETA: 4s - loss: 1.4440 - acc: 0.452 - ETA: 4s - loss: 1.4428 - acc: 0.452 - ETA: 4s - loss: 1.4469 - acc: 0.449 - ETA: 4s - loss: 1.4471 - acc: 0.450 - ETA: 3s - loss: 1.4517 - acc: 0.445 - ETA: 3s - loss: 1.4489
I expected something like:
Epoch 1/100
3009/3009 [==============================] - 30s 10ms/step - loss: 1.5875 - acc: 0.2795 - val_loss: 1.5542 - val_acc: 0.4130
Epoch 2/100
3009/3009 [==============================] - 27s 9ms/step - loss: 1.5049 - acc: 0.4403 - val_loss: 1.4963 - val_acc: 0.4130
That looks like an interaction with a notebook/kernel environment.
You may prefer the results if you change verbose=1 to verbose=2.

Categories