Giter Club home page Giter Club logo

aminehy / yolov3-for-custum-objects Goto Github PK

View Code? Open in Web Editor NEW
24.0 3.0 4.0 132.51 MB

This repository illustrates the steps for training YOLOv3 and YOLOv3-tiny to detect fire in images and videos. First, a fire dataset of labeled images is collected from the internet. The images with their annotations have been prepared and converted into YOLO format and put into one folder to gather all the data. Therefore, the data folder contains images ('*jpg') and their associated annotations files ('.txt') with the same name.

License: Other

CMake 1.75% Makefile 0.30% PowerShell 0.50% Shell 0.48% C# 0.19% Batchfile 0.73% Python 6.00% C 67.11% C++ 8.64% Cuda 14.29%
fire firedetection yolo-model object detection

yolov3-for-custum-objects's Introduction

Training a Fire Detector

This folder illustrate the steps for training YOLOv3 and YOLOv3-tiny to detect fire in images and videos.

First a fire dataset of labeled images is collected from internet. The images with their annotations have been prepared and converted into YOLO format and put into one folder to gather all the data. Therefore, the data folder contains images ('*jpg') and their associated annotations files ('.txt') with the same name.

The annotations need to be converted into YOLO format, which is :

<class_id, x_c/W, y_c/H, h/H, w/W>

AI-lab

Launch AI-LAB

Pull AI-lab from Docker Hub

docker pull aminehy/ai-lab

Run the AI-lab and start your development

xhost +

then

docker run -it --rm
--runtime=nvidia
-v $(pwd):/workspace \
-w /workspace \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=$DISPLAY \
-p 8888:8888 -p 6006:6006 aminehy/ai-lab:latest

Retrain YOLO on a Costum Dataset

retrain_Yolo diagram

YOLOv3

  1. Create a customized configuration file for YOLO model from cfg/yolov3.cfg

    cp cfg/yolov3.cfg yolov3-obj.cfg
    
    yolov3-obj.cfg
        [net]
        # Testing
        # batch=64
        # subdivisions=8
        # Training
        batch=64
        subdivisions=16
        width=416
        height=416
        channels=3
        momentum=0.9
        decay=0.0005
        angle=0
        saturation = 1.5
        exposure = 1.5
        hue=.1
        ...
    
  2. Open yolov3-obj.cfg and edit its content with the appropriate information. In this application we have only one object to detect, 'fire', thus, nb_class = 1

    * batch = 64
    * subdivision=8 (increase if `Out of memory`)
    * filters = (nb_class+5)*3: filters = 255 => filter = 18
    * classes = nb_class: classes = 80  => classes = 1
    * max_batches=classes*2000: max_batches = 2000
    * steps=80% and 90% of max_batches : steps = 1600, 1800
    
    
  3. Create a file train.txt that lists paths of all annotated images (*.jpg) of the dataset data/obj/

    train.txt
        data/obj/pic (132).jpg
        data/obj/img (42).jpg
        data/obj/img (90).jpg
        data/obj/pic (148).jpg
        data/obj/small (82).jpg
        data/obj/small (55).jpg
        data/obj/small (73).jpg
        data/obj/small (53).jpg
        data/obj/pic (42).jpg
        ...
    
    
  4. Create obj.names and list the classes names

    obj.names
        fire
    
  5. Create and setup a data file obj.data

    obj.data
        classes = 1
        train  = train.txt
        valid  = train.txt
        names = obj.names
        backup = backup/
    
  6. Download pre-trained weights for the convolutional layers (154 MB): https://pjreddie.com/media/files/darknet53.conv.74

  7. Start training by using the command line

    ./darknet detector train yolov3-obj.cfg obj.data darknet53.conv.74
    
  8. test:

./darknet detector test obj.data  yolov3-obj.cfg backup/yolov3-obj_final.weights

YOLOv3-tiny

  1. Create a customized configuration file for YOLO model from cfg/yolov3-tiny_obj.cfg

    cp cfg/yolov3.cfg yolov3-obj.cfg
    
    yolov3-obj.cfg
        [net]
        # Testing
        # batch=64
        # subdivisions=8
        # Training
        batch=64
        subdivisions=16
        width=416
        height=416
        channels=3
        momentum=0.9
        decay=0.0005
        angle=0
        saturation = 1.5
        exposure = 1.5
        hue=.1
        ...
    
  2. Open yolov3-obj.cfg and edit its content with the appropriate information. In this application we have only one object to detect, 'fire', thus, nb_class = 1

    * batch = 64
    * subdivision=8 (increase if `Out of memory`)
    * filters = (nb_class+5)*3: filters = 255 => filter = 18
    * classes = nb_class: classes = 80  => classes = 1
    * max_batches=classes*2000: max_batches = 2000
    * steps=80% and 90% of max_batches : steps = 1600, 1800
    
    
  3. Get pre-trained weights yolov3-tiny.conv.15

./darknet partial cfg/yolov3-tiny.cfg fire/model/yolov3-tiny.weights fire/model/yolov3-tiny.conv.15 15
  1. Training
./darknet detector train obj.data yolov3-tiny-obj.cfg fire/model/yolov3-tiny.conv.15
  1. Results
v3 (mse loss, Normalizer: (iou: 0.750000, cls: 1.000000) Region 23 Avg (IOU: 0.664938, GIOU: 0.652729), Class: 0.999684, Obj: 0.376908, No Obj: 0.000314, .5R: 1.000000, .75R: 0.000000, count: 3

 2000: 0.604868, 0.560218 avg loss, 0.000010 rate, 1.346011 seconds, 128000 images
Saving weights to backup//yolov3-tiny-obj_2000.weights
Saving weights to backup//yolov3-tiny-obj_last.weights
Saving weights to backup//yolov3-tiny-obj_final.weights

chart_yolo-tiny

Test of the Trained Fire Detection Application

(Note: You might want to recompile the DarkNet on your computer: Edit the Makefile.txt then run make)

Image

Detect fire in an imahge file

```
./darknet detector test fire/data/obj.data fire/cfg/yolov3-tiny-obj.cfg fire/model/yolov3-tiny-obj_final.weights fire/data/obj/img (9).jpg
```

Results

Video

  • Detect fire in real-time video stream from webcam

    ./darknet detector demo fire/data/obj.data fire/cfg/yolov3-tiny-obj.cfg fire/model/yolov3-tiny-obj_final.weights
    

    Note: add the option to save the output video: -out_filename filename.mp4

  • Test on video stream from file

    ./darknet detector demo fire/data/obj.data fire/cfg/yolov3-tiny-obj.cfg fire/model/yolov3-tiny-obj_final.weights fire/videos/test.mp4
    
  • Example:

    ./darknet detector demo fire/data/obj.data fire/cfg/yolov3-tiny-obj.cfg fire/model/yolov3-tiny-obj_final.weights fire/videos/DJI_0070.MOV -out_filename ./fire/videos/DJI_0070_output.mp4

Pre-trained Models

There are weights-file for different cfg-files (smaller size -> faster speed & lower accuracy:

enetb0-coco_final.weights and yolov3-tiny-prn.cfg (33.1% [email protected] - 3.5 BFlops - more)

Reference

yolov3-for-custum-objects's People

Contributors

aminehy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

yolov3-for-custum-objects's Issues

Download the Dataset ?

Hello,
Thank you Amine for this great work !
Is it possible to get a direct link to download the annotated dataset ?
Thank you

how many images for training

i am working on similar project , and i want to know , how many images of fire to train in order to get height mAP ( 80 - 90 ) ????

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.