My code snippet is below -
from tensorflow.keras.applications import InceptionResNetV2
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Conv2D, MaxPool2D, Dense, Flatten, Dropout, Input, Resizing
inputs = Input(shape=x_train.shape[1:])
x = Conv2D(filters=3, kernel_size=(1,1), activation='relu')(inputs)
x = Resizing(height=75, width=75)(x)
base_model = InceptionResNetV2(input_shape=(75, 75, 3), include_top=False, input_tensor=x, weights='imagenet')
The expcetion I am getting is -
ValueError Traceback (most recent call last)
/var/folders/26/0fbl62dn7zsd3x5t5f3zh1mr0000gn/T/ipykernel_90240/1249320150.py in <module>
7 # x = Resizing(height=75, width=75)(x)
8
----> 9 base_model = InceptionResNetV2(input_shape=(75, 75, 3), include_top=False, input_tensor=x, weights='imagenet')
10 base_model.trainable = False
11
/opt/homebrew/Caskroom/miniforge/base/envs/pattern-recognition/lib/python3.9/site-packages/keras/applications/inception_resnet_v2.py in InceptionResNetV2(include_top, weights, input_tensor, input_shape, pooling, classes, classifier_activation, **kwargs)
246 cache_subdir='models',
247 file_hash='d19885ff4a710c122648d3b5c3b684e4')
--> 248 model.load_weights(weights_path)
249 elif weights is not None:
250 model.load_weights(weights)
/opt/homebrew/Caskroom/miniforge/base/envs/pattern-recognition/lib/python3.9/site-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
65 except Exception as e: # pylint: disable=broad-except
66 filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67 raise e.with_traceback(filtered_tb) from None
68 finally:
69 del filtered_tb
/opt/homebrew/Caskroom/miniforge/base/envs/pattern-recognition/lib/python3.9/site-packages/keras/saving/hdf5_format.py in load_weights_from_hdf5_group(f, model)
717 layer_names = filtered_layer_names
718 if len(layer_names) != len(filtered_layers):
--> 719 raise ValueError(
720 f'Layer count mismatch when loading weights from file. '
721 f'Model expected {len(filtered_layers)} layers, found '
ValueError: Layer count mismatch when loading weights from file. Model expected 449 layers, found 448 saved layers.
I have tried this with multiple models found here, however, they all fail with the same error, ie: the saved layers are one less than expected. Please let me know if there is a workaround.