ultralytics / yolov5

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

val.py starts multiple processes when called from Python script #6025

Closed Denbergvanthijs closed 2 years ago

Denbergvanthijs commented 2 years ago

Search before asking

YOLOv5 Component

Validation

Bug

First of all, thank you for YOLOv5!

My repository has the following structure:

Within my_script.py I have the following code:

from yolov5 import val

results, _, timings = val.run(data="./data/rs19_person.yaml",
                              weights=["yolov5n.pt"],
                              batch_size=1,
                              task="val",
                              workers=1,
                              single_cls=True)

Sadly, this code will start 8 processes and my computer gets stuck. However changing data="./data/rs19_person.yaml" to data="./yolov5/coco128.yaml" does work and will not start 8 processes.

The logs show the following and then my computer freezes and I have to force-close the console. YOLOv5 v6.0-150-g361705d torch 1.10.0+cu113 CUDA:0 (NVIDIA GeForce GTX 1050, 2048MiB) Fusing layers... Model Summary: 213 layers, 1867405 parameters, 0 gradients val: Scanning 'data\rs19_person\labels\val' images and labels...: 0%| | 0/21 [00:00

Environment

  • YOLOv5 v6.0-150-g361705d torch 1.10.0+cu113 CUDA:0 (NVIDIA GeForce GTX 1050, 2048MiB)
  • OS: Windows 10
  • Python 3.9.9

Minimal Reproducible Example

A folder with the following files and folders inside:

  • yolov5/
  • data/rs19_person.yaml
  • my_script.py

A file my_script.py with the following code:

from yolov5 import val

results, _, timings = val.run(data="./data/rs19_person.yaml",
                              weights=["yolov5n.pt"],
                              batch_size=1,
                              task="val",
                              workers=1,
                              single_cls=True)

The yaml contains the following:

path: ./data/rs19_person # Dataset root dir
train: images/train # Train images
val: images/val # Val images
test: images/test # Test images

# Classes
nc: 1 # Number of classes
names: ["person"] # Class names

Additional

I understand that val.py is just a basic script and not meant for production, it does however serve my needs and I would really like to use it. Thank you very much for your time!

P.S. the whole repository can be found at https://github.com/Denbergvanthijs/railsem19_yolov5 This is a W.I.P. still though.

Are you willing to submit a PR?

  • [X] Yes I'd like to help by submitting a PR!
github-actions[bot] commented 2 years ago

👋 Hello @Denbergvanthijs, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python>=3.6.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

$ git clone https://github.com/ultralytics/yolov5
$ cd yolov5
$ pip install -r requirements.txt

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

glenn-jocher commented 2 years ago

@Denbergvanthijs 👋 hi, thanks for letting us know about this possible problem with YOLOv5 🚀. We've created a few short guidelines below to help users provide what we need in order to get started investigating a possible problem.

How to create a Minimal, Reproducible Example

When asking a question, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This is referred to by community members as creating a minimum reproducible example. Your code that reproduces the problem should be:

For Ultralytics to provide assistance your code should also be:

If you believe your problem meets all the above criteria, please close this issue and raise a new one using the 🐛 Bug Report template with a minimum reproducible example to help us better understand and diagnose your problem.

Thank you! 😃

Denbergvanthijs commented 2 years ago

Hi @glenn-jocher , is the code I have provided minimal and reproducible enough for you? What can I do to make it better?

glenn-jocher commented 2 years ago

@Denbergvanthijs val.py operates correctly for me. If we can't reproduce an error on our side the issue is non-actionable.

Screen Shot 2021-12-17 at 5 16 55 PM
Denbergvanthijs commented 2 years ago

Sorry if I was unclear, the coco128.yaml does indeed work for me. The problem is that it doesn't work on my custom dataset.

I'm in doubt if my custom dataset is incorrect because when I run python ./yolov5/val.py --data "./data/rs19_person.yaml" --weights "yolov5n.pt" --batch-size 1 --task val --workers 1 --single-cls it does work. The same goes for training from the command line, that also works for my custom dataset

glenn-jocher commented 2 years ago

@Denbergvanthijs if you can demonstrate an issue using any of the autodownload datasets (i.e. COCO, COCO128, VOC, etc.) then please let us know, thanks!

https://github.com/ultralytics/yolov5/tree/master/data

Denbergvanthijs commented 2 years ago

I will give it a go, thank you for your fast responses!

Denbergvanthijs commented 2 years ago

I have been able to solve my problem by adding if __name__ == "__main__": to the script. Its still strange that 8 processes start when I run my script. But for now my problem is solved. Thank you for your assistance Glenn!