{"id":21693549,"url":"https://github.com/kleinyuan/easy-yolo","last_synced_at":"2025-04-12T10:40:51.656Z","repository":{"id":87912019,"uuid":"89671551","full_name":"KleinYuan/easy-yolo","owner":"KleinYuan","description":"Yolo (Real time object detection) model training tutorial with deep learning neural networks","archived":false,"fork":false,"pushed_at":"2017-11-07T08:58:45.000Z","size":72047,"stargazers_count":100,"open_issues_count":4,"forks_count":27,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-26T05:33:12.856Z","etag":null,"topics":["camera","darknet","deep-learning","deep-learning-tutorial","labelimg","machine-learning","multiple-gpu","object-detection","python","real-time","training-yolo","tutorial","yolo"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KleinYuan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-28T05:43:31.000Z","updated_at":"2025-01-01T04:16:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"2e6be26b-fe93-4af8-bf8c-d003d3a075c0","html_url":"https://github.com/KleinYuan/easy-yolo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KleinYuan%2Feasy-yolo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KleinYuan%2Feasy-yolo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KleinYuan%2Feasy-yolo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KleinYuan%2Feasy-yolo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KleinYuan","download_url":"https://codeload.github.com/KleinYuan/easy-yolo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248556640,"owners_count":21124155,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["camera","darknet","deep-learning","deep-learning-tutorial","labelimg","machine-learning","multiple-gpu","object-detection","python","real-time","training-yolo","tutorial","yolo"],"created_at":"2024-11-25T18:20:46.766Z","updated_at":"2025-04-12T10:40:51.646Z","avatar_url":"https://github.com/KleinYuan.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Description\n\nHere, we guide you step by step with a bare machine to get a real time object detector with Deep Learning Neural Network.\n\n-  Claim:This project is based on [darknet](https://github.com/pjreddie/darknet)\n\n-  Task: Real time object detection and classification\n\n-  Paper: [YOLO9000: Better, Faster, Stronger](https://arxiv.org/abs/1612.08242)\n\n-  Dependencies: Ubuntu 14.04/OpenCV v2.4.13/CUDA 8.0/cuDNN v5.0\n\n-  Languages: C + Python 2.7 (Python 3.5 will work but you need to modify files in /scripts a little bit)\n\n# Step by Step Tutorial\n\n### Step-1. Prepare machine and environment\n\n#### a. System and GPU\n\nA `Ubuntu 14.04` native system is preferred in training process.\nAt least one `NVIDIA GPU Card` is required such as `GeForce` series to enable GPU mode. This is not a must but strongly recommended if you do not have lots of time.\n\n*It is very tricky to use virtualBox on top of macOS/windows to communicate to GPU (actually, to be more general, taking advantages of host machine's resources including memories on VirtualBox is quite limited)*. *Therefore, I do not recommend this way but feel free to try it if you have no other work around.*\n\n#### b. Environment (GPU)\n\n##### Descriptions:\n\n- [ ] `OpenCV` :  OpenCV is useful no matter whether you want to enable GPU mode and here we use `OpenCV v2.4.13` for `Ubuntu 14.04`;\n\n- [ ] `NVIDIA Driver`: NVIDIA Driver is needed for machine to communicate with GPU;\n\n- [ ] `CUDA`: CUDA is a parallel computing platform and application programming interface (API) model created by Nvidia and we use `CUDA 8.0` here;\n\n- [ ] `cuDNN`: cuDNN is a GPU acceleration library, especially for deep learning neural networks (i. e., it speeds up when you work with GPU) and we use `cuDNN v5.0 for CUDA 8.0` here\n\n##### Install:\n\n`OpenCV`:\n\n```\nsudo apt-get update\nsudo apt-get install -y build-essential\nsudo apt-get install -y cmake\nsudo apt-get install -y libgtk2.0-dev\nsudo apt-get install -y pkg-config\nsudo apt-get install -y python-numpy python-dev\nsudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev\nsudo apt-get install -y libjpeg-dev libpng-dev libtiff-dev libjasper-dev\nsudo apt-get -qq install libopencv-dev build-essential checkinstall cmake pkg-config yasm libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils\nwget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.13/opencv-2.4.13.zip\nunzip opencv-2.4.13.zip\ncd opencv-2.4.13\nmkdir release\ncd release\ncmake -G \"Unix Makefiles\" -D CMAKE_CXX_COMPILER=/usr/bin/g++ CMAKE_C_COMPILER=/usr/bin/gcc -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D BUILD_FAT_JAVA_LIB=ON -D INSTALL_TO_MANGLED_PATHS=ON -D INSTALL_CREATE_DISTRIB=ON -D INSTALL_TESTS=ON -D ENABLE_FAST_MATH=ON -D WITH_IMAGEIO=ON -D BUILD_SHARED_LIBS=OFF -D WITH_GSTREAMER=ON -DBUILD_TIFF=ON ..\nmake all -j8\nsudo make install\n```\n\nReferring from :https://gist.github.com/bigsnarfdude/7305c8d8335c7cfc91888485a33d9bd9\n\n`NVIDIA Driver`:\n\n```\nsudo apt-get update \u0026\u0026 sudo apt-get upgrade\nsudo apt-get install build-essential\nwget https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run\nchmod +x cuda_8.0.61_375.26_linux-run\nmkdir nvidia_installers\n./cuda_8.0.61_375.26_linux-run -extract=${PWD}/nvidia_installers\n```\n\n###### Highlight!!!\nFor Ubuntu, if you install the system together with Windows sharing BIOS/UEFI, you probably would like to turn off `Security Boot` so that you don't have any signature issues while installing the NVIDIA driver.\n\nIf you are using AWS EC2 Ubuntu Machines, also run following(which is to disable nouveau since it conflicts with NVIDIA's kernel module and please PAY ATTENTION TO THE LAST LINE, which requires REBOOT. Pay extra attention, if you are using AWS EC2 spot instance):\n\n```\nsudo apt-get install linux-image-extra-virtual\necho \"blacklist nouveau\" | sudo tee -a /etc/modprobe.d/blacklist-nouveau.conf\necho \"blacklist lbm-nouveau\" | sudo tee -a /etc/modprobe.d/blacklist-nouveau.conf\necho \"options nouveau modeset=0\" | sudo tee -a /etc/modprobe.d/blacklist-nouveau.conf\necho \"alias nouveau off\" | sudo tee -a /etc/modprobe.d/blacklist-nouveau.conf\necho \"alias lbm-nouveau off\" | sudo tee -a /etc/modprobe.d/blacklist-nouveau.conf\necho options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf\nsudo update-initramfs -u\nsudo reboot\n```\n\nThen\n\n```\nsudo apt-get install linux-source\nsudo apt-get install linux-headers-`uname -r`\nsudo ./nvidia_installers/NVIDIA-Linux-x86_64-375.26.run -s\n```\n\nIf you are not using AWS EC2 Ubuntu or, to be more clear, if you are using an Ubuntu with an UI, it means that you are running a X server, which will bring your problems on executing last line.\n\nTherefore, you need to kill the X server to install nvidia driver (which by default will prompt out an UI) and then restart X server.\n\nTherefore:\n\n- [X] Press Control + ALT + F1\n\n- [X] Type your ubuntu system username (exp. ubuntu) and password to log in\n\n- [X] Kill X Server by `sudo service lightdm stop`\n\n- [X] Navigate to the correct folder and Install NVIDIA Driver in silent mode `sudo ./nvidia_installers/NVIDIA-Linux-x86_64-375.26.run -s`\n\n- [X] Restart X server by `sudo service lightdm start`\n\n- [X] Go back to your fancy UI if you are using any by Control + ALT + F7\n\n\n`CUDA`:\n\n```\nsudo modprobe nvidia\nsudo apt-get install build-essential\nsudo ./cuda-linux64-rel-8.0.61-21551265.run\nsudo ./cuda-samples-linux-8.0.61-21551265.run\necho \"export PATH=$PATH:/usr/local/cuda-8.0/bin\" \u003e\u003e ~/.bashrc\necho \"export LD_LIBRARY_PATH=:/usr/local/cuda-8.0/lib64\" \u003e\u003e ~/.bashrc\nsource ~/.bashrc\nsudo ldconfig\n```\n\n`cuDNN`:\n\nFirst,\n\ndownload `cudnn-8.0-linux-x64-v5.0-ga.tgz` from https://developer.nvidia.com/cudnn (You may need to sign up a NVIDIA developer to download it and don't panic, it's free.)\n\n![nvidia-cudnn](https://cloud.githubusercontent.com/assets/8921629/25516102/621cd374-2b9d-11e7-8afa-8351f700ced4.png)\n\nThen:\n```\ntar -zxf cudnn-8.0-linux-x64-v5.0-ga.tgz\nsudo cp ./cuda/lib64/* /usr/local/cuda/lib64/\nsudo cp ./cuda/include/cudnn.h /usr/local/cuda/include/\n```\n\nValidate:\n\n- [ ] `OpenCV`: ```pkg-config opencv --cflags```\n\n- [ ] `NVIDIA Driver`: ```sudo nvidia-smi```\n\n- [ ] `CUDA`: ``` nvcc --version```\n\n- [ ] `cuDNN`: No need to validate, install cuDNN is purely just doing copy\u0026paste to your local machine\n\n\n### Step-2. Download this repo\n\n```\ngit clone https://github.com/KleinYuan/easy-yolo.git\n```\n\nAnd create a folder called `devkit` in root of this repo and also sub-folders like below:\n\n```\n+-- cfg\n+-- scripts\n+-- src\n+-- devkit\n|   +-- 2017\n|       +-- Annotations\n|       +-- ImageSets\n|       +-- Images\n|       +-- labels\n.gitignore\ndarkenet19_448.conv.23\neasy.names\nLICENSE\nMakefile\nREADME.md\n```\n\n\n\n### Step-3. Prepare data step by step\n\n#### a. Collect Images with no bigger size than 416*416\nGo ahead and collect many many images and put all of them into `devkit/2017/Images` folder, for example:\n```\n.\n+-- dataSets\n|   +-- 01.png\n|   +-- 02.png\n|   +-- 03.png\n|   ..........\n|   (many many many ...)\n|   ..........\n```\n\n\n#### b. Install the correct tool\n[labelImg](https://github.com/tzutalin/labelImg) is my favorite tool, which works very well on many different platforms and here we use this tool to label images:\n\n#### c. Label images\n`labelImg` will eventually create .xml file including bounding box coord, (class) name and file information\n\nSample .xml:\n```\n\u003cannotation verified=\"no\"\u003e\n  \u003cfolder\u003e2017\u003c/folder\u003e\n  \u003cfilename\u003e0\u003c/filename\u003e\n  \u003cpath\u003e${dir}/0.png\u003c/path\u003e\n  \u003csource\u003e\n    \u003cdatabase\u003eUnknown\u003c/database\u003e\n  \u003c/source\u003e\n  \u003csize\u003e\n    \u003cwidth\u003e416\u003c/width\u003e\n    \u003cheight\u003e416\u003c/height\u003e\n    \u003cdepth\u003e3\u003c/depth\u003e\n  \u003c/size\u003e\n  \u003csegmented\u003e0\u003c/segmented\u003e\n  \u003cobject\u003e\n    \u003cname\u003e2\u003c/name\u003e\n    \u003cpose\u003eUnspecified\u003c/pose\u003e\n    \u003ctruncated\u003e0\u003c/truncated\u003e\n    \u003cdifficult\u003e0\u003c/difficult\u003e\n    \u003cbndbox\u003e\n      \u003cxmin\u003e239\u003c/xmin\u003e\n      \u003cymin\u003e179\u003c/ymin\u003e\n      \u003cxmax\u003e291\u003c/xmax\u003e\n      \u003cymax\u003e226\u003c/ymax\u003e\n    \u003c/bndbox\u003e\n  \u003c/object\u003e\n\u003c/annotation\u003e\n```\n\n### Step-4. Pre-process labeled data and Configure model\n\n#### a. Pre-process labeled data\n\nFirst of all, you need to know how many classes you want to classify (i.e, how many kinds of objects you want this algorithm to spot eventually) and their names.\n\nThen, open `scripts/easy_label.py` and edit the `7th line` to replace the `classes`. For example, the default one is for task to is train a model to spot `banana`, `monkey`, `panda` in future photos/videos of a zoo.\n\nAlso, in the same file, edit the `6th line` to replace the format of your images, and by default, it's `png`.\n\nAt last, add(replace the default) classes names in `./easy.names`.\n\nNavigate to the root of this folder and run:\n```\nmake prepare-data\n```\nThen you will see:\n```\n+-- devkit\n|   +-- 2017\n|       +-- Annotations\n|           +-- 01.xml\n|           +-- 02.xml\n|           +-- ...\n|       +-- ImageSets\n|           +-- train.txt\n|           +-- val.txt\n|       +-- Images\n|           +-- 01.png\n|           +-- 02.png\n|           +-- ...\n|       +-- labels\n|           +-- 01.txt\n|           +-- 02.txt\n|           +-- ...\n+-- 2017_train.txt\n+-- 2017_val.txt\n```\nWhich is exactly a DEV Kit for your deep learning model.\n\n#### b. Configure Model\n\nFirstly,\n\nLet's say, your training images size is `A*A` (which means width and height are both A) and classes number (how many classes you are trying to classify) is B.\n\nNavigate to the root of this folder and run:\n```\npython ${PWD}/scripts/in_place.py -f ${PWD}/cfg/easy.cfg -o ${IMAGE_WIDTH} -n A\npython ${PWD}/scripts/in_place.py -f ${PWD}/cfg/easy.cfg -o ${IMAGE_HEIGHT} -n A\npython ${PWD}/scripts/in_place.py -f ${PWD}/cfg/easy.cfg -o ${CLASS_NUM} -n B\npython ${PWD}/scripts/in_place.py -f ${PWD}/cfg/easy.data -o ${CLASS_NUM} -n B\n```\n\nSecondly,\n\nWe need to do some math and let's say you have C = (classes + 5) * 5.\n\nThen continue run:\n\n```\npython ${PWD}/scripts/in_place.py -f ${PWD}/cfg/easy.cfg -o ${FILTERS_NUM} -n C\n\n```\n\n*Note: If those scripts does not work, you just manually replace them.*\n\n### Step-5. Make darknet executable and Train\n\n#### a. Configure Makefile\n\nIf you are using GPU to train, then do not change any thing.\n\nIf you are using CPU to train, open Makefile and edit first 4 lines to be below:\n```\nGPU=0\nCUDNN=0\nOPENCV=1\nDEBUG=0\n```\nwhich basically just disable GPU mode\n\n\n\n#### b. Create darknet executable\n\nNavigate to the root of this folder and run:\n```\nmake\n```\nThen you are supposed to see a file just called `darknet` in root.\n\n#### c. Train\n\nNavigate to the root of this folder and run:\n```\nmake train\n```\n\n\n*Command above will train model with single GPU*\n\nIf you want to train with multiple GPUs you need to first still run above and then wait for a model called easy_1000.weights (or whatever weights files larger than 1000) occur in backup folder.\n\nAnd then run:\n```\nmake train-multi-gpus\n```\n(Examples above assume that you have 2 GPUs and with easy_1000.weights)\n\n\nTADA! You can go to sleep and wait for several hours (days) to get a trained model sitting in `backup` folder.\n\n### Step-6. Test with static image and live stream camera\n\n#### a. Static Image\nDrag your image into the root folder and rename it as `test.png`, then run:\n```\nmake test\n```\n\n#### b. Live stream camera\n\n```\nmake test-camera\n```\n\n# Further Work\n\n- [X] Add a python wrapper\n- [ ] Build a docker image to automate the entire process (could be tricky to mount with camera tho)\n\n# License\n[License](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkleinyuan%2Feasy-yolo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkleinyuan%2Feasy-yolo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkleinyuan%2Feasy-yolo/lists"}