YoloV5 implemented by TensorFlow2 , with support for training, evaluation and inference.

Overview

Yolov5

LICENSE

YoloV5 implemented by TensorFlow2 , with support for training, evaluation and inference.

NOT perfect project currently, but I will continue to improve this, so you might want to watch/star this repo to revisit. Any contribution is highly welcomed

demo

Key Features

  • minimal Yolov5 by pure tensorflow2
  • yaml file to configure the model
  • custom data training
  • mosaic data augmentation
  • label encoding by iou or wh ratio of anchor
  • positive sample augment
  • multi-gpu training
  • detailed code comments
  • full of drawbacks with huge space to improve

Usage

Clone and install requirements

$ git clone [email protected]:LongxingTan/Yolov5.git
$ cd Yolov5/
$ pip install -r requirements.txt

Download VOC

$ bash data/scripts/get_voc.sh
$ cd yolo
$ python dataset/prepare_data.py

Train

$ python train.py

Inference

$ python detect.py
$ python test.py

Train on custom data

If you want to train on custom dataset, PLEASE note the input data should like this:

image_dir/001.jpg x_min, y_min, x_max, y_max, class_id x_min2, y_min2, x_max2, y_max2, class_id2

And maybe new anchor need to be created, don't forget to change the nc(number classes) in yolo-yaml.

$ python dataset/create_anchor.py

References and Further Reading

