<jupyter_start><jupyter_text>Connect google drive<jupyter_code># Check if NVIDIA GPU is enabled
!nvidia-smi
from google.colab import drive
drive.mount('/content/gdrive')
!ln -s /content/gdrive/My\ Drive/ /mydrive
!ls /mydrive<jupyter_output><empty_output><jupyter_text>Clone, configure & compile Darknet<jupyter_code># Clone
!git clone https://github.com/AlexeyAB/darknet
# Configure
%cd darknet
!sed -i 's/OPENCV=0/OPENCV=1/' Makefile
!sed -i 's/GPU=0/GPU=1/' Makefile
!sed -i 's/CUDNN=0/CUDNN=1/' Makefile
# Compile, Warnings are fine
!make<jupyter_output><empty_output><jupyter_text>Configure yolov3.cfg file
change `max_batches` and `classes` acordingly.<jupyter_code># Make a copy of yolov3.cfg
!cp cfg/yolov3.cfg cfg/yolov3_training.cfg

!sed -i 's/batch=1/batch=64/' cfg/yolov3_training.cfg
!sed -i 's/subdivisions=1/subdivisions=16/' cfg/yolov3_training.cfg
!sed -i 's/max_batches = 500200/max_batches = 6000/' cfg/yolov3_training.cfg
!sed -i '610 s@classes=80@classes=3@' cfg/yolov3_training.cfg
!sed -i '696 s@classes=80@classes=3@' cfg/yolov3_training.cfg
!sed -i '783 s@classes=80@classes=3@' cfg/yolov3_training.cfg
!sed -i '603 s@filters=255@filters=24@' cfg/yolov3_training.cfg
!sed -i '689 s@filters=255@filters=24@' cfg/yolov3_training.cfg
!sed -i '776 s@filters=255@filters=24@' cfg/yolov3_training.cfg<jupyter_output><empty_output><jupyter_text>Create .names and .data files<jupyter_code>!echo -e 'Without Mask\nWith Mask\nMask worn incorrect' > data/obj.names
!echo -e 'classes= 3\ntrain  = data/train.txt\nvalid  = data/test.txt\nnames = data/obj.names\nbackup = /mydrive/yolov3' > data/obj.data<jupyter_output><empty_output><jupyter_text>Save yolov3_training.cfg and obj.names files in Google drive<jupyter_code>!cp cfg/yolov3_training.cfg /mydrive/yolov3/yolov3_testing.cfg
!cp data/obj.names /mydrive/yolov3/classes.txt<jupyter_output><empty_output><jupyter_text>Create a folder and unzip image train dataset<jupyter_code>!mkdir data/obj
!unzip /mydrive/yolov3/images_train.zip -d data/obj<jupyter_output><empty_output><jupyter_text>Create train.txt file<jupyter_code>import glob
import random
images_list = glob.glob("data/obj/test/*.png")

# Uncomment to get random train/test split (Only use if no retraining/evaluation ect.)
# k = int(len(images_list) * 0.8)
# print(len(images_list))
# train = random.sample(images_list, k=k)
# print(len(train))
# test = list(set(images_list) - set(train))
# print( len(test))

# with open("data/train.txt", "w") as f:
#     f.write("\n".join(train))
# with open("data/test.txt", "w") as f:
#     f.write("\n".join(test))

with open("data/train.txt", "w") as f:
     f.write("\n".join(images_list))<jupyter_output><empty_output><jupyter_text>Download pre-trained weights for the convolutional layers file
Only needed when training without previous training.<jupyter_code>!wget https://pjreddie.com/media/files/darknet53.conv.74<jupyter_output><empty_output><jupyter_text>Start training<jupyter_code>!./darknet detector train data/obj.data cfg/yolov3_training.cfg darknet53.conv.74 -dont_show<jupyter_output><empty_output><jupyter_text>Continue Training<jupyter_code>!./darknet detector train data/obj.data cfg/yolov3_training.cfg /mydrive/yolov3/yolov3_training_last.weights -dont_show<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14307504575960953, 'fraction_numerical': 0.030201342281879196, 'mean_word_length': 6.270509977827051, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 43, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '334094', 'license': 'CC0-1.0', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1296, 'n_words': 231, 'path': 'Train_YoloV3_Darknet.ipynb', 'repo_name': 'rlcmtzc/FacemaskDetection', 'size': '3278'}