It's a mess, but I'll show you how to detect an object very easily.
--Learning YOLO original data http://takesan.hatenablog.com/entry/2018/08/16/013452 --Learning YOLO v3 original data on Google Colaboratory https://qiita.com/emi-cd/items/60e8fe877dbedb2cfae7 --Counting objects using darknet (YOLO) on Google Colab [Image recognition] https://wakuphas.hatenablog.com/entry/2018/09/19/025941
What is YOLO in the first place? What is object detection? Please refer to the above for answers to questions such as. This article is also included in the 3 hours of creation, so please forgive me though there are some places where it is broken.
Prepare simple teacher data. In my case, I wanted to detect the greenhouse this time, so I prepared 30 images for the time being. Like this. The aerial photograph of Google Maps is so beautiful![Screenshot 2019-12-20 20.37.09.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/285361 /aa7b62c1-f85c-4b13-b543-35e0fe032768.png)
We will perform annotation work (labeling) on it. This time I used a tool called labelImg. There are other tools called VoTT and BBox-Label-Tool, but VoTT supports YOLO, but if it doesn't work, it's difficult to start over, and BBox is troublesome to set up when trying to create multiple classes. So I chose labelImg.
Execute the following command to make labelImg ready for use. If you have Python3 installed, you can skip line 3.4.
git clone https://github.com/tzutalin/labelImg.git sudo apt install pyqt5-dev-tools sudo apt install python3-pip sudo pip3 install lxml cd labelImg make qt5py3
Create a folder with any name in the labelimg folder and move the prepared image there. (Vinyl, etc. for greenhouses) Then modify predefined_class.txt in labelimg / data. At first, about 20 classes are written in advance, but this time, delete all the class names that have already been written, and write the class name with a line break with your favorite name. I wrote a line with vinyl.
python3 labelimg.py Run labelImg by. Cut for internal work. Roughly speaking
I will label it like this. 30 sheets is an instant. This completes the teacher data preparation.
We will prepare for learning. To use YOLO, install a framework called darknet. This framework works pretty well with YOLO. (Rather, is it used by YOLO developers?) Install from the following command.
git clone https://github.com/pjreddie/darknet.git
Next, move the images used with labelImg to darknet / data / images and the text files created with labelImg to darknet / data / labels. In that state at / darknet python3 process.py To execute. This separates the teacher data into a teacher file and a learning file.
We will do various work from here. Enumerate. -Create /darknet/data/images/obj.names and enter the name of the label you want to identify (vinyl) -Do the same for /darknet/data/images/obj.list -Set the classes on line 244 of /darknet/cfg/yolo-obj.cfg to 1 as above, and set the filters on line 237 to (classes + coord + 1) * 5. In this case it is 30. -Max_batches on the 20th line of /darknet/cfg/yolo-obj.cfg is the number of times to actually learn. The ideal is classes * 2000, so in this case 2000.
If you don't have /darknet/cfg/yolo-obj.cfg, copy and edit /darknet/cfg/yolov2-voc.cfg. 3rd line: Set batch = 64. The number of images used for each learning step. You can comment out and turn on line 6 4th line: Set subdivisions = 8. The batch is divided by 8. You can comment out and turn on line 7
Finally, modify /darknet/cfg/obj.data as follows: classes=1 train = data/images/train.txt valid = data/images/test.txt labels = data/images/obj.names backup = backup/
https://pjreddie.com/media/files/darknet19_448.conv.23 The preparation is completed by downloading.
It's finally learning. In the current state ./darknet detector train cfg/obj.data cfg/yolo-obj.cfg darknet19_448.conv.23 It's okay to start learning as a CPU, but it takes an unbelievably long time with a CPU and I'm desperate. Therefore, here, we will learn by GPU using Google Colaboratory.
Google Colaboratory is a tool that allows you to use the GPU for free, and it is very friendly because it is basically equipped with tools for deep learning. AI beginners should definitely use it. (Only when you do not use information that cannot be disclosed because it is open source.)
Upload the darknet folder you were working on to drive. After that, save the file related to Google Collaboration from the following and do what is written in .ipynb. git clone https://github.com/foifoi1201/yolo.git
If your post is correct, this should complete the model creation. The rest is based on the downloaded .weights ./darknet detect cfg/obj.cfg obj_final.weights data/***.jpg I think that it can be detected by executing.
If you try to create an object detection model with 30 teacher data within 3 hours, the result will be like this.
I can confirm it. .. ..
Object detection using YOLO is very troublesome to create, and in fact, if you do it this way, you may not be able to do everything well. Besides, Google Colabatory is constantly updated, so it is possible that the same creation method will not work over time. (Actually, it seems that the update was done this time as well, and it took more time than expected to create it. Thank you very much for the references ,,,,,,)
I hope it will be of some help to the same AI beginners as myself.
Recommended Posts