<jupyter_start><jupyter_text><jupyter_code># Step 1. Mount drive 
from google.colab import drive
drive.mount('/content/gdrive')
# Step 2. Tai ma nguon YOLO ve drive
!rm -rf darknet
%cd /content/gdrive/My\ Drive
!git clone https://github.com/AlexeyAB/darknet
%cd /content/gdrive/My\ Drive/darknet
!rm -rf data
!mkdir data
# Step 4. file data
%cd /content/gdrive/My\ Drive/darknet/data
!unzip data.zip
# Step 5. Create file yolo.names
%cd /content/gdrive/My\ Drive/darknet
!echo "PET" > yolo.names
!echo "HDPE" >> yolo.names
# Step 6. Create file train.txt and val.txt
%cd /content/gdrive/My\ Drive/darknet

import glob2
import math  
import os
import numpy as np

files = []
for ext in ["*.png", "*.jpeg", "*.jpg"]:
  image_files = glob2.glob(os.path.join("data/data/", ext))
  files += image_files

nb_val = math.floor(len(files)*0.2)
rand_idx = np.random.randint(0, len(files), nb_val)

# Tạo file train.txt
with open("train.txt", "w") as f:
  for idx in np.arange(len(files)):
    if (os.path.exists(files[idx][:-3] + "txt")):
      f.write(files[idx]+'\n')

# Tạo file vali.txt
with open("val.txt", "w") as f:
  for idx in np.arange(len(files)):
    if (idx in rand_idx) and (os.path.exists(files[idx][:-3] + "txt")):
      f.write(files[idx]+'\n')
# Step 7. Create file yolo.data
%cd /content/gdrive/My\ Drive/darknet
!mkdir backup
!echo classes=2 > yolo.data
!echo train=train.txt >> yolo.data
!echo valid=val.txt >> yolo.data
!echo names=yolo.names >> yolo.data
!echo backup=backup >> yolo.data
# Step 8. Make darknet
%cd /content/gdrive/My\ Drive/darknet
!rm darknet
!make
# Step 9. Download pretrain weight
%cd /content/gdrive/My\ Drive/darknet
!wget https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v3_optimal/yolov4.conv.137
# Step 10. Train
%cd /content/gdrive/My\ Drive/darknet
!./darknet detector train yolo.data cfg/yolov4-custom.cfg yolov4.conv.137 -dont_show<jupyter_output>[Errno 2] No such file or directory: '/content/gdrive/My Drive/darknet'
/content
/bin/bash: ./darknet: No such file or directory
{'fraction_non_alphanumeric': 0.15913555992141454, 'fraction_numerical': 0.01424361493123772, 'mean_word_length': 4.042079207920792, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 16, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '397309', 'license': 'Apache-2.0', 'n_tokens_mistral': 811, 'n_tokens_neox': 786, 'n_words': 206, 'path': 'test_cvbot.ipynb', 'repo_name': 'Kiet-98/cvbot', 'size': '2036'}