Comments
  • fixed iou calculation mistake, this will fix the Nan loss issue

    fixed iou calculation mistake, this will fix the Nan loss issue

    This PR addresses a mistake made in the iou calculation. The original method of calculating intersection will lead to incorrect iou value.

    For example, considering two boxes that do not overlap each other in [x1, y1, x2, y2] format: [0, 0, 10, 10] and [20, 20, 30, 30]: using the original formula: inter = (min(10, 30) - max(0, 20)) * (min(10, 30) - max(0, 20)) = 100. However, it's clear that the intersection of [0, 0, 10, 10] and [20, 20, 30, 30] should be 0.

    I believe the loss implementation uses the official Pytorch implementation as reference, from the intersection calculation of official implementation, you can see the correct way of calculating intersection:

    inter = (torch.min(b1_x2, b2_x2) - torch.max(b1_x1, b2_x1)).clamp(0) * \
                (torch.min(b1_y2, b2_y2) - torch.max(b1_y1, b2_y1)).clamp(0)
    

    This PR will make sure intersection calculation is the same as the official implementation, and will fix the #2

    opened by vbvg2008 2
  • prepare_data.py doesn't contain parse_xml method

    prepare_data.py doesn't contain parse_xml method

    In the prepare_data.py line 151 we are calling VOCParser.parse_xml but there is no method parse_xml in the VOCParser class. I think it should be called the method parse in VOCParser class should be called here. I checked it by replacing with parse method and its working good.

    opened by gshashank84 1
  • Bump pyyaml from 5.3.1 to 5.4

    Bump pyyaml from 5.3.1 to 5.4

    Bumps pyyaml from 5.3.1 to 5.4.

    Changelog

    Sourced from pyyaml's changelog.

    5.4 (2021-01-19)

    Commits
    • 58d0cb7 5.4 release
    • a60f7a1 Fix compatibility with Jython
    • ee98abd Run CI on PR base branch changes
    • ddf2033 constructor.timezone: _copy & deepcopy
    • fc914d5 Avoid repeatedly appending to yaml_implicit_resolvers
    • a001f27 Fix for CVE-2020-14343
    • fe15062 Add 3.9 to appveyor file for completeness sake
    • 1e1c7fb Add a newline character to end of pyproject.toml
    • 0b6b7d6 Start sentences and phrases for capital letters
    • c976915 Shell code improvements
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Error when importing from YoloV5

    Error when importing from YoloV5

    ❔Question

    I exported a saved_model from YoloV5 and tried to use it with this. Using detect.py with the exported model, I got the following error:

    InvalidArgumentError: cannot compute Pack as input #3(zero-based) was expected to be a float tensor but is a int32 tensor [Op:Pack] name: packed

    at the following line in detect.py pred_bbox = [tf.reshape(x, (tf.shape(x)[0], -1, tf.shape(x)[-1])) for x in pred_bbox]

    Have anyone had any success moving model from the other yolov5 to this one's?

    EDIT: I included nms within the exported model, which isn't compatible with the code here.

    question 
    opened by Lime-Cakes 0
  • Commit Test from BXT

    Commit Test from BXT

    Description

    This PR ...

    Checklist

    • [ ] Linked issues (if existing)
    • [ ] Added/modified tests
    • [ ] Used pre-commit hooks when committing to ensure that code is compliant with hooks. Install hooks with pre-commit install. To run hooks independent of commit, execute pre-commit run --all-files

    Make sure to have fun coding!

    opened by Clark1216 0
  • LICENSE?

    LICENSE?

    ❔Question

    Hello!

    Thank you for the project! I'd be happy to know, do you plan to attach some kind of LICENSE to it? MIT perhaps?

    Thank you, Ben

    Additional context

    question 
    opened by BenAsaf 0
  • [Errno 2] No such file or directory: '../data/voc2012/VOCdevkit/VOC2012/train.txt'

    [Errno 2] No such file or directory: '../data/voc2012/VOCdevkit/VOC2012/train.txt'

    when executing - ! python train.py, there's an error showing up - [Errno 2] No such file or directory: '../data/voc2012/VOCdevkit/VOC2012/train.txt'

    I tried to look for the .txt file in the given directory, but I couldn't find it. Did anyone else have this same issue?

    I also checked the read_data.py script, but I cant seem to find the directory linked to it. How to resolve this issue.

    To be clear here's the entire error:

    Traceback (most recent call last): File "/home/jovyan/Yolov5/yolo/train.py", line 153, in DataReader = DataReader(params['train_annotations_dir'], img_size=params['img_size'], transforms=transforms, File "/home/jovyan/Yolov5/yolo/dataset/read_data.py", line 21, in init self.annotations = self.load_annotations(annotations_dir) File "/home/jovyan/Yolov5/yolo/dataset/read_data.py", line 65, in load_annotations with open(annotations_dir, 'r') as f: FileNotFoundError: [Errno 2] No such file or directory: '../data/voc2012/VOCdevkit/VOC2012/train.txt'

    opened by thanujTa 2
  • Use of different yolov5 models

    Use of different yolov5 models

    ❔Question

    is it enough to change "yolo-m-mish.yaml" part, when i want to use different yolo structures (e.g yolo-s-mish.yaml or yolo-l-mish.yaml) in config.py in line: parser.add_argument('--yaml_dir', type=str, default='configs/yolo-m-mish.yaml', help='model.yaml path')

    Additional context

    question 
    opened by emingunes1 0
  • Weights for yolov5 & training loss

    Weights for yolov5 & training loss

    ❔Looking for weights for yolov5 and how to minimize training loss

    Are there existing weights which can be used ? And I have seen that you linked the weights from yolov4, do you have any advice on how to use them with this model?

    Additionally what would you consider a "good" loss ? I currently have a loss of about 200 which seems a bit high and yields results wich are not that good. How can i improve my loss ? Thank you for your help!

    question 
    opened by darkC00kie 3
  • operation in Yolov5/yolo/dataset/augment_data.py

    operation in Yolov5/yolo/dataset/augment_data.py

    In Yolov5/yolo/dataset/augment_data.py Yolov5/yolo/dataset/augment_data.py", line 103 M = T @ S @ R @ P @ C # order of operations (right to left) is IMPORTANT What operation it is doing?

    And can I save the trained model and use that for further uses.

    Thanks

    question 
    opened by ArunaKote 0
  • Can you point out the meaning of this number in label_anchor

    Can you point out the meaning of this number in label_anchor

    Thank you for the wonderful project. Can you please show what is the meaning of number 6 in this line of code?

    https://github.com/LongxingTan/Yolov5/blob/88acfd988decc4cc78335cfb6eb50f1975294c1f/yolo/dataset/label_anchor.py#L35

    opened by hieuth133 2
  • Could you provide the pre-trained weights

    Could you provide the pre-trained weights

    ❔Question

    Which is working for your code? I have been looking around the internet and couldn't find the TensorFlow(2.x) or Keras's weights or model. It would be nice you could provide it. Otherwise, there is no way to see if your repo works or not. Thanks.

    Additional context

    question 
    opened by AI-Passionner 2
Owner
A slow researcher
null
Torchserve server using a YoloV5 model running on docker with GPU and static batch inference to perform production ready inference.

Yolov5 running on TorchServe (GPU compatible) ! This is a dockerfile to run TorchServe for Yolo v5 object detection model. (TorchServe (PyTorch librar

null 82 Nov 29, 2022
🍅🍅🍅YOLOv5-Lite: lighter, faster and easier to deploy. Evolved from yolov5 and the size of model is only 1.7M (int8) and 3.3M (fp16). It can reach 10+ FPS on the Raspberry Pi 4B when the input size is 320×320~

YOLOv5-Lite:lighter, faster and easier to deploy Perform a series of ablation experiments on yolov5 to make it lighter (smaller Flops, lower memory, a

pogg 1.5k Jan 5, 2023
A Python training and inference implementation of Yolov5 helmet detection in Jetson Xavier nx and Jetson nano

yolov5-helmet-detection-python A Python implementation of Yolov5 to detect head or helmet in the wild in Jetson Xavier nx and Jetson nano. In Jetson X

null 12 Dec 5, 2022
Multi-task yolov5 with detection and segmentation based on yolov5

YOLOv5DS Multi-task yolov5 with detection and segmentation based on yolov5(branch v6.0) decoupled head anchor free segmentation head README中文 Ablation

null 150 Dec 30, 2022
TPH-YOLOv5: Improved YOLOv5 Based on Transformer Prediction Head for Object Detection on Drone-Captured Scenarios

TPH-YOLOv5 This repo is the implementation of "TPH-YOLOv5: Improved YOLOv5 Based on Transformer Prediction Head for Object Detection on Drone-Captured

cv516Buaa 439 Dec 22, 2022
Yolov5-lite - Minimal PyTorch implementation of YOLOv5

Yolov5-Lite: Minimal YOLOv5 + Deep Sort Overview This repo is a shortened versio

Kadir Nar 57 Nov 28, 2022
Bytedance Inc. 2.5k Jan 6, 2023
Yolov5 deepsort inference,使用YOLOv5+Deepsort实现车辆行人追踪和计数,代码封装成一个Detector类,更容易嵌入到自己的项目中

使用YOLOv5+Deepsort实现车辆行人追踪和计数,代码封装成一个Detector类,更容易嵌入到自己的项目中。

null 813 Dec 31, 2022
Rewrite ultralytics/yolov5 v6.0 opencv inference code based on numpy, no need to rely on pytorch

Rewrite ultralytics/yolov5 v6.0 opencv inference code based on numpy, no need to rely on pytorch; pre-processing and post-processing using numpy instead of pytroch.

炼丹去了 21 Dec 12, 2022
Custom TensorFlow2 implementations of forward and backward computation of soft-DTW algorithm in batch mode.

Batch Soft-DTW(Dynamic Time Warping) in TensorFlow2 including forward and backward computation Custom TensorFlow2 implementations of forward and backw

null 19 Aug 30, 2022
Regression Metrics Calculation Made easy for tensorflow2 and scikit-learn

Regression Metrics Installation To install the package from the PyPi repository you can execute the following command: pip install regressionmetrics I

Ashish Patel 11 Dec 16, 2022
Pointer networks Tensorflow2

Pointer networks Tensorflow2 原文:https://arxiv.org/abs/1506.03134 仅供参考与学习,内含代码备注 环境 tensorflow==2.6.0 tqdm matplotlib numpy 《pointer networks》阅读笔记 应用场景

HUANG HAO 7 Oct 27, 2022
Tf alloc - Simplication of GPU allocation for Tensorflow2

tf_alloc Simpliying GPU allocation for Tensorflow Developer: korkite (Junseo Ko)

Junseo Ko 3 Feb 10, 2022
Tensorflow2 Keras-based Semantic Segmentation Models Implementation

Tensorflow2 Keras-based Semantic Segmentation Models Implementation

Hah Min Lew 1 Feb 8, 2022
Collection of TensorFlow2 implementations of Generative Adversarial Network varieties presented in research papers.

TensorFlow2-GAN Collection of tf2.0 implementations of Generative Adversarial Network varieties presented in research papers. Model architectures will

null 41 Apr 28, 2022
Machine learning evaluation metrics, implemented in Python, R, Haskell, and MATLAB / Octave

Note: the current releases of this toolbox are a beta release, to test working with Haskell's, Python's, and R's code repositories. Metrics provides i

Ben Hamner 1.6k Dec 26, 2022
PyTorch-LIT is the Lite Inference Toolkit (LIT) for PyTorch which focuses on easy and fast inference of large models on end-devices.

PyTorch-LIT PyTorch-LIT is the Lite Inference Toolkit (LIT) for PyTorch which focuses on easy and fast inference of large models on end-devices. With

Amin Rezaei 157 Dec 11, 2022
Monocular 3D pose estimation. OpenVINO. CPU inference or iGPU (OpenCL) inference.

human-pose-estimation-3d-python-cpp RealSenseD435 (RGB) 480x640 + CPU Corei9 45 FPS (Depth is not used) 1. Run 1-1. RealSenseD435 (RGB) 480x640 + CPU

Katsuya Hyodo 8 Oct 3, 2022