GithubHelp home page GithubHelp logo

gingerbrains / object-detection Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 3.0 19.88 MB

This repository contains an implementation of object detection using YOLOv8 specifically designed for detecting weapons in images and videos. The repository includes pre-trained models and sample data for testing.

License: GNU General Public License v3.0

Python 100.00%

object-detection's Introduction

object-detection

This repository contains an implementation of object detection using YOLOv8 specifically designed for detecting weapons in images and videos. The repository includes pre-trained models and sample data for testing.

Resources Used

Language: Python 3.9

Dataset: https://universe.roboflow.com/fend-tech/weapon-detection-dinou

Here I have used a labelled dataset but if are unable to find a pre-labelled dataset you can label it yourself.

Manually labelling your dataset

Split your dataset into three classes train test valid.

Use labelImg -> https://github.com/heartexlabs/labelImg Make sure to select the txt format for the labels as that is what YOLO requires.

YOLO also requires a data.yaml file. If this file is not generated by labelimg simply create one, here is what my data.yaml contains :

names:
- Grenade
- Gun
- Knife
- Pistol
- handgun
- rifle
nc: 6
test: ../test/images
train: ../train/images
val: ../valid/images

Setting the Data Systematically

The Directory should be as follows:

object_detection
             └── train
                   ├── images
                   │      ├── image_1.jpg
                   │      ├── image_2.jpg
                   │      └── ...
                   │
                   └── labels
                          ├── image_1.txt
                          ├── image_2.txt
                          └── ...
             └── test
                   ├── images
                   │      ├── image_1.jpg
                   │      ├── image_2.jpg
                   │      └── ...
                   │
                   └── labels
                          ├── image_1.txt
                          ├── image_2.txt
                          └── ...
             └── valid
                   ├── images
                   │      ├── image_1.jpg
                   │      ├── image_2.jpg
                   │      └── ...
                   │
                   └── labels
                          ├── image_1.txt
                          ├── image_2.txt
                          └── ...
             ├── data.yaml
             ├──weapon-detection.ipynb
                

Steps to train the model on your custom dataset :

- Create an environment

$python -m venv venv

- Activate Environment

Windows

# In cmd.exe
venv\Scripts\activate.bat
# In PowerShell
venv\Scripts\Activate.ps1

Linux

source myvenv/bin/activate

- Install YOLOv8 via the ultralytics pip package

$pip install ultralytics

- Test your YOLO installation

$yolo task=detect mode=predict model=yolov8n.pt conf=0.25 source='https://media.roboflow.com/notebooks/examples/dog.jpeg'

- Train YOLOv8 on a custom dataset

$yolo task=detect mode=train model=yolov8s.pt data={dataset location}/data.yaml epochs=100 imgsz=640

Your model will begin training and run for several minutes, or hours, depending on how big the dataset is and which training options you chose. A folder named runs will be created.

- Validate with a new model

yolo task=detect mode=val model=/runs/detect/train/weights/best.pt data={dataset location}/data.yaml

- Predict with a custom model

yolo task=detect mode=predict model={HOME}/runs/detect/train/weights/best.pt conf=0.25 source={path to the image u wish to run inference on}

You can also run prediction on an entire folder containing test images

yolo task=detect mode=predict model={HOME}/runs/detect/train/weights/best.pt conf=0.25 source={dataset.location}/test/images

My Results

Test set

result

Confusion Matrix

confusion-matrix

Loss over time

loss

Note :Roboflow is a quick way to get your hands on some labelled data. https://universe.roboflow.com/roboflow-100

object-detection's People

Contributors

gingerbrains avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

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.