TypeError: Could not locate class ‘Model’

   import tensorflow as tf
from tensorflow.keras.applications import ResNet50
from tensorflow.keras.layers import LSTM, Dense, GlobalAveragePooling2D, Dropout
from tensorflow.keras.activations import relu

class Model(tf.keras.Model):
    def __init__(self, num_classes, latent_dim=2048, lstm_layers=1, hidden_dim=2048, bidirectional=False):
        super(Model, self).__init__()
        self.base_model = tf.keras.Sequential([
            ResNet50(include_top=False, weights=None, input_shape=(None, None, 3)),
        ], name='resnet50_base')
        self.base_model.layers[0].name = 'resnet50_base'  # Set a unique name for the ResNet50 model
        self.base_model.layers[0].trainable = False  # Ensure the ResNet50 model is not trainable
        self.lstm = LSTM(hidden_dim, return_sequences=True, return_state=True, name='lstm_layer')
        self.relu = relu
        self.dp = Dropout(0.4, name='dropout_layer')
        self.linear1 = Dense(num_classes, name='output_layer')
        self.avgpool = GlobalAveragePooling2D(name='global_avg_pooling')
        self.built = True  # Mark the model as built

    def call(self, inputs):
        batch_size, seq_length, h, w, c = inputs.shape.as_list()  # TensorFlow shape order is different
        inputs = tf.reshape(inputs, (batch_size * seq_length, h, w, c))
        fmap = self.base_model(inputs)
        x = self.avgpool(fmap)
        x = tf.reshape(x, (batch_size, seq_length, -1))
        x_lstm, _, _ = self.lstm(x)
        x = tf.reduce_mean(x_lstm, axis=1)
        x = self.dp(x)
        x = self.linear1(x)
        return fmap, x


model = Model(num_classes=2)  # Binary classification with 2 classes: 'real' and 'fake'`

after training and saving it as model.save(“vedio_model.keras”), when i try to load , the model ,
it gives error loaded_model = tf.keras.models.load_model(“vedio_model.keras”)

TypeError Traceback (most recent call last)
Cell In[34], line 1
—-> 1 loaded_model = tf.keras.models.load_model(“vedio_model.keras”)

File /usr/local/lib/python3.11/dist-packages/keras/src/saving/saving_api.py:176, in load_model(filepath, custom_objects, compile, safe_mode)
173 is_keras_zip = True
175 if is_keras_zip:
–> 176 return saving_lib.load_model(
177 filepath,
178 custom_objects=custom_objects,
179 compile=compile,
180 safe_mode=safe_mode,
181 )
182 if str(filepath).endswith((“.h5”, “.hdf5”)):
183 return legacy_h5_format.load_model_from_hdf5(filepath)

File /usr/local/lib/python3.11/dist-packages/keras/src/saving/saving_lib.py:155, in load_model(filepath, custom_objects, compile, safe_mode)
153 # Construct the model from the configuration file in the archive.
154 with ObjectSharingScope():
–> 155 model = deserialize_keras_object(
156 config_dict, custom_objects, safe_mode=safe_mode
157 )
159 all_filenames = zf.namelist()
160 if _VARS_FNAME + “.h5” in all_filenames:

File /usr/local/lib/python3.11/dist-packages/keras/src/saving/serialization_lib.py:687, in deserialize_keras_object(config, custom_objects, safe_mode, **kwargs)
684 if obj is not None:
685 return obj
–> 687 cls = _retrieve_class_or_fn(
688 class_name,
689 registered_name,
690 module,
691 obj_type=”class”,
692 full_config=config,
693 custom_objects=custom_objects,
694 )
696 if isinstance(cls, types.FunctionType):
697 return cls

File /usr/local/lib/python3.11/dist-packages/keras/src/saving/serialization_lib.py:805, in _retrieve_class_or_fn(name, registered_name, module, obj_type, full_config, custom_objects)
“ 802 if obj is not None:
803 return obj
–> 805 raise TypeError(
806 f”Could not locate {obj_type} ‘{name}’. ”
807 “Make sure custom classes are decorated with ”
808 “`@keras.saving.r

``

egister_keras_serializable()`. ”
809 f”Full object config: {full_config}”
810 )

TypeError: Could not locate class ‘Model’. Make sure custom classes are decorated with @keras.saving.register_keras_serializable(). Full object config: {‘module’: None, ‘class_name’: ‘Model’, ‘config’: {‘trainable’: True, ‘dtype’: ‘float32’}, ‘registered_name’: ‘Model’}

There was no error while , training and saving. but it is e=giving error while loading

New contributor

Shivanand Garg is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật