tf2-keras implement yolov5

Overview

YOLOv5 in tesnorflow2.x-keras

模型测试

  • 训练 COCO2017(val 5k)

  • 检测效果

  • 精度/召回率

Requirements

pip3 install -r requirements.txt

Get start

  1. 训练
python3 train.py
  1. tensorboard
tensorboard --host 0.0.0.0 --logdir ./logs/ --port 8053 --samples_per_plugin=images=40
  1. 查看
http://127.0.0.1:8053
  1. 测试, 修改detect.py里面input_imagemodel_path
python3 detect.py

训练自己的数据

  1. labelme打标自己的数据
  2. 打开data/labelme2coco.py脚本, 修改如下地方
input_dir = '这里写labelme打标时保存json标记文件的目录'
output_dir = '这里写要转CoCo格式的目录,建议建一个空目录'
labels = "这里是你打标时所有的类别名, txt文本即可, 每行一个类, 类名无需加引号"
  1. 执行data/labelme2coco.py脚本会在output_dir生成对应的json文件和图片
  2. 修改train.py文件中coco_annotation_file以及num_class, 注意classes通过CoCoDataGenrator(*).coco.cats[label_id]['name']可获得,由于coco中类别不连续,所以通过coco.cats拿到的数组下标拿到的类别可能不准.
  3. 开始训练, python3 train.py
Comments
  • 关于类别损失计算的问题

    关于类别损失计算的问题

    您好,loss这段不是很理解, https://github.com/yyccR/yolov5_in_tf2_keras/blob/3e6645cbf94d2a1e11c33663e80113daa4590321/loss.py#L142-L152 请问targets最后两位应该是置信度1和最佳的anchor索引吗? https://github.com/yyccR/yolov5_in_tf2_keras/blob/3e6645cbf94d2a1e11c33663e80113daa4590321/loss.py#L288-L293 那这边split出来的true_obj, true_cls应该就是对应的置信度1和最佳的anchor索引吧。 那这个类别损失 https://github.com/yyccR/yolov5_in_tf2_keras/blob/3e6645cbf94d2a1e11c33663e80113daa4590321/loss.py#L356 计算的不是最佳anchor索引吗,是跟obj_mask 有关系吗

    opened by whalefa1I 5
  • sparse_categorical_crossentropy训练时有nan结果

    sparse_categorical_crossentropy训练时有nan结果

    有的数据会在这行出现nan https://github.com/yyccR/yolov5_in_tf2_keras/blob/033a1156c1481f4258bf24a4a8215af39682da94/loss.py#L357 查看了input的is_nan,都正常。而且把sparse_categorical_crossentropy换成binary_crossentropy就好了。 请问这两者在这里计算有差别吗,是否可以进行替换

    opened by whalefa1I 3
  • lebelme2coco处理逻辑有误

    lebelme2coco处理逻辑有误

    我在实际使用您的代码训练自己的数据集时发现,labelme2coco.py 好像缺少对shape_type == "rectangle"时的处理,导致我最后生成的json文件annotations项为空。 以下是labelme2coco.py文件100行到124行代码: ` if shape_type == "polygon": mask = labelme.utils.shape_to_mask( img.shape[:2], points, shape_type ) # cv2.imshow("",np.array(mask, dtype=np.uint8)*255) # cv2.waitKey(0)

                if group_id is None:
                    group_id = uuid.uuid1()
    
                instance = (label, group_id)
                # print(instance)
    
                if instance in masks:
                    masks[instance] = masks[instance] | mask
                else:
                    masks[instance] = mask
                # print(masks[instance].shape)
    
                if shape_type == "rectangle":
                    (x1, y1), (x2, y2) = points
                    x1, x2 = sorted([x1, x2])
                    y1, y2 = sorted([y1, y2])
                    points = [x1, y1, x2, y1, x2, y2, x1, y2]
                if shape_type == "circle": 
                ....
    

    ` 代码永远不会执行到shape_type == "rectangle"或shape_type == "circle"。

    opened by aijialin 2
  • layers.py

    layers.py

    根據ultralytics/yolov5:

    https://github.com/ultralytics/yolov5/blob/63ddb6f0d06f6309aa42bababd08c859197a27af/models/common.py#L70-L73

    這一段程式:

    https://github.com/yyccR/yolov5_in_tf2_keras/blob/46298d7c98073750176d64896ee9dc01b55c5aca/layers.py#L127-L132

    是不是應該改寫成:

        def call(self, inputs, *args, **kwargs):
            y = self.multiheadAttention(self.q(inputs), self.v(inputs), self.k(inputs)) + inputs
            x = self.fc1(x)
            x = self.fc2(x)
            x = x +  y
            return x
    
    opened by AugustusHsu 1
  • What is the mAP on COCO17 val ?

    What is the mAP on COCO17 val ?

    Hi @yyccR, thanks for your repo. I want to know if you can reach the same mAP as in original YOLOV5 (Train on COCO17 train and test on COCO17 val)? And do you have plan to release some pretrained checkpoint ?

    opened by Tyler-D 1
