EfficientNetV2XL pretrained with imagenet21k has problems with output shape #94
Replies: 4 comments 3 replies
-
The output shape for raw import keras_efficientnet_v2
base_model = keras_efficientnet_v2.EfficientNetV2XL(pretrained="imagenet21k", num_classes=21843)
print(base_model.output_shape)
# (None, 21843)
# Run prediction
import tensorflow as tf
from skimage.data import chelsea
from keras_cv_attention_models.imagenet import decode_predictions_imagenet21k
imm = tf.image.resize(chelsea(), base_model .input_shape[1:3]) # Chelsea the cat
pred = base_model (tf.expand_dims(imm / 128. - 1., 0)).numpy()
print(decode_predictions_imagenet21k(pred)[0])
# [('n02124075', 'Egyptian_cat', 0.08923767), ('n02122298', 'kitty, kitty-cat, puss, pussy, pussycat', 0.0891152), ...] If want the imagenet fine-tuned weights, set |
Beta Was this translation helpful? Give feedback.
-
When I use my own value of WARNING:tensorflow:Skipping loading of weights for layer predictions due to mismatch in shape ((1280, 30) vs (1280, 21843)). So layer before output layer doesn't get weights and model shows worse results than same model from tensorflow.hub. |
Beta Was this translation helpful? Give feedback.
-
It's just the header layer weights skipped, as the log printed. All layers before that got the pretrained weights. You need to fine-tune a new header for using on your own dataset, or the output layers are just randomly initialized. |
Beta Was this translation helpful? Give feedback.
-
WARNING:tensorflow:Skipping loading of weights for layer predictions due to mismatch in shape ((1280, 1000) vs (1280, 21843)).
WARNING:tensorflow:Skipping loading of weights for layer predictions due to mismatch in shape ((1000,) vs (21843,)).
Output layer is:
predictions (Dense) (None, 1000) 1281000 dropout_2[0][0]
It has to be non-fine-tuned model, but somehow output layer has wrong shape.
Beta Was this translation helpful? Give feedback.
All reactions