I just tried your method and found the generated .keras file cannot be loaded properly
ValueError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/keras/src/ops/operation.py in from_config(cls, config)
233 try:
ā 234 return cls(**config)
235 except Exception as e:
13 frames
/usr/local/lib/python3.10/dist-packages/keras/src/layers/convolutional/conv2d.py in init(self, filters, kernel_size, strides, padding, data_format, dilation_rate, groups, activation, use_bias, kernel_initializer, bias_initializer, kernel_regularizer, bias_regularizer, activity_regularizer, kernel_constraint, bias_constraint, **kwargs)
108 ):
ā 109 super().init(
110 rank=2,
/usr/local/lib/python3.10/dist-packages/keras/src/layers/convolutional/base_conv.py in init(self, rank, filters, kernel_size, strides, padding, data_format, dilation_rate, groups, activation, use_bias, kernel_initializer, bias_initializer, kernel_regularizer, bias_regularizer, activity_regularizer, kernel_constraint, bias_constraint, lora_rank, **kwargs)
106 ):
ā 107 super().init(activity_regularizer=activity_regularizer, **kwargs)
108 self.rank = rank
/usr/local/lib/python3.10/dist-packages/keras/src/layers/layer.py in init(self, activity_regularizer, trainable, dtype, autocast, name, **kwargs)
265 if kwargs:
ā 266 raise ValueError(
267 "Unrecognized keyword arguments "
ValueError: Unrecognized keyword arguments passed to Conv2D: {ābatch_input_shapeā: [None, 150, 150, 3]}
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/keras/src/saving/serialization_lib.py in deserialize_keras_object(config, custom_objects, safe_mode, **kwargs)
717 try:
ā 718 instance = cls.from_config(inner_config)
719 except TypeError as e:
/usr/local/lib/python3.10/dist-packages/keras/src/ops/operation.py in from_config(cls, config)
235 except Exception as e:
ā 236 raise TypeError(
237 f"Error when deserializing class ā{cls.name}ā using "
TypeError: Error when deserializing class āConv2Dā using config={ānameā: āconv2d_20ā, ātrainableā: True, ādtypeā: āfloat32ā, ābatch_input_shapeā: [None, 150, 150, 3], āfiltersā: 32, ākernel_sizeā: [3, 3], āstridesā: [1, 1], āpaddingā: āvalidā, ādata_formatā: āchannels_lastā, ādilation_rateā: [1, 1], āgroupsā: 1, āactivationā: āreluā, āuse_biasā: True, ākernel_initializerā: {āmoduleā: ākeras.initializersā, āclass_nameā: āGlorotUniformā, āconfigā: {āseedā: None}, āregistered_nameā: None}, ābias_initializerā: {āmoduleā: ākeras.initializersā, āclass_nameā: āZerosā, āconfigā: {}, āregistered_nameā: None}, ākernel_regularizerā: None, ābias_regularizerā: None, āactivity_regularizerā: None, ākernel_constraintā: None, ābias_constraintā: None}.
Exception encountered: Unrecognized keyword arguments passed to Conv2D: {ābatch_input_shapeā: [None, 150, 150, 3]}
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/keras/src/saving/serialization_lib.py in deserialize_keras_object(config, custom_objects, safe_mode, **kwargs)
717 try:
ā 718 instance = cls.from_config(inner_config)
719 except TypeError as e:
/usr/local/lib/python3.10/dist-packages/keras/src/models/sequential.py in from_config(cls, config, custom_objects)
346 else:
ā 347 layer = serialization_lib.deserialize_keras_object(
348 layer_config,
/usr/local/lib/python3.10/dist-packages/keras/src/saving/serialization_lib.py in deserialize_keras_object(config, custom_objects, safe_mode, **kwargs)
719 except TypeError as e:
ā 720 raise TypeError(
721 f"{cls} could not be deserialized properly. Please"
TypeError: <class ākeras.src.layers.convolutional.conv2d.Conv2Dā> could not be deserialized properly. Please ensure that components that are Python object instances (layers, models, etc.) returned by get_config()
are explicitly deserialized in the modelās from_config()
method.
config={āmoduleā: ākeras.layersā, āclass_nameā: āConv2Dā, āconfigā: {ānameā: āconv2d_20ā, ātrainableā: True, ādtypeā: āfloat32ā, ābatch_input_shapeā: [None, 150, 150, 3], āfiltersā: 32, ākernel_sizeā: [3, 3], āstridesā: [1, 1], āpaddingā: āvalidā, ādata_formatā: āchannels_lastā, ādilation_rateā: [1, 1], āgroupsā: 1, āactivationā: āreluā, āuse_biasā: True, ākernel_initializerā: {āmoduleā: ākeras.initializersā, āclass_nameā: āGlorotUniformā, āconfigā: {āseedā: None}, āregistered_nameā: None}, ābias_initializerā: {āmoduleā: ākeras.initializersā, āclass_nameā: āZerosā, āconfigā: {}, āregistered_nameā: None}, ākernel_regularizerā: None, ābias_regularizerā: None, āactivity_regularizerā: None, ākernel_constraintā: None, ābias_constraintā: None}, āregistered_nameā: None, ābuild_configā: {āinput_shapeā: [None, 150, 150, 3]}}.
Exception encountered: Error when deserializing class āConv2Dā using config={ānameā: āconv2d_20ā, ātrainableā: True, ādtypeā: āfloat32ā, ābatch_input_shapeā: [None, 150, 150, 3], āfiltersā: 32, ākernel_sizeā: [3, 3], āstridesā: [1, 1], āpaddingā: āvalidā, ādata_formatā: āchannels_lastā, ādilation_rateā: [1, 1], āgroupsā: 1, āactivationā: āreluā, āuse_biasā: True, ākernel_initializerā: {āmoduleā: ākeras.initializersā, āclass_nameā: āGlorotUniformā, āconfigā: {āseedā: None}, āregistered_nameā: None}, ābias_initializerā: {āmoduleā: ākeras.initializersā, āclass_nameā: āZerosā, āconfigā: {}, āregistered_nameā: None}, ākernel_regularizerā: None, ābias_regularizerā: None, āactivity_regularizerā: None, ākernel_constraintā: None, ābias_constraintā: None}.
Exception encountered: Unrecognized keyword arguments passed to Conv2D: {ābatch_input_shapeā: [None, 150, 150, 3]}
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
in <cell line: 4>()
2
3 imbalanced_history = pd.read_csv(āhistory-imbalanced/history-imbalanced.csvā)
----> 4 imbalanced_model = tf.keras.models.load_model(āmodel-imbalanced.kerasā)
/usr/local/lib/python3.10/dist-packages/keras/src/saving/saving_api.py in load_model(filepath, custom_objects, compile, safe_mode)
180
181 if is_keras_zip or is_keras_dir:
ā 182 return saving_lib.load_model(
183 filepath,
184 custom_objects=custom_objects,
/usr/local/lib/python3.10/dist-packages/keras/src/saving/saving_lib.py in load_model(filepath, custom_objects, compile, safe_mode)
235 )
236 with open(filepath, ārbā) as f:
ā 237 return _load_model_from_fileobj(
238 f, custom_objects, compile, safe_mode
239 )
/usr/local/lib/python3.10/dist-packages/keras/src/saving/saving_lib.py in _load_model_from_fileobj(fileobj, custom_objects, compile, safe_mode)
312 config_json = f.read()
313
ā 314 model = _model_from_config(
315 config_json, custom_objects, compile, safe_mode
316 )
/usr/local/lib/python3.10/dist-packages/keras/src/saving/saving_lib.py in _model_from_config(config_json, custom_objects, compile, safe_mode)
301 # Construct the model from the configuration file in the archive.
302 with ObjectSharingScope():
ā 303 model = deserialize_keras_object(
304 config_dict, custom_objects, safe_mode=safe_mode
305 )
/usr/local/lib/python3.10/dist-packages/keras/src/saving/serialization_lib.py in deserialize_keras_object(config, custom_objects, safe_mode, **kwargs)
718 instance = cls.from_config(inner_config)
719 except TypeError as e:
ā 720 raise TypeError(
721 f"{cls} could not be deserialized properly. Please"
722 " ensure that components that are Python object"
TypeError: <class ākeras.src.models.sequential.Sequentialā> could not be deserialized properly. Please ensure that components that are Python object instances (layers, models, etc.) returned by get_config()
are explicitly deserialized in the modelās from_config()
method.
config={āmoduleā: ākerasā, āclass_nameā: āSequentialā, āconfigā: {ānameā: āsequential_5ā, ālayersā: [{āmoduleā: ākeras.layersā, āclass_nameā: āInputLayerā, āconfigā: {ābatch_input_shapeā: [None, 150, 150, 3], ādtypeā: āfloat32ā, āsparseā: False, āraggedā: False, ānameā: āconv2d_20_inputā}, āregistered_nameā: None}, {āmoduleā: ākeras.layersā, āclass_nameā: āConv2Dā, āconfigā: {ānameā: āconv2d_20ā, ātrainableā: True, ādtypeā: āfloat32ā, ābatch_input_shapeā: [None, 150, 150, 3], āfiltersā: 32, ākernel_sizeā: [3, 3], āstridesā: [1, 1], āpaddingā: āvalidā, ādata_formatā: āchannels_lastā, ādilation_rateā: [1, 1], āgroupsā: 1, āactivationā: āreluā, āuse_biasā: True, ākernel_initializerā: {āmoduleā: ākeras.initializersā, āclass_nameā: āGlorotUniformā, āconfigā: {āseedā: None}, āregistered_nameā: None}, ābias_initializerā: {āmoduleā: ākeras.initializersā, āclass_nameā: āZerosā, āconfigā: {}, āregistered_nameā: None}, ākernel_regularizerā: None, ābias_regularizerā: None, āactivity_regularizerā: None, ākernel_constraintā: None, ābias_constraintā: None}, āregistered_nameā: None, ābuild_configā: {āinput_shapeā: [None, 150, 150, 3]}}, {āmoduleā: ākeras.layersā, āclass_nameā: āMaxPooling2Dā, āconfigā: {ānameā: āmax_pooling2d_20ā, ātrainableā: True, ādtypeā: āfloat32ā, āpool_sizeā: [2, 2], āpaddingā: āvalidā, āstridesā: [2, 2], ādata_formatā: āchannels_lastā}, āregistered_nameā: None}, {āmoduleā: ākeras.layersā, āclass_nameā: āConv2Dā, āconfigā: {ānameā: āconv2d_21ā, ātrainableā: True, 'dā¦
Exception encountered: <class ākeras.src.layers.convolutional.conv2d.Conv2Dā> could not be deserialized properly. Please ensure that components that are Python object instances (layers, models, etc.) returned by get_config()
are explicitly deserialized in the modelās from_config()
method.
config={āmoduleā: ākeras.layersā, āclass_nameā: āConv2Dā, āconfigā: {ānameā: āconv2d_20ā, ātrainableā: True, ādtypeā: āfloat32ā, ābatch_input_shapeā: [None, 150, 150, 3], āfiltersā: 32, ākernel_sizeā: [3, 3], āstridesā: [1, 1], āpaddingā: āvalidā, ādata_formatā: āchannels_lastā, ādilation_rateā: [1, 1], āgroupsā: 1, āactivationā: āreluā, āuse_biasā: True, ākernel_initializerā: {āmoduleā: ākeras.initializersā, āclass_nameā: āGlorotUniformā, āconfigā: {āseedā: None}, āregistered_nameā: None}, ābias_initializerā: {āmoduleā: ākeras.initializersā, āclass_nameā: āZerosā, āconfigā: {}, āregistered_nameā: None}, ākernel_regularizerā: None, ābias_regularizerā: None, āactivity_regularizerā: None, ākernel_constraintā: None, ābias_constraintā: None}, āregistered_nameā: None, ābuild_configā: {āinput_shapeā: [None, 150, 150, 3]}}.
Exception encountered: Error when deserializing class āConv2Dā using config={ānameā: āconv2d_20ā, ātrainableā: True, ādtypeā: āfloat32ā, ābatch_input_shapeā: [None, 150, 150, 3], āfiltersā: 32, ākernel_sizeā: [3, 3], āstridesā: [1, 1], āpaddingā: āvalidā, ādata_formatā: āchannels_lastā, ādilation_rateā: [1, 1], āgroupsā: 1, āactivationā: āreluā, āuse_biasā: True, ākernel_initializerā: {āmoduleā: ākeras.initializersā, āclass_nameā: āGlorotUniformā, āconfigā: {āseedā: None}, āregistered_nameā: None}, ābias_initializerā: {āmoduleā: ākeras.initializersā, āclass_nameā: āZerosā, āconfigā: {}, āregistered_nameā: None}, ākernel_regularizerā: None, ābias_regularizerā: None, āactivity_regularizerā: None, ākernel_constraintā: None, ābias_constraintā: None}.
Exception encountered: Unrecognized keyword arguments passed to Conv2D: {ābatch_input_shapeā: [None, 150, 150, 3]}