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

Number of detections #8357

Closed jayley007 closed 2 years ago

jayley007 commented 2 years ago

Search before asking

Question

I have used YOLOv5 for the detection of these barcodes. However, I was wondering whether if it’s possible to calculate the number of the barcodes that has to be detected prior to the detection which might requires me to annotate the entire disk individually (in this pic it’s 16)

Then I multiply 16x3 = 48 barcodes After the detections, the model will check whether the number of detection = the counted value which allows me to sort them into 2 different folders (pass and fail)

Additional

No response

github-actions[bot] commented 2 years ago

πŸ‘‹ Hello @jayley007, 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

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

@jayley007 πŸ‘‹ Hello! Thanks for asking about handling inference results. YOLOv5 πŸš€ PyTorch Hub models allow for simple model loading and inference in a pure python environment without using detect.py.

Simple Inference Example

This example loads a pretrained YOLOv5s model from PyTorch Hub as model and passes an image for inference. 'yolov5s' is the YOLOv5 'small' model. For details on all available models please see the README. Custom models can also be loaded, including custom trained PyTorch models and their exported variants, i.e. ONNX, TensorRT, TensorFlow, OpenVINO YOLOv5 models.

import torch

# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')  # yolov5n - yolov5x6 official model
#                                            'custom', 'path/to/best.pt')  # custom model

# Images
im = 'https://ultralytics.com/images/zidane.jpg'  # or file, Path, URL, PIL, OpenCV, numpy, list

# Inference
results = model(im)

# Results
results.print()  # or .show(), .save(), .crop(), .pandas(), etc.
results.xyxy[0]  # im predictions (tensor)

results.pandas().xyxy[0]  # im predictions (pandas)
#      xmin    ymin    xmax   ymax  confidence  class    name
# 0  749.50   43.50  1148.0  704.5    0.874023      0  person
# 2  114.75  195.75  1095.0  708.0    0.624512      0  person
# 3  986.00  304.00  1028.0  420.0    0.286865     27     tie

results.pandas().xyxy[0].value_counts('name')  # class counts (pandas)
# person    2
# tie       1

See YOLOv5 PyTorch Hub Tutorial for details.

Good luck πŸ€ and let us know if you have any other questions!

jayley007 commented 2 years ago

Thank you for the reply. But, how can I load my own model using torch.hub.load ? Thanks

glenn-jocher commented 2 years ago

Your question is already answered above.

Screenshot 2022-06-28 at 11 24 38
jayley007 commented 2 years ago

@glenn-jocher Sorry i overlooked. But is there any parameters that i should set as the result of the image that was tested appeared to be darker compared to the ones tested using detect.py?

glenn-jocher commented 2 years ago

@jayley007 See https://docs.ultralytics.com/yolov5/tutorials/pytorch_hub_model_loading for details.

jayley007 commented 2 years ago

Thanks, im progressing well. However, I want to change the location where it saves the output. Where should I change? As im looping my dataset, so it keeps saving in different folder ''exp, exp1, exp2, exp3, ... ''

glenn-jocher commented 2 years ago

see .save() method arguments

jayley007 commented 2 years ago

sorry, can you elaborate?

glenn-jocher commented 2 years ago

@jayley007 https://github.com/ultralytics/yolov5/blob/6935a54e603d634f6b0a9026604dc5875d1ca990/models/common.py#L689-L692

jayley007 commented 2 years ago

@glenn-jocher May I know what are the main issues that lead to wrong detections with conf_threshold above 0.5. From what I see, the wrong detection doesnt resemble the object at all (some even just blank background)

glenn-jocher commented 2 years ago

@jayley007 πŸ‘‹ Hello! Thanks for asking about improving YOLOv5 πŸš€ training results.

Most of the time good results can be obtained with no changes to the models or training settings, provided your dataset is sufficiently large and well labelled. If at first you don't get good results, there are steps you might be able to take to improve, but we always recommend users first train with all default settings before considering any changes. This helps establish a performance baseline and spot areas for improvement.

If you have questions about your training results we recommend you provide the maximum amount of information possible if you expect a helpful response, including results plots (train losses, val losses, P, R, mAP), PR curve, confusion matrix, training mosaics, test results and dataset statistics images such as labels.png. All of these are located in your project/name directory, typically yolov5/runs/train/exp.

We've put together a full guide for users looking to get the best results on their YOLOv5 trainings below.

Dataset

COCO Analysis

Model Selection

Larger models like YOLOv5x and YOLOv5x6 will produce better results in nearly all cases, but have more parameters, require more CUDA memory to train, and are slower to run. For mobile deployments we recommend YOLOv5s/m, for cloud deployments we recommend YOLOv5l/x. See our README table for a full comparison of all models.

YOLOv5 Models

Training Settings

Before modifying anything, first train with default settings to establish a performance baseline. A full list of train.py settings can be found in the train.py argparser.

Further Reading

If you'd like to know more a good place to start is Karpathy's 'Recipe for Training Neural Networks', which has great ideas for training that apply broadly across all ML domains: http://karpathy.github.io/2019/04/25/recipe/

Good luck πŸ€ and let us know if you have any other questions!

jayley007 commented 2 years ago

Thank you for the tips. Is it possible to see the detected images for validation set like the ones in detect.py? which part of the code should i extract?

glenn-jocher commented 2 years ago

@jayley007 val.py produces a number of output plots and images when run by default. These are all saved to runs/val/exp.

python val.py --data coco128.yaml --weights yolov5s.pt
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 ⭐!