can't load saved Convnext model 
model download link - https://easyupload.io/mn1i8h @mv96,
The link provided contains only the `.h5` model link and it doesn't contain any code. Please provide the complete code to debug.  

There are two formats you can use to save an entire model to disk: the TensorFlow SavedModel format, and the older Keras H5 format. The recommended format is SavedModel. It is the default when you use model.save().

You can switch to the H5 format by:

```
Passing save_format='h5' to save().
Passing a filename that ends in .h5 or .keras to save().
```
Also  refer to [this](https://www.tensorflow.org/guide/keras/save_and_serialize) guide for the reference.
Alternative approach can be followed as below;

`my_loaded_model = tf.keras.models.load_model('my_models_name.h5', custom_objects={'KerasLayer':hub.KerasLayer , 'AdamWeightDecay': optimizer})`
Also, can you also try saving the model in 'tf' format as **model.save('MinimalExample_tf', save_format='tf')** and load the model
Saving a Keras model:

```
model = ...  # Get model (Sequential, Functional Model, or Model subclass)
model.save('path/to/location')
```
Loading the model back:

```
from tensorflow import keras
model = keras.models.load_model('path/to/location')
```
Also the PR [#17547](https://github.com/keras-team/keras/pull/17547) was merged for the similar issue where fixes a bug in the [LayerScale](https://github.com/keras-team/keras/blob/master/keras/applications/convnext.py#L199) layer, which hindered **ConvNeXt** pretrained models to work with mixed precision. The solution was simply to set the appropriate dtype in the gamma variable of the **LayerScale** layer.

https://github.com/andreped/keras/blob/810fd3c203dbae8bb1f888ebc91cdd31ff30cf34/keras/applications/convnext.py#L221


```
    def build(self, input_shape):
        self.gamma = self.add_weight(
            shape=(self.projection_dim,),
            initializer=initializers.Constant(self.init_values),
            trainable=True,
``` This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Thank you.
 Closing this as stale. Please reopen if this is still a valid request. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/59767">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/59767">No</a>
 I am having the same problem using ConvNeXt models from the Keras application library.

I have tried using both ConvNeXtLarge and ConvNeXtBase and I receive the same error. It appears to be some problem with the "LayerScale" layeres in the provided ConvNeXt network.

I have tried the saving the model as a 'tf' model (in order to re save it as a .keras model as discussed in @tilakrayal answer above but run into a different error that does not allow the model to be saved in this format (more on this below).

Bellow is some of my code for context. 

In training (for transfer learning) I build my model using:

```
base_model = tf.keras.applications.ConvNeXtBase(
    include_top=False,  
    weights='imagenet',  
    input_shape=(image_height, image_width, 3)  
)
base_model.trainable = False

classification_head = tf.keras.Sequential([
    tf.keras.layers.Flatten(),
    tf.keras.layers.Dense(512, activation='relu'),
    tf.keras.layers.Dropout(0.5),
    tf.keras.layers.Dense(1, activation='sigmoid')  # Binary classification
])

transfer_model = tf.keras.Sequential([
    base_model,
    classification_head
])
```

The model is then compiled and trained (with a few callbacks e.g learning rate decay - but nothing crazy).
training runs as expected and appears to give intended results.

I then save the model in both .keras and .h5 format.


```
model_filename = os.path.join(save_folder, f"{model_save_name}_TL.h5")
transfer_model.save(model_filename)

model_filename = os.path.join(save_folder, f"{model_save_name}_TL.keras")
transfer_model.save(model_filename)
```

These work fine, but when I try and load them later I get two different errors.

Using the .keras format I get this error:


```
[/usr/local/lib/python3.10/dist-packages/keras/src/saving/saving_api.py](https://localhost:8080/#) in load_model(filepath, custom_objects, compile, safe_mode, **kwargs)
    228                 f"with the native Keras format: {list(kwargs.keys())}"
    229             )
--> 230         return saving_lib.load_model(
    231             filepath,
    232             custom_objects=custom_objects,

[/usr/local/lib/python3.10/dist-packages/keras/src/saving/saving_lib.py](https://localhost:8080/#) in load_model(filepath, custom_objects, compile, safe_mode)
    273 
    274     except Exception as e:
--> 275         raise e
    276     else:
    277         return model

[/usr/local/lib/python3.10/dist-packages/keras/src/saving/saving_lib.py](https://localhost:8080/#) in load_model(filepath, custom_objects, compile, safe_mode)
    238             # Construct the model from the configuration file in the archive.
    239             with ObjectSharingScope():
--> 240                 model = deserialize_keras_object(
    241                     config_dict, custom_objects, safe_mode=safe_mode
    242                 )

[/usr/local/lib/python3.10/dist-packages/keras/src/saving/serialization_lib.py](https://localhost:8080/#) in deserialize_keras_object(config, custom_objects, safe_mode, **kwargs)
    702     safe_mode_scope = SafeModeScope(safe_mode)
    703     with custom_obj_scope, safe_mode_scope:
--> 704         instance = cls.from_config(inner_config)
    705         build_config = config.get("build_config", None)
    706         if build_config:

[/usr/local/lib/python3.10/dist-packages/keras/src/engine/sequential.py](https://localhost:8080/#) in from_config(cls, config, custom_objects)
    471         for layer_config in layer_configs:
    472             use_legacy_format = "module" not in layer_config
--> 473             layer = layer_module.deserialize(
    474                 layer_config,
    475                 custom_objects=custom_objects,

[/usr/local/lib/python3.10/dist-packages/keras/src/layers/serialization.py](https://localhost:8080/#) in deserialize(config, custom_objects, use_legacy_format)
    267         )
    268     if use_legacy_format:
--> 269         return legacy_serialization.deserialize_keras_object(
    270             config,
    271             module_objects=LOCAL.ALL_OBJECTS,

[/usr/local/lib/python3.10/dist-packages/keras/src/saving/legacy/serialization.py](https://localhost:8080/#) in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
    495             if "custom_objects" in arg_spec.args:
    496                 tlco = object_registration._THREAD_LOCAL_CUSTOM_OBJECTS.__dict__
--> 497                 deserialized_obj = cls.from_config(
    498                     cls_config,
    499                     custom_objects={

[/usr/local/lib/python3.10/dist-packages/keras/src/engine/training.py](https://localhost:8080/#) in from_config(cls, config, custom_objects)
   3225                 # Revive Functional model
   3226                 # (but not Functional subclasses with a custom __init__)
-> 3227                 inputs, outputs, layers = functional.reconstruct_from_config(
   3228                     config, custom_objects
   3229                 )

[/usr/local/lib/python3.10/dist-packages/keras/src/engine/functional.py](https://localhost:8080/#) in reconstruct_from_config(config, custom_objects, created_layers)
   1500                 while layer_nodes:
   1501                     node_data = layer_nodes[0]
-> 1502                     if process_node(layer, node_data):
   1503                         layer_nodes.pop(0)
   1504                     else:

[/usr/local/lib/python3.10/dist-packages/keras/src/engine/functional.py](https://localhost:8080/#) in process_node(layer, node_data)
   1440                     input_tensors
   1441                 )
-> 1442             output_tensors = layer(input_tensors, **kwargs)
   1443 
   1444             # Update node index map.

TypeError: 'str' object is not callable
```


and when trying to load the .h5 model I get the same error as described at the top of this thread.


```
[/usr/local/lib/python3.10/dist-packages/keras/src/saving/saving_api.py](https://localhost:8080/#) in load_model(filepath, custom_objects, compile, safe_mode, **kwargs)
    236 
    237     # Legacy case.
--> 238     return legacy_sm_saving_lib.load_model(
    239         filepath, custom_objects=custom_objects, compile=compile, **kwargs
    240     )

[/usr/local/lib/python3.10/dist-packages/keras/src/utils/traceback_utils.py](https://localhost:8080/#) in error_handler(*args, **kwargs)
     68             # To get the full stack trace, call:
     69             # `tf.debugging.disable_traceback_filtering()`
---> 70             raise e.with_traceback(filtered_tb) from None
     71         finally:
     72             del filtered_tb

[/usr/local/lib/python3.10/dist-packages/keras/src/saving/legacy/serialization.py](https://localhost:8080/#) in class_and_config_for_serialized_keras_object(config, module_objects, custom_objects, printable_module_name)
    363     )
    364     if cls is None:
--> 365         raise ValueError(
    366             f"Unknown {printable_module_name}: '{class_name}'. "
    367             "Please ensure you are using a `keras.utils.custom_object_scope` "

ValueError: Unknown layer: 'LayerScale'. Please ensure you are using a `keras.utils.custom_object_scope` and that this object is included in the scope. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.
```


I don't understand how to do the registration of a custom object when it is a pretrained model pulled from keras applications. Or if this is a bug or something else. 

I'm not sure if this is relevant to this issue but I have tried saving the model as tf format to use the fix described above. My code for this is:

```
model_filename = os.path.join(save_folder, f"{model_save_name}_TL_tf")
transfer_model.save(model_filename,save_format="tf")
```

I get this error however:

```
[/usr/local/lib/python3.10/dist-packages/keras/src/utils/traceback_utils.py](https://localhost:8080/#) in error_handler(*args, **kwargs)
     68             # To get the full stack trace, call:
     69             # `tf.debugging.disable_traceback_filtering()`
---> 70             raise e.with_traceback(filtered_tb) from None
     71         finally:
     72             del filtered_tb

[/usr/local/lib/python3.10/dist-packages/tensorflow/python/saved_model/save.py](https://localhost:8080/#) in fill_object_graph_proto(self, proto)
    351         child_proto = object_proto.children.add()
    352         child_proto.node_id = self.node_ids[child.ref]
--> 353         child_proto.local_name = child.name
    354       for name, ref in self.augmented_graph_view.list_dependencies(node):
    355         child_proto = object_proto.dependencies.add()

TypeError: None has type NoneType, but expected one of: bytes, unicode
```


Any help on this would be appreciated. This is the only source I have found that has the exact same problem as me.

Its it relevant the input images are somewhat large at 572x572 (the model is scaled accordingly), it is being used as a binary classifier and I have tried training on a range of different NVIDIA GPUs  I have been playing around and have simplified the code to recreate the same problem. This time with the default ConvNeXt model just downloading it from applications and then saving it locally and trying to load it in with the same results. See bellow:

Here is the code for downloading the model and saving it as the two file types (NOTE: again I am unable to save as the 'tf' file format)


```
import tensorflow as tf
from tensorflow import keras
from keras.applications.convnext import ConvNeXtBase, preprocess_input
import os

print(tf.__version__)

model_save_name ="OG_ConvNeXTBase_V2"
save_folder = "/content/mydata/Models/Test_Space"

test_model = tf.keras.applications.ConvNeXtBase(
    model_name="convnext_base",
    include_top=True,
    include_preprocessing=True,
    weights="imagenet",
    input_tensor=None,
    input_shape=None,
    pooling=None,
    classes=1000,
    classifier_activation="softmax",
)


model_filename = os.path.join(save_folder, f"{model_save_name}_TL.h5")
test_model.save(model_filename)

model_filename = os.path.join(save_folder, f"{model_save_name}_TL.keras")
test_model.save(model_filename)
```

Then when I re load it I get the same errors:

```
load_model_filename = '/content/mydata/Models/Test_Space/OG_ConvNeXTBase_V2_TL.h5'

load_test = tf.keras.models.load_model(load_model_filename)
```

```
ValueError Traceback (most recent call last)
[<ipython-input-2-371145205fb0>](https://localhost:8080/#) in <cell line: 3>()
      1 load_model_filename = '/content/mydata/Models/Test_Space/OG_ConvNeXTBase_V2_TL.h5'
      2 
----> 3 load_test = tf.keras.models.load_model(load_model_filename)


[/usr/local/lib/python3.10/dist-packages/keras/src/saving/saving_api.py](https://localhost:8080/#) in load_model(filepath, custom_objects, compile, safe_mode, **kwargs)
    236 
    237     # Legacy case.
--> 238     return legacy_sm_saving_lib.load_model(
    239         filepath, custom_objects=custom_objects, compile=compile, **kwargs
    240     )

[/usr/local/lib/python3.10/dist-packages/keras/src/utils/traceback_utils.py](https://localhost:8080/#) in error_handler(*args, **kwargs)
     68             # To get the full stack trace, call:
     69             # `tf.debugging.disable_traceback_filtering()`
---> 70             raise e.with_traceback(filtered_tb) from None
     71         finally:
     72             del filtered_tb

[/usr/local/lib/python3.10/dist-packages/keras/src/saving/legacy/serialization.py](https://localhost:8080/#) in class_and_config_for_serialized_keras_object(config, module_objects, custom_objects, printable_module_name)
    363     )
    364     if cls is None:
--> 365         raise ValueError(
    366             f"Unknown {printable_module_name}: '{class_name}'. "
    367             "Please ensure you are using a `keras.utils.custom_object_scope` "

ValueError: Unknown layer: 'LayerScale'. Please ensure you are using a `keras.utils.custom_object_scope` and that this object is included in the scope. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.
```

and . keras version

```
load_model_filename = '/content/mydata/Models/Test_Space/OG_ConvNeXTBase_V2_TL.keras'

load_test = tf.keras.models.load_model(load_model_filename)
```

```
TypeError  Traceback (most recent call last)
[<ipython-input-3-9a9c94514126>](https://localhost:8080/#) in <cell line: 3>()
      1 load_model_filename = '/content/mydata/Models/Test_Space/OG_ConvNeXTBase_V2_TL.keras'
      2 
----> 3 load_test = tf.keras.models.load_model(load_model_filename)

[/usr/local/lib/python3.10/dist-packages/keras/src/saving/saving_api.py](https://localhost:8080/#) in load_model(filepath, custom_objects, compile, safe_mode, **kwargs)
    228                 f"with the native Keras format: {list(kwargs.keys())}"
    229             )
--> 230         return saving_lib.load_model(
    231             filepath,
    232             custom_objects=custom_objects,

[/usr/local/lib/python3.10/dist-packages/keras/src/saving/saving_lib.py](https://localhost:8080/#) in load_model(filepath, custom_objects, compile, safe_mode)
    273 
    274     except Exception as e:
--> 275         raise e
    276     else:
    277         return model

[/usr/local/lib/python3.10/dist-packages/keras/src/saving/saving_lib.py](https://localhost:8080/#) in load_model(filepath, custom_objects, compile, safe_mode)
    238             # Construct the model from the configuration file in the archive.
    239             with ObjectSharingScope():
--> 240                 model = deserialize_keras_object(
    241                     config_dict, custom_objects, safe_mode=safe_mode
    242                 )

[/usr/local/lib/python3.10/dist-packages/keras/src/saving/serialization_lib.py](https://localhost:8080/#) in deserialize_keras_object(config, custom_objects, safe_mode, **kwargs)
    702     safe_mode_scope = SafeModeScope(safe_mode)
    703     with custom_obj_scope, safe_mode_scope:
--> 704         instance = cls.from_config(inner_config)
    705         build_config = config.get("build_config", None)
    706         if build_config:

[/usr/local/lib/python3.10/dist-packages/keras/src/engine/training.py](https://localhost:8080/#) in from_config(cls, config, custom_objects)
   3225                 # Revive Functional model
   3226                 # (but not Functional subclasses with a custom __init__)
-> 3227                 inputs, outputs, layers = functional.reconstruct_from_config(
   3228                     config, custom_objects
   3229                 )

[/usr/local/lib/python3.10/dist-packages/keras/src/engine/functional.py](https://localhost:8080/#) in reconstruct_from_config(config, custom_objects, created_layers)
   1500                 while layer_nodes:
   1501                     node_data = layer_nodes[0]
-> 1502                     if process_node(layer, node_data):
   1503                         layer_nodes.pop(0)
   1504                     else:

[/usr/local/lib/python3.10/dist-packages/keras/src/engine/functional.py](https://localhost:8080/#) in process_node(layer, node_data)
   1440                     input_tensors
   1441                 )
-> 1442             output_tensors = layer(input_tensors, **kwargs)
   1443 
   1444             # Update node index map.

TypeError: 'str' object is not callable
```
I hope this is helpful for re-creating the error > I have been playing around and have simplified the code to recreate the same problem. This time with the default ConvNeXt model just downloading it from applications and then saving it locally and trying to load it in with the same results. See bellow:
> 
> Here is the code for downloading the model and saving it as the two file types (NOTE: again I am unable to save as the 'tf' file format)
> 
> ```
> import tensorflow as tf
> from tensorflow import keras
> from keras.applications.convnext import ConvNeXtBase, preprocess_input
> import os
> 
> print(tf.__version__)
> 
> model_save_name ="OG_ConvNeXTBase_V2"
> save_folder = "/content/mydata/Models/Test_Space"
> 
> test_model = tf.keras.applications.ConvNeXtBase(
>     model_name="convnext_base",
>     include_top=True,
>     include_preprocessing=True,
>     weights="imagenet",
>     input_tensor=None,
>     input_shape=None,
>     pooling=None,
>     classes=1000,
>     classifier_activation="softmax",
> )
> 
> 
> model_filename = os.path.join(save_folder, f"{model_save_name}_TL.h5")
> test_model.save(model_filename)
> 
> model_filename = os.path.join(save_folder, f"{model_save_name}_TL.keras")
> test_model.save(model_filename)
> ```
> 
> Then when I re load it I get the same errors:
> 
> ```
> load_model_filename = '/content/mydata/Models/Test_Space/OG_ConvNeXTBase_V2_TL.h5'
> 
> load_test = tf.keras.models.load_model(load_model_filename)
> ```
> 
> ```
> ValueError Traceback (most recent call last)
> [<ipython-input-2-371145205fb0>](https://localhost:8080/#) in <cell line: 3>()
>       1 load_model_filename = '/content/mydata/Models/Test_Space/OG_ConvNeXTBase_V2_TL.h5'
>       2 
> ----> 3 load_test = tf.keras.models.load_model(load_model_filename)
> 
> 
> [/usr/local/lib/python3.10/dist-packages/keras/src/saving/saving_api.py](https://localhost:8080/#) in load_model(filepath, custom_objects, compile, safe_mode, **kwargs)
>     236 
>     237     # Legacy case.
> --> 238     return legacy_sm_saving_lib.load_model(
>     239         filepath, custom_objects=custom_objects, compile=compile, **kwargs
>     240     )
> 
> [/usr/local/lib/python3.10/dist-packages/keras/src/utils/traceback_utils.py](https://localhost:8080/#) in error_handler(*args, **kwargs)
>      68             # To get the full stack trace, call:
>      69             # `tf.debugging.disable_traceback_filtering()`
> ---> 70             raise e.with_traceback(filtered_tb) from None
>      71         finally:
>      72             del filtered_tb
> 
> [/usr/local/lib/python3.10/dist-packages/keras/src/saving/legacy/serialization.py](https://localhost:8080/#) in class_and_config_for_serialized_keras_object(config, module_objects, custom_objects, printable_module_name)
>     363     )
>     364     if cls is None:
> --> 365         raise ValueError(
>     366             f"Unknown {printable_module_name}: '{class_name}'. "
>     367             "Please ensure you are using a `keras.utils.custom_object_scope` "
> 
> ValueError: Unknown layer: 'LayerScale'. Please ensure you are using a `keras.utils.custom_object_scope` and that this object is included in the scope. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.
> ```
> 
> and . keras version
> 
> ```
> load_model_filename = '/content/mydata/Models/Test_Space/OG_ConvNeXTBase_V2_TL.keras'
> 
> load_test = tf.keras.models.load_model(load_model_filename)
> ```
> 
> ```
> TypeError  Traceback (most recent call last)
> [<ipython-input-3-9a9c94514126>](https://localhost:8080/#) in <cell line: 3>()
>       1 load_model_filename = '/content/mydata/Models/Test_Space/OG_ConvNeXTBase_V2_TL.keras'
>       2 
> ----> 3 load_test = tf.keras.models.load_model(load_model_filename)
> 
> [/usr/local/lib/python3.10/dist-packages/keras/src/saving/saving_api.py](https://localhost:8080/#) in load_model(filepath, custom_objects, compile, safe_mode, **kwargs)
>     228                 f"with the native Keras format: {list(kwargs.keys())}"
>     229             )
> --> 230         return saving_lib.load_model(
>     231             filepath,
>     232             custom_objects=custom_objects,
> 
> [/usr/local/lib/python3.10/dist-packages/keras/src/saving/saving_lib.py](https://localhost:8080/#) in load_model(filepath, custom_objects, compile, safe_mode)
>     273 
>     274     except Exception as e:
> --> 275         raise e
>     276     else:
>     277         return model
> 
> [/usr/local/lib/python3.10/dist-packages/keras/src/saving/saving_lib.py](https://localhost:8080/#) in load_model(filepath, custom_objects, compile, safe_mode)
>     238             # Construct the model from the configuration file in the archive.
>     239             with ObjectSharingScope():
> --> 240                 model = deserialize_keras_object(
>     241                     config_dict, custom_objects, safe_mode=safe_mode
>     242                 )
> 
> [/usr/local/lib/python3.10/dist-packages/keras/src/saving/serialization_lib.py](https://localhost:8080/#) in deserialize_keras_object(config, custom_objects, safe_mode, **kwargs)
>     702     safe_mode_scope = SafeModeScope(safe_mode)
>     703     with custom_obj_scope, safe_mode_scope:
> --> 704         instance = cls.from_config(inner_config)
>     705         build_config = config.get("build_config", None)
>     706         if build_config:
> 
> [/usr/local/lib/python3.10/dist-packages/keras/src/engine/training.py](https://localhost:8080/#) in from_config(cls, config, custom_objects)
>    3225                 # Revive Functional model
>    3226                 # (but not Functional subclasses with a custom __init__)
> -> 3227                 inputs, outputs, layers = functional.reconstruct_from_config(
>    3228                     config, custom_objects
>    3229                 )
> 
> [/usr/local/lib/python3.10/dist-packages/keras/src/engine/functional.py](https://localhost:8080/#) in reconstruct_from_config(config, custom_objects, created_layers)
>    1500                 while layer_nodes:
>    1501                     node_data = layer_nodes[0]
> -> 1502                     if process_node(layer, node_data):
>    1503                         layer_nodes.pop(0)
>    1504                     else:
> 
> [/usr/local/lib/python3.10/dist-packages/keras/src/engine/functional.py](https://localhost:8080/#) in process_node(layer, node_data)
>    1440                     input_tensors
>    1441                 )
> -> 1442             output_tensors = layer(input_tensors, **kwargs)
>    1443 
>    1444             # Update node index map.
> 
> TypeError: 'str' object is not callable
> ```
> 
> I hope this is helpful for re-creating the error

Has someone found any solution?? I have exactly the same error, I don't know what to do :( The LayerScale layer is not exposed using @keras_export in https://github.com/keras-team/keras/blob/b80dd12da9c0bc3f569eca3455e77762cf2ee8ef/keras/applications/convnext.py#L199 
A work around this error would be to copy the custom layers LayerScale and also StochasticDepth to a local script and import them, and then to load the model as follows:

`best_model = models.load_model(
                <path_to_checkpoint>, compile=False,
                custom_objects={
                    "LayerScale": LayerScale,
                    "StochasticDepth": StochasticDepth
                }
            )` > The LayerScale layer is not exposed using @keras_export in https://github.com/keras-team/keras/blob/b80dd12da9c0bc3f569eca3455e77762cf2ee8ef/keras/applications/convnext.py#L199 A work around this error would be to copy the custom layers LayerScale and also StochasticDepth to a local script and import them, and then to load the model as follows:
> 
> `best_model = models.load_model( <path_to_checkpoint>, compile=False, custom_objects={ "LayerScale": LayerScale, "StochasticDepth": StochasticDepth } )`

i did this and it is working well. Thanks baniks! Loading VIT model in keras error coming 

[ValueError: Unknown layer: 'ClassToken'. Please ensure you are using a `keras.utils.custom_object_scope` and that this object is included in the scope. See ](https://www.tensorflow.org/guide/keras/save_and_serialize%3C/span%3E%3Cspan)https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details. > The LayerScale layer is not exposed using @keras_export in https://github.com/keras-team/keras/blob/b80dd12da9c0bc3f569eca3455e77762cf2ee8ef/keras/applications/convnext.py#L199 A work around this error would be to copy the custom layers LayerScale and also StochasticDepth to a local script and import them, and then to load the model as follows:
> 
> `best_model = models.load_model( <path_to_checkpoint>, compile=False, custom_objects={ "LayerScale": LayerScale, "StochasticDepth": StochasticDepth } )`


This solution by @baniks  works perfectly!
<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Bug

### Have you reproduced the bug with TF nightly?

Yes

### Source

source

### Tensorflow Version

2.11

### Custom Code

Yes

### OS Platform and Distribution

Linux Ubuntu

### Mobile device

_No response_

### Python version

_No response_

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

Nvidia A100

### Current Behaviour?

```shell
Can't load tensorflow saved model (.h5) for Convnext model ..
```


### Standalone code to reproduce the issue

```shell
model download link - https://easyupload.io/mn1i8h
```


### Relevant log output

```shell
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[13], line 47
     43 models=["EfficientNetv2L_avg.h5",
     44         "convnext_tiny_avg.h5","convnext_Large_avg.h5"]
     46 for model in models:
---> 47     _f1_score=evaluate_f1_for_tf_model(model_path=model,validation_dataset=sub_sample_validation_dataset,y_true=y_true)
     48     print(f"f1 score of the {model} is {_f1_score}")

Cell In[13], line 23, in evaluate_f1_for_tf_model(model_path, validation_dataset, y_true, show_confusion_report)
     21 # Wrap the loaded model inside the strategy scope to distribute it across the GPUs
     22 with strategy.scope():
---> 23     model = tf.keras.models.load_model(model_path)
     25 #show model arch
     26 print(model.summary())

File /gpfslocalsup/pub/anaconda-py3/2022.05/envs/tensorflow-gpu-2.11.0+py3.10.8/lib/python3.10/site-packages/keras/utils/traceback_utils.py:70, in filter_traceback.<locals>.error_handler(*args, **kwargs)
     67     filtered_tb = _process_traceback_frames(e.__traceback__)
     68     # To get the full stack trace, call:
     69     # `tf.debugging.disable_traceback_filtering()`
---> 70     raise e.with_traceback(filtered_tb) from None
     71 finally:
     72     del filtered_tb

File /gpfslocalsup/pub/anaconda-py3/2022.05/envs/tensorflow-gpu-2.11.0+py3.10.8/lib/python3.10/site-packages/keras/saving/legacy/serialization.py:385, in class_and_config_for_serialized_keras_object(config, module_objects, custom_objects, printable_module_name)
    381 cls = object_registration.get_registered_object(
    382     class_name, custom_objects, module_objects
    383 )
    384 if cls is None:
--> 385     raise ValueError(
    386         f"Unknown {printable_module_name}: '{class_name}'. "
    387         "Please ensure you are using a `keras.utils.custom_object_scope` "
    388         "and that this object is included in the scope. See "
    389         "https://www.tensorflow.org/guide/keras/save_and_serialize"
    390         "#registering_the_custom_object for details."
    391     )
    393 cls_config = config["config"]
    394 # Check if `cls_config` is a list. If it is a list, return the class and the
    395 # associated class configs for recursively deserialization. This case will
    396 # happen on the old version of sequential model (e.g. `keras_version` ==
    397 # "2.0.6"), which is serialized in a different structure, for example
    398 # "{'class_name': 'Sequential',
    399 #   'config': [{'class_name': 'Embedding', 'config': ...}, {}, ...]}".

ValueError: Unknown layer: 'LayerScale'. Please ensure you are using a `keras.utils.custom_object_scope` and that this object is included in the scope. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.
```
</details>