This repo let's you train a custom image detector using the state-of-the-art YOLOv3 computer vision algorithm. For a short write up check out this medium post.
To build and test your YOLO object detection algorithm follow the below steps:
1_Image_Annotation
: Scripts and instructions on annotating images2_Training
: Scripts and instructions on training your YOLOv3 model3_Inference
: Scripts and instructions on testing your trained YOLO model on new images and videosData
: Input Data, Output Data, Model Weights and ResultsUtils
: Utility scripts used by main scriptsWith Google Colab you can skip most of the set up steps and start training your own model right away.
The only hard requirement is a running version of python 3.6 or 3.7. To install python 3.7 go to
and follow the installation instructions. Note that this repo has only been tested with python 3.6 and python 3.7 thus it is recommened to use either python3.6
or python3.7
.
To speed up training, it is recommended to use a GPU with CUDA support. For example on AWS you can use a p2.xlarge
instance (Tesla K80 GPU with 12GB memory). Inference is very fast even on a CPU with approximately ~2 images per second.
Clone this repo with:
git clone https://github.com/AntonMu/TrainYourOwnYOLO
cd TrainYourOwnYOLO/
Create Virtual (Linux/Mac) Environment:
python3 -m venv env
source env/bin/activate
Make sure that, from now on, you run all commands from within your virtual environment.
Use the Github Desktop GUI to clone this repo to your local machine. Navigate to the TrainYourOwnYOLO
project folder and open a power shell window by pressing Shift + Right Click and selecting Open PowerShell window here
in the drop-down menu.
Create Virtual (Windows) Environment:
py -m venv env
.\env\Scripts\activate
Make sure that, from now on, you run all commands from within your virtual environment.
Install all required packages with:
pip install -r requirements.txt
If this fails, you may have to upgrade your pip version first with pip install pip --upgrade
. If your system has working CUDA drivers, it will use your GPU automatically for training and inference.
To test the cat face detector on test images located in TrainYourOwnYOLO/Data/Source_Images/Test_Images
run the Minimal_Example.py
script in the root folder with:
python Minimal_Example.py
The outputs are saved in TrainYourOwnYOLO/Data/Source_Images/Test_Image_Detection_Results
. This includes:
Detection_Results.csv
file with file names and locations of bounding boxes.If you want to detect cat faces in your own pictures, replace the cat images in Data/Source_Images/Test_Images
with your own images.
To train your own custom YOLO object detector please follow the instructions detailed in the three numbered subfolders of this repo:
To make everything run smoothly it is highly recommended to keep the original folder structure of this repo!
Each *.py
script has various command line options that help tweak performance and change things such as input and output directories. All scripts are initialized with good default values that help accomplish all tasks as long as the original folder structure is preserved. To learn more about available command line options of a python script <script_name.py>
run:
python <script_name.py> -h
Unless explicitly stated otherwise at the top of a file, all code is licensed under the MIT license. This repo makes use of ilmonteux/logohunter which itself is inspired by qqwweee/keras-yolo3.
Many thanks to Niklas Wilson for contributing towards making this repo compatible with Tensorflow 2.0.
If you encounter any error, please make sure you follow the instructions exactly (word by word). Once you are familiar with the code, you're welcome to modify it as needed but in order to minimize error, I encourage you to not deviate from the instructions above. If you would like to file an issue, please use the provided template and make sure to fill out all fields.
If you encounter a FileNotFoundError
or a Module not found
error, make sure that you did not change the folder structure. In particular, your working directory needs to look like this:
TrainYourOwnYOLO
└─── 1_Image_Annotation
└─── 2_Training
└─── 3_Inference
└─── Data
└─── Utils
If you want to use a different folder layout (not recommended) you will have to specify your paths as command line arguments. Also, try to avoid spaces in folder names, i.e. don't use a folder name like this my folder
but instead use my_folder
.
If you are using pipenv and are having trouble running python3 -m venv env
, try:
pipenv shell
If you are having trouble getting cv2 to run, try:
apt-get update
apt-get install -y libsm6 libxext6 libxrender-dev
pip install opencv-python
If you are a Linux user and having trouble installing *.snap
package files try:
snap install --dangerous vott-2.1.0-linux.snap
See Snap Tutorial for more information.
If you would like to file an issue, please use the provided issue template and make sure to complete all fields. This makes it easier to reproduce the issue for someone trying to help you.
Issues without a completed issue template will be closed after 7 days.
This work is licensed under a Creative Commons Attribution 4.0 International License. This means that you are free to:
Under the following terms:
Cite as:
@misc{TrainYourOwnYOLO,
title={TrainYourOwnYOLO: Building a Custom Object Detector from Scratch},
author={Anton Muehlemann},
year={2019},
url={https://github.com/AntonMu/TrainYourOwnYOLO}
}
If your work doesn't include a citation list, simply link this github repo!
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。