Chris-hughes10 / Yolov7-training

A clean, modular implementation of the Yolov7 model family, which uses the official pretrained weights, with utilities for training the model on custom (non-COCO) tasks.
GNU General Public License v3.0
116 stars 35 forks source link

Once custom yolov7 trained, how can I use it into test.py and detect.py? #17

Closed dimcarien closed 1 year ago

dimcarien commented 1 year ago

Hello, Thanks for your deep dive implementation of custom yolov7 model. Just finalized the training and got best_model.pt and ema_model.pt. Then, I copy these pytorch files in the yolov7 repository I downloaded (your forked version found here: https://github.com/Chris-hughes10/yolov7) in order to use the model with detect.py. But It does not work. Please find below the script I run and the error I got. Can you help me to fix that please? Or can you tell me the steps I have to follow to use the model please?

Many thanks in advance for your helps! Have a nice day!

The script: !python detect.py --weights best_model.pt --conf 0.5 --img-size 640 --source {image_folder} --no-trace

The error:

Namespace(weights=['best_model.pt'], source='/content/gdrive/MyDrive/CookiePy/Script/yolov7/data/TestSet/images', img_size=640, conf_thres=0.5, iou_thres=0.45, device='', view_img=False, save_txt=False, save_conf=False, nosave=False, classes=None, agnostic_nms=False, augment=False, update=False, project='runs/detect', name='exp', exist_ok=False, no_trace=True)
YOLOR 🚀 55b90e1 torch 2.0.1+cu118 CPU

Traceback (most recent call last):
  File "/content/gdrive/MyDrive/CookiePy/Script/yolov7/detect.py", line 195, in <module>
    detect()
  File "/content/gdrive/MyDrive/CookiePy/Script/yolov7/detect.py", line 34, in detect
    model = attempt_load(weights, map_location=device)  # load FP32 model
  File "/content/gdrive/MyDrive/CookiePy/Script/yolov7/models/experimental.py", line 253, in attempt_load
    model.append(ckpt['ema' if ckpt.get('ema') else 'model'].float().fuse().eval())  # FP32 model
KeyError: 'model'
Chris-hughes10 commented 1 year ago

Hi,

The models in this repo are not compatible with the detect.py file from the original repo. For an example of inference, please check out this script, which evaluates on the COCO dataset