Releases(v1.1)
  • v1.1(Jun 24, 2022)

    v1.1 几个总结:

    • [1]. 调整tf.keras.layers.BatchNormalization的__call__方法中training=True
    • [2]. 新增TFLite/onnx格式导出与验证,详见/data/h5_to_tflite.py, /data/h5_to_onnx.py
    • [3]. 修改backbone网络里batch_size,在训练和测试时需指定,避免tflite导出时FlexOps问题
    • [4]. YoloHead里对类别不再做softmax,直接sigmoid,支持多类别输出
    • [5]. release里的yolov5s-best.h5为kaggle猫狗脸数据集的重新训练权重,训练:测试为8:2,val精度大概如下:

    | class | [email protected] | [email protected]:0.95 | precision | recall | | :-: | :-: | :-: | :-: | :-: | | cat | 0.962680 | 0.672483 | 0.721003 | 0.958333 | | dog | 0.934285 | 0.546893 | 0.770701 | 0.923664 | | total | 0.948482 | 0.609688 | 0.745852 | 0.940999 |

    • [6]. release里的yolov5s-best.tflite为上述yolov5s-best.h5的tflite量化模型,建议用Netron软件打开查看输入输出
    • [7]. release里的yolov5s-best.onnx为上述yolov5s-best.h5的onnx模型,建议用Netron软件打开查看输入输出
    • [8]. android 模型测试效果如下:

    就这样,继续加油!💪🏻💪🏻💪🏻

    Source code(tar.gz)
    Source code(zip)
    yolov5s-best.h5(27.51 MB)
    yolov5s-best.onnx(27.25 MB)
    yolov5s-best.tflite(6.95 MB)
  • v1.0(Jun 21, 2022)

    v1.0 几个总结:

    • [1]. 模型结构总的与 ultralytics/yolov5 v6.0 保持一致
    • [2]. 其中Conv层替换swishRelu
    • [3]. 整体数据增强与 ultralytics/yolov5 保持一致
    • [4]. readme中训练所需的数据集为kaggle公开猫狗脸检测数据集,已放到release列表中
    • [5]. 为什么不训练coco数据集?因为没资源,跑一个coco要很久的,服务器一直都有任务在跑所以没空去跑 - . -
    • [6]. release里的yolov5s-best.h5为上述kaggle猫狗脸数据集的训练权重,训练:测试为8:2,val精度大概如下:

    | class | [email protected] | [email protected]:0.95 | precision | recall | | :-: | :-: | :-: | :-: | :-: | | cat | 0.905156 | 0.584378 | 0.682848 | 0.886555 | | dog | 0.940633 | 0.513005 | 0.724036 | 0.934866 | | total | 0.922895 | 0.548692 | 0.703442 | 0.910710 |

    就这样,继续加油!💪🏻💪🏻💪🏻

    Source code(tar.gz)
    Source code(zip)
    JPEGImages.zip(260.17 MB)
    yolov5s-best.h5(27.51 MB)
Owner
yangcheng
yangcheng
Official repository for "Intriguing Properties of Vision Transformers" (2021)

Intriguing Properties of Vision Transformers Muzammal Naseer, Kanchana Ranasinghe, Salman Khan, Munawar Hayat, Fahad Shahbaz Khan, & Ming-Hsuan Yang P

Muzammal Naseer 155 Dec 27, 2022
PyTorch Implementation of SSTNs for hyperspectral image classifications from the IEEE T-GRS paper "Spectral-Spatial Transformer Network for Hyperspectral Image Classification: A FAS Framework."

PyTorch Implementation of SSTN for Hyperspectral Image Classification Paper links: SSTN published on IEEE T-GRS. Also, you can directly find the imple

Zilong Zhong 54 Dec 19, 2022
The PyTorch improved version of TPAMI 2017 paper: Face Alignment in Full Pose Range: A 3D Total Solution.

Face Alignment in Full Pose Range: A 3D Total Solution By Jianzhu Guo. [Updates] 2020.8.30: The pre-trained model and code of ECCV-20 are made public

