Due to Covid-19, the social distancing level is elevated and gathering more than 5 people is prohibited in Korea. We designed this program in order to detect face mask and the gathering of people using deep learning and computer vision. We use YOLOv5 which is a pre-trained object detection model in Google Colab and Visual Studio Code through Anaconda virtual environment.
1. Download Image and Annotation files
1.1. Download Zip file
(Annotation file's format : XML)
1.2. XML to Text(Yolov5) Conversion
Object detection by using YOLOv5 requires a compatible label format. Since the annotation downloaded from kaggle has a .xml format, we convert it to a .txt file according to the method presented.
Skip tutorial and create new object detection project. Roboflow provides object detection type basically and you do not need to change.
Now, you can upload data to roboflow. Select the path to your images and annotations.
Then, the labels are indicated on the images in position.
You can assign the proportion of training, testing and validation set. For this step, we continue as default set since we do not need to separate data set. (You can set all data to single set such as training, testing, or validation)
You can preprocess the data such as 'Auto-Orient' and 'Resize' before converting. These process are recommanded but not essential and you can skip.
Click 'Generate' button on the bottom of the page and finish conversion.
Select YOLOv5 Pytorch data format and download.
2. Training
2.1. Recall converted image and annotation files
If you have run the code, you can see the images and label folders for train, test, and valid created in the file window on the left.
Currently, the train and validation datasets are randomly divided. But we want to shuffle the data every time we train. So put all the data together and shuffle them randomly.
classColors:# Ultralytics color palette https://ultralytics.com/def__init__(self):# hex = matplotlib.colors.TABLEAU_COLORS.values()hex= ('FFB330','0B6CE3','FF0000','FFB21D','CFD231','48F90A','92CC17','3DDB86','1A9334','00D4BB','2C99A8','00C2FF','344593','6473FF','0018EC','8438FF','520085','CB38FF','FF95C8','FF37C7') self.palette = [self.hex2rgb('#'+ c)for c inhex] self.n =len(self.palette)def__call__(self,i,bgr=False): c = self.palette[int(i)% self.n]return (c[2], c[1], c[0]) if bgr else c@staticmethoddefhex2rgb(h): # rgb order (PIL)returntuple(int(h[1+ i:1+ i +2], 16) for i in (0, 2, 4))