ultralytics / yolov5

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

How we can run yolo on multiple inputs parallelly? #10198

Closed Curious404 closed 1 year ago

Curious404 commented 1 year ago

Search before asking

Question

I have multiple data for the input. I wanted to perform object detection on multiple inputs and process them parallelly instead of one by one.

Additional

Example: 3 inputs fed => showing All 3s output window simultaneously which having object detection.

github-actions[bot] commented 1 year ago

👋 Hello @Curious404, 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 support@ultralytics.com.

Requirements

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

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

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

YOLOv5 CI

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

MartinPedersenpp commented 1 year ago

https://github.com/ultralytics/yolov5/blob/ff6e6e328efe43547bc57d4e02ae8ddc3387ef58/detect.py#L98-L110

Not tested, but if you increase the batch size and feed detect.py with an array of images It might do the trick? If you use TorchHub I think you need to use the torch dataloader or create your own?

Hope this helps

Curious404 commented 1 year ago

@MartinPedersenpp I think your are increasing the batch size only. I am asking about direct "3" separate inputs to the model.

MartinPedersenpp commented 1 year ago

@MartinPedersenpp I think your are increasing the batch size only. I am asking about direct "3" separate inputs to the model.

Yes that was my thought. if you put your 3 inputs in to a dataloader with batch size 3, would that not feed all three images to your model? Again not tested, but that is how I have used dataloaders in the past

Curious404 commented 1 year ago

And what commandl line do you pass? Because it is giving anerror.

MartinPedersenpp commented 1 year ago

Well the dataloader accepts lists or tuples, so I would assume that [img1_path, img2_path, img3_path] would work, but again, you might have to tweak some code if you get errors.

github-actions[bot] commented 1 year 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 ⭐!

glenn-jocher commented 11 months ago

@MartinPedersenpp is correct. You can input multiple images by passing their file paths as a list to the --source argument in the detect.py script. For example, python detect.py --source ['img1.jpg', 'img2.jpg', 'img3.jpg']. If you encounter any errors, feel free to refer to our documentation for further assistance.

vano-vega commented 5 months ago

@MartinPedersenpp I think your are increasing the batch size only. I am asking about direct "3" separate inputs to the model.

Did you find any solution for this parallel input issue?

Jeong-m1n commented 2 months ago

@glenn-jocher

Hi, I am trying to put multi video to yolo model and I tried this method. results=model.track(source_list, persist=True, device= torch.device('cuda'), tracker ="bytetrack.yaml", conf=0.6) Then, I got seperate result for each video but YOLOv8 tracking model assign same ID to different objects.

image 5 inputs (elements of source_list) are from one original frame, cropped image by frame[x1:x2, y1:y2] to put only ROI as input of yolo.

And strange thing is only one output shows ID with detected results(class and confidence) and others show only bounding box. image

Can you tell me what cause this problem?

glenn-jocher commented 2 months ago

Hi @Jeong-m1n,

Thank you for reaching out with your issue. It seems like you're encountering a problem with the YOLOv8 tracking model assigning the same ID to different objects when processing multiple videos or cropped regions of interest (ROIs) from a single frame.

Here are a few suggestions to help you troubleshoot and potentially resolve this issue:

  1. Verify Latest Versions: Ensure you are using the latest versions of YOLOv5/YOLOv8 and all dependencies. Sometimes, bugs are fixed in newer releases.

  2. Separate Tracking Contexts: When processing multiple inputs, especially cropped ROIs from a single frame, it's crucial to maintain separate tracking contexts for each input. This can help avoid ID conflicts. You might need to instantiate separate tracker objects for each input.

  3. Check Tracker Configuration: Ensure that your tracker configuration (e.g., bytetrack.yaml) is correctly set up for handling multiple inputs. Sometimes, tweaking the tracker parameters can help resolve ID assignment issues.

  4. Batch Processing: If you are processing multiple inputs in a batch, ensure that the batch processing logic correctly handles the tracking IDs. You might need to modify the code to ensure that IDs are unique across different inputs.

  5. Debugging: Add debugging statements to check the intermediate outputs and ensure that the tracking IDs are being assigned correctly at each step. This can help identify where the IDs are getting mixed up.

Here is an example of how you might modify your code to handle separate tracking contexts:

results = []
for source in source_list:
    result = model.track(source, persist=True, device=torch.device('cuda'), 
                         tracker="bytetrack.yaml", conf=0.6)
    results.append(result)

This approach ensures that each input is processed independently, which might help resolve the ID conflict issue.

If the issue persists, please provide more details about your setup and any error messages you encounter. This will help us better understand the problem and provide more specific guidance.

Feel free to check out our documentation for additional resources and examples.