-
Hi, I am working on Food Vision Milestone project. I was able to get a model similar to the tutorial while fitting the test data and saved the checkpoints for weights as shown below. #############################################################################
history_101_food_classes_feature_extract = model.fit(train_data,
epochs=3,
steps_per_epoch=(len(train_data)),
validation_data=test_data,
validation_steps=int(0.15*len(test_data)),
callbacks=[create_tensorboard_callback(dir_name="training_logs",
experiment_name="efficientnetb0_101"),
model_checkpoint])
Saving TensorBoard log files to: training_logs/efficientnetb0_101/20220720-053759
Epoch 1/3
2368/2368 [==============================] - 170s 71ms/step - loss: 1.1328 - accuracy: 0.7048 - val_loss: 1.0842 - val_accuracy: 0.7052
Epoch 2/3
2368/2368 [==============================] - 170s 71ms/step - loss: 1.0383 - accuracy: 0.7292 - val_loss: 1.0708 - val_accuracy: 0.7055
Epoch 3/3
2368/2368 [==============================] - 169s 71ms/step - loss: 0.9670 - accuracy: 0.7449 - val_loss: 1.0768 - val_accuracy: 0.7076
###############################################################################
results_feature_extract_model = model.evaluate(test_data)
results_feature_extract_model
790/790 [==============================] - 50s 63ms/step - loss: 1.0642 - accuracy: 0.7098
[1.0641952753067017, 0.7097821831703186] ############################################################################### Now, when I clone the model and load the weights, it is giving me very low accuracy. Can you please help me with it? ###############################################################################
cloned_model = tf.keras.models.clone_model(model)
cloned_model.summary()
Model: "model"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_2 (InputLayer) [(None, 224, 224, 3)] 0
efficientnetb0 (Functional) (None, None, None, 1280) 4049571
global_average_pooling2d (G (None, 1280) 0
lobalAveragePooling2D)
dense (Dense) (None, 101) 129381
activation (Activation) (None, 101) 0
=================================================================
Total params: 4,178,952
Trainable params: 129,381
Non-trainable params: 4,049,571
_________________________________________________________________
###########################################################################
cloned_model.load_weights(checkpoint_path)
<tensorflow.python.training.tracking.util.CheckpointLoadStatus at 0x7fc84333af50>
###########################################################################
cloned_model.compile(loss="sparse_categorical_crossentropy",
optimizer=tf.keras.optimizers.Adam(),
metrics=["accuracy"])
results_cloned_model_with_loaded_weights = cloned_model.evaluate(test_data)
790/790 [==============================] - 49s 61ms/step - loss: 1.7362 - accuracy: 0.5509 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey, I found out that the EfficientNetBX family has issues serializing to save the model on TF2.10 >, I am unable to conclude if this issue is related to the loss of accuracy after loading weights, did you ever find out the reason? |
Beta Was this translation helpful? Give feedback.
-
Hi @reshma93s and @santiagorg2401 , Thank you for your troubleshooting steps and tips. After a fair bit of troubleshooting, it looks like the As I was able to create a new model (using the same modelling code as the original model was made with) and load the weights to achieve the same performance. Alongside this, I installed See the full update/solution here: #550 |
Beta Was this translation helpful? Give feedback.
Hi @reshma93s and @santiagorg2401 ,
Thank you for your troubleshooting steps and tips.
After a fair bit of troubleshooting, it looks like the
tf.keras.clone_model
method is not performing reliably.As I was able to create a new model (using the same modelling code as the original model was made with) and load the weights to achieve the same performance.
Alongside this, I installed
tf-nightly
(May 2023 version which is 2.14.0) to help fix withtf.keras.applications.efficientnet
issues.See the full update/solution here: #550