Image&Video Weapon Recognizer by Yolov5
First, you can run my example code, and then train your own model and use it in the program.
To run Recognizer clone repo:
git clone https://github.com/andrey-kireev-1/Recognizer.git
Install python requirements:
pip install -r requirements.txt
Open and run app.py. Here you can select recognition accuracy and files (images: .jpg, .png; videos: .avi, .mp4).
After selecting a file, object recognition will start. 4 categories of weapons can be recognized: pistol, machine gun, knife, hand grenade. For example, the input and output image could be like this:
And video:
Download different photos and videos with weapons and try to recognize them. Enjoy :)
Collect a set of images with your object. Label your images (for example, with: Make Sense).
Divide the collected and labeled set of images into 3 folders: train, valid, test. (Further, I recommend using Google Colab, but you can also work locally.) Create a folder in Google Drive, put the folders train, valid, test and dataset.yaml file there (replace the folder paths according to your Google Drive).
Next: Upload on Google Drive train_model.ipynb, open it in Google Colab, change folders paths and run this file. The model will start training.
After completing the training of the model, download the file best.pt from the path /content/yolov5/runs/train/exp/weights/best.pt. Close Google Colab. Place your best.pt file into your cloning repo local folder. Now your program will recognize your own object.