[Python] can't load the saved model YOLOV8Backbone from keras_cv after thefine-tuning

Discussão em 'Python' iniciado por Stack, Março 28, 2025.

  1. Stack

    Stack Membro Participativo

    checkpoint_filepath='E:\model.yolo_v8_s_ft.h5'
    # backbone = keras_cv.models.YOLOV8Backbone.from_preset("yolo_v8_m_backbone_coco")
    backbone = keras.models.load_model(checkpoint_filepath)

    yolo = keras_cv.models.YOLOV8Detector(
    num_classes=len(class_mapping),
    bounding_box_format="xyxy",
    backbone=backbone,
    fpn_depth=2,)
    optimizer = tf.keras.optimizers.Adam(learning_rate=LEARNING_RATE,global_clipnorm=GLOBAL_CLIPNORM,)
    yolo.compile(optimizer=optimizer, classification_loss="binary_crossentropy", box_loss="ciou")


    Save_mode= keras.callbacks.ModelCheckpoint(filepath=checkpoint_filepath,monitor='val_loss',mode='auto',save_best_only=True,save_freq="epoch")
    reduce_lr = keras.callbacks.ReduceLROnPlateau(monitor='val_loss', factor=0.5,patience=3, min_lr=0.0001)
    Stop=keras.callbacks.EarlyStopping(monitor="val_loss",patience=7,mode="auto")

    yolo.fit(
    train_ds,
    validation_data=val_ds,
    epochs=EPOCH,
    callbacks=[Save_mode, reduce_lr, Stop],
    )


    raise err:


    ValueError: Unknown layer: 'YOLOV8Detector'.
    ​

    try use tensorflow_hub (backbone = keras.models.load_model(checkpoint_filepath,custom_objects={'YOLOV8Detector':hub.YOLOV8Detector})) - raise err:


    AttributeError: module 'tensorflow_hub' has no attribute 'YOLOV8Detector'
    ​

    try save model as '.tf' - raise err:


    ValueError: The filepath provided must end in .keras (Keras model format). Received: filepath=E:\model.yolo_v8_s_ft.tf
    ​

    from keras.callbacks.ModelCheckpoint

    Continue reading...

Compartilhe esta Página