ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.47k stars 16.29k forks source link

Why has different result between val.py and detec.py by using same weight and same input image? #6895

Closed star4s closed 2 years ago

star4s commented 2 years ago

Search before asking

Question

Why has different result between val.py and detec.py by using same weight?

Both results are almost same, but sometimes are not.

By using val.py, I can detect correct class and location. However, when I use detect.py, I cannot detect class and location by using same weight.

I think that both result should be same.

each command line:

  1. python val.py --weights ./runs/train/exp3/weights/best.pt --data test.yaml --img 2352 --conf-thres 0.4 --half --task test --save-txt --save-hybrid --save-conf &

  2. python detect.py --img 2352 --conf 0.4 --iou-thres 0.6 --source ../data/Yolo_Data_run//test --weights ./runs/train/exp3/weights/best.pt --save-txt --save-conf --save-crop &

Images(jpg) and annotation(txt) pointed out by test.yaml are in the folder which is ../data/Yolo_Data_run//test.

Thank you for your attention.

Additional

No response

glenn-jocher commented 2 years ago

@star4s 👋 Hello, thanks for asking about the differences between train.py, detect.py and val.py in YOLOv5 🚀.

These 3 files are designed for different purposes and utilize different dataloaders with different settings. train.py dataloaders are designed for a speed-accuracy compromise, val.py is designed to obtain the best mAP on a validation dataset, and detect.py is designed for best real-world inference results. A few important aspects of each:

train.py

val.py

detect.py

YOLOv5 PyTorch Hub Inference

YOLOv5 PyTorch Hub models areAutoShape() instances used for image loading, preprocessing, inference and NMS. For more info see YOLOv5 PyTorch Hub Tutorial https://github.com/ultralytics/yolov5/blob/7ee5aed0b3fa6a805afb0a820c40bbcbf29960de/models/common.py#L276-L282

Good luck 🍀 and let us know if you have any other questions!

github-actions[bot] commented 2 years ago

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 🚀 resources:

Access additional Ultralytics ⚡ resources:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐!