You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trained custom model Yolo v9-m from scratch. During inference I noticed that logger throwing messages:
WARNING ⚠ Weight Not Found for key: 19.conv yolo.py:152
WARNING ⚠ Weight Not Found for key: 21.conv3.0.conv2 yolo.py:152
WARNING ⚠ Weight Not Found for key: 34.conv3.0.conv2 yolo.py:152
WARNING ⚠ Weight Not Found for key: 38.heads.1.anchor_conv.0 yolo.py:152
WARNING ⚠ Weight Not Found for key: 22.heads.2.anc2vec
The main reasons of this warnings:
Lightning save weights as a key of file with extension .ckpt.
Keys of initialized model and trained model mismatched. Need add model.model into name of key
System Info (please complete the following ## information):
I have the same issue here for a custom YOLOv9-t model. Basically, the custom trained checkpoint won't be able to load for inference. What I've done is adjusting the create_model method in yolo.py to allow to read ckpt files. This seems to work!
defcreate_model(model_cfg: ModelConfig, weight_path: Union[bool, Path] =True, class_num: int=80) ->YOLO:
"""Constructs and returns a model from a Dictionary configuration file. Args: config_file (dict): The configuration file of the model. Returns: YOLO: An instance of the model defined by the given configuration. """OmegaConf.set_struct(model_cfg, False)
model=YOLO(model_cfg, class_num)
ifweight_path:
ifweight_path==True:
weight_path=Path("weights") /f"{model_cfg.name}.pt"elifisinstance(weight_path, str):
weight_path=Path(weight_path)
ifnotweight_path.exists():
logger.info(f"🌐 Weight {weight_path} not found, try downloading")
prepare_weight(weight_path=weight_path)
ifweight_path.exists():
ifweight_path.suffix==".ckpt":
checkpoint=torch.load(weight_path)
state_dict=checkpoint['state_dict']
# Fix the keys in the checkpointnew_state_dict= {}
forkey, valueinstate_dict.items():
ifkey.startswith("model.model."):
new_key=key.replace("model.model.", "model.", 1)
new_state_dict[new_key] =valueelse:
new_state_dict[key] =value# Load new state dictmodel.load_state_dict(new_state_dict, strict=False)
forname, paraminmodel.named_parameters():
ifnamenotinnew_state_dict:
print(f"Missing weight for layer: {name}")
logger.info(":white_check_mark: Success load model & checkpoint")
else:
model.save_load_weights(weight_path)
logger.info(":white_check_mark: Success load model & weight")
Activity
[-]Missed keys during inference[/-][+]Keys not found during inference[/+]cansik commentedon Dec 11, 2024
I have the same issue here for a custom YOLOv9-t model. Basically, the custom trained checkpoint won't be able to load for inference. What I've done is adjusting the
create_modelmethod in yolo.py to allow to read ckpt files. This seems to work!divyanidhi commentedon Mar 28, 2025
@cansik Can you please share your run command for inferencing?