jueves, 10 de septiembre de 2020

Project 3 part 2 Mask / No mask, train a Yolov4 cnn with Darknet

 

 Project 3 part 2"Mask / No mask", trained with Darknet and Yolov4.cfg


Video output from test-video1 with standard darknet rectangles:

Video output from test-video1.mp4:



Video output from test-video1 with standard darknet rectangles:


Video output from test-video1.mp4: 



https://www.youtube.com/watch?v=42iEsn5D5JI&feature=youtu.be 

Task 2: Train the object detector using Yolo v4 [30 Marks]

You should repeat the above experiment using the Yolo v4 architecture and model.

HINT:

1. You need to change Step 6 along with the above changes. You can use the following link as a reference for training the model using Yolo v4 architecture and pre-trained model.

https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects

I wrote a notebook with the basic pipeline for train a yolov4 cnn with Darknet in Google colab, this are the steps:

1.- I created a folder in Google drive to upload the test files.

2.- Mount a google drive and check its files.


3.- Clone, configure and compile darknet.




4.- Configure yolov3.cfg file.


5.- Create names and data files and save to Google drive.





6.- Create a folder where unzip the image dataset.


7.- Create a train.txt file.


8.- Download pre-trained weights for the convolutional layers file.


9.- Start training.

10.- Object detection with the test images. ...OOPS!





I got the weights after 12 hours training with the best "activation: mist" in .cfg file

Unsuccesfully I tried to install a  version of OpenCV newer than 4.1.2 in Google Colab, I didn't get the trick.

I know that OpenCV 4.3.0 supports "activation: swish" that is almost like "activation: mish", I also tried that here after I modified "yolov4_testingb.cfg".

OpenCV 4.4.0 supports "activation: mish" in function 'ReadDarknetFromCfgStream', Then I run the tests yolov4 with OpenCV 4.4.0 in my own system, here are the outputs.

I found that yolov4 takes longer to train, but is faster and more precise than yolov3.

10.- Object detection with the test images.


Look at the right, the man wearing a black mask, the mask is detected with Yolov4



Look at the girl in black, "No Mask" is detected with yolov4.



11.- Object detection with the test videos.


Youtube link: https://youtu.be/CxfY2xjaDQ0


Youtube link: https://youtu.be/42iEsn5D5JI 

I wished to run all the yolov4 using "activation: mist" in one notebook at colab, I couldn’t do  that because the OpenCV version in colab was 4.1.2, so I left this project aside for several days, when I went back I understood from the hint in the specifications that darknet is a polymorph program, it can do train and test on images, videos and camera stream, it draws the standard rectangles over the images and don’t need OpenCV to do that. I trained yolov3 and yolov4 again; here are some screenshots from the notebook. I changed the file image.c from darknet source files, so the rectangle on people with facemask is green and magenta(danger) with No mask.

predictions-image1.jpg


predictions-image2.jpg

predictions-image3.jpg

predictions-image4.jpg

The videos with the Darknet standard rectangle:

The prediction for test-video1:


The prediction for test-video2



No hay comentarios:

Publicar un comentario