Jianzhu Guo 3.4k Jan 02, 2023
TensorFlow-LiveLessons - "Deep Learning with TensorFlow" LiveLessons

TensorFlow-LiveLessons Note that the second edition of this video series is now available here. The second edition contains all of the content from th

Deep Learning Study Group 830 Jan 03, 2023
Pytorch implementation of DeepMind's differentiable neural computer paper.

DNC pytorch This is a Pytorch implementation of DeepMind's Differentiable Neural Computer (DNC) architecture introduced in their recent Nature paper:

Yuanpu Xie 91 Nov 21, 2022
The official re-implementation of the Neurips 2021 paper, "Targeted Neural Dynamical Modeling".

Targeted Neural Dynamical Modeling Note: This is a re-implementation (in Tensorflow2) of the original TNDM model. We do not plan to further update the

6 Oct 05, 2022
YOLOv4-v3 Training Automation API for Linux

This repository allows you to get started with training a state-of-the-art Deep Learning model with little to no configuration needed! You provide your labeled dataset or label your dataset using our

BMW TechOffice MUNICH 626 Dec 31, 2022
Key information extraction from invoice document with Graph Convolution Network

Key Information Extraction from Scanned Invoices Key information extraction from invoice document with Graph Convolution Network Related blog post fro

Phan Hoang 39 Dec 16, 2022
My usage of Real-ESRGAN to upscale anime, some test and results in the test_img folder

anime upscaler My usage of Real-ESRGAN to upscale anime, I hope to use this on a proper GPU cuz doing this on CPU is completely shit 😂 , I even tried

Shangar Muhunthan 29 Jan 07, 2023
用opencv的dnn模块做yolov5目标检测,包含C++和Python两个版本的程序

yolov5-dnn-cpp-py yolov5s,yolov5l,yolov5m,yolov5x的onnx文件在百度云盘下载, 链接:https://pan.baidu.com/s/1d67LUlOoPFQy0MV39gpJiw 提取码:bayj python版本的主程序是main_yolov5.

365 Jan 04, 2023
PyTorch implementation of DreamerV2 model-based RL algorithm

PyDreamer Reimplementation of DreamerV2 model-based RL algorithm in PyTorch. The official DreamerV2 implementation can be found here. Features ... Run

118 Dec 15, 2022
Minimal fastai code needed for working with pytorch

fastai_minima A mimal version of fastai with the barebones needed to work with Pytorch #all_slow Install pip install fastai_minima How to use This lib

Zachary Mueller 14 Oct 21, 2022
PyTorch implementation of SMODICE: Versatile Offline Imitation Learning via State Occupancy Matching

SMODICE: Versatile Offline Imitation Learning via State Occupancy Matching This is the official PyTorch implementation of SMODICE: Versatile Offline I

Jason Ma 14 Aug 30, 2022
Consistency Regularization for Adversarial Robustness

Consistency Regularization for Adversarial Robustness Official PyTorch implementation of Consistency Regularization for Adversarial Robustness by Jiho

40 Dec 17, 2022
The pytorch implementation of SOKD (BMVC2021).

Semi-Online Knowledge Distillation Implementations of SOKD. Requirements This repo was tested with Python 3.8, PyTorch 1.5.1, torchvision 0.6.1, CUDA

4 Dec 19, 2021
A collection of Google research projects related to Federated Learning and Federated Analytics.

Federated Research Federated Research is a collection of research projects related to Federated Learning and Federated Analytics. Federated learning i

Google Research 483 Jan 05, 2023
Official repository for Fourier model that can generate periodic signals

Conditional Generation of Periodic Signals with Fourier-Based Decoder Jiyoung Lee, Wonjae Kim, Daehoon Gwak, Edward Choi This repository provides offi

8 May 25, 2022
A super lightweight Lagrangian model for calculating millions of trajectories using ERA5 data

Easy-ERA5-Trck Easy-ERA5-Trck Galleries Install Usage Repository Structure Module Files Version iteration Easy-ERA5-Trck is a super lightweight Lagran

Zhenning Li 26 Nov 19, 2022
This repository contains the source codes for the paper AtlasNet V2 - Learning Elementary Structures.

AtlasNet V2 - Learning Elementary Structures This work was build upon Thibault Groueix's AtlasNet and 3D-CODED projects. (you might want to have a loo

Théo Deprelle 123 Nov 11, 2022
TUPÃ was developed to analyze electric field properties in molecular simulations

TUPÃ: Electric field analyses for molecular simulations What is TUPÃ? TUPÃ (pronounced as tu-pan) is a python algorithm that employs MDAnalysis engine

Marcelo D. Polêto 10 Jul 17, 2022