admin管理员组文章数量:1355604
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,)
yolopile(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
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,)
yolopile(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
Share Improve this question asked Mar 28 at 8:17 PulfPulf 133 bronze badges1 Answer
Reset to default 0This error happens as Keras doesn't recognise the YOLOV8Detector class. The issue is that you're saving the entire detector model but load it as a backbone.
Try this load with custo object
# Save the entire detector
checkpoint_filepath = 'E:/model.yolo_v8_s_ft.keras'
yolo.save(checkpoint_filepath)
# Later, load with custom objects
from keras_cv.models.object_detection.yolo_v8 import YOLOV8Detector
loaded_model = keras.models.load_model(
checkpoint_filepath,
custom_objects={'YOLOV8Detector': YOLOV8Detector}
)
本文标签: pythoncan39t load the saved model YOLOV8Backbone from kerascv after thefinetuningStack Overflow
版权声明:本文标题:python - can't load the saved model YOLOV8Backbone from keras_cv after thefine-tuning - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744049045a2582079.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论