<jupyter_start><jupyter_text>Download Dataset of GoogleDownload data from below link with mark and area and label```https://storage.googleapis.com/openimages/web/visualizer/index.html?set=train&type=detection&c=%2Fm%2F01mqdt```<jupyter_code>from google.colab import drive
drive.mount('/content/gdrive')<jupyter_output>Mounted at /content/gdrive<jupyter_text>download model<jupyter_code># clone darknet repo
# % cd ../gdrive/MyDrive/Yolo/yolov3
!git clone https://github.com/AlexeyAB/darknet<jupyter_output>Cloning into 'darknet'...
remote: Enumerating objects: 15363, done.[K
remote: Counting objects: 100% (5/5), done.[K
remote: Compressing objects: 100% (5/5), done.[K
remote: Total 15363 (delta 0), reused 3 (delta 0), pack-reused 15358[K
Receiving objects: 100% (15363/15363), 14.00 MiB | 17.51 MiB/s, done.
Resolving deltas: 100% (10328/10328), done.<jupyter_text>download data<jupyter_code>! git clone https://github.com/EscVM/OIDv4_ToolKit.git
! mkdir dataset/google
% cd OIDv4_ToolKit
! pip3 install -r requirements.txt
! python3 main.py downloader --classes Traffic_sign --type_csv validation --Dataset ../../dataset/google/ -y
! python3 main.py downloader --classes Traffic_sign --type_csv test  --Dataset ../../dataset/google/ -y
! python3 main.py downloader --classes Traffic_sign --type_csv train --Dataset ../../dataset/google/ -y<jupyter_output>Cloning into 'OIDv4_ToolKit'...
remote: Enumerating objects: 422, done.[K
remote: Total 422 (delta 0), reused 0 (delta 0), pack-reused 422[K
Receiving objects: 100% (422/422), 34.08 MiB | 19.55 MiB/s, done.
Resolving deltas: 100% (146/146), done.
mkdir: cannot create directory ‘dataset/google’: No such file or directory
/content/OIDv4_ToolKit
Requirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 1)) (1.1.5)
Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 2)) (1.19.5)
Collecting awscli
  Downloading awscli-1.22.6-py3-none-any.whl (3.8 MB)
[K     |████████████████████████████████| 3.8 MB 4.3 MB/s 
[?25hRequirement already satisfied: urllib3 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 5)) (1.24.3)
Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 7)) (4.62.3)
Requirement alread[...]<jupyter_text>organize the data<jupyter_code>% cd ../dataset
! mkdir obj
! cp google/test/Traffic\ sign/Label/* obj
! cp google/test/Traffic\ sign/*.jpg obj
! cp google/train/Traffic\ sign/Label/* obj
! cp google/train/Traffic\ sign/*.jpg obj
! cp google/validation/Traffic\ sign/Label/* obj
! cp google/validation/Traffic\ sign/*.jpg obj
!sed -i 's/Traffic sign/0/g' obj/*.txt
! pwd<jupyter_output>/content/dataset<jupyter_text>change annotation<jupyter_code>import os 
filelist = os.listdir('obj')
textfilelist = list(filter(lambda x : '.txt' in x, filelist))
import cv2
for textfile in textfilelist :
  file = open("obj/"+textfile,mode='r+')
  all_of_it = file.read()
  lines = all_of_it.split('\n')[:-1]  
  file.close()
  
  im = cv2.imread('obj/'+textfile.split('.txt')[0]+'.jpg')
  h, w, c = im.shape
  print(h, w, c)

  new_file = open("obj/"+textfile, "w+")
  for line in lines :
    print(line)
    content = line.split()
    print(content)
    min_x = float(content[1]) 
    min_y = float(content[2])
    max_x = float(content[3])
    max_y = float(content[4])
    content[1] = str(float(min_x/w))
    content[2] = str(float(min_y/h))
    content[3] = str(float(max_x/w))
    content[4] = str(float(max_y/h))
    print(content)
    new_line = " ".join(content)+"\n"
    print(new_line)
    new_file.write(new_line)
  new_file.close()
  # break
!cp -r obj ../darknet/data<jupyter_output><empty_output><jupyter_text>write obj.names<jupyter_code>!echo "Traffic sign" > ../darknet/data/obj.names<jupyter_output><empty_output><jupyter_text>write obj.data<jupyter_code>!echo -e """classes= 1\ntrain  = data/train.txt\nvalid  = data/test.txt\nnames = data/obj.names\nbackup = /content/gdrive/MyDrive/Yolo/yolov3""" > ../darknet/data/obj.data<jupyter_output><empty_output><jupyter_text>make train.txt<jupyter_code>% pwd
% cd ..
import os
image_files = []
os.chdir(os.path.join("dataset", "obj"))
for filename in os.listdir(os.getcwd()):
    if filename.endswith(".jpg"):
        image_files.append("data/obj/" + filename)
os.chdir("..")
% pwd
with open("../darknet/data/train.txt", "w") as outfile:
    for image in image_files:
        outfile.write(image)
        outfile.write("\n")
    outfile.close()
os.chdir("..")<jupyter_output><empty_output><jupyter_text>make cfg file<jupyter_code>% cd darknet
! cp cfg/yolov3.cfg cfg/yolov3_traffic_signal.cfg
!sed -i 's/batch=1/batch=8/' cfg/yolov3_traffic_signal.cfg
!sed -i 's/subdivisions=1/subdivisions=1/' cfg/yolov3_traffic_signal.cfg
!sed -i 's/max_batches = 500200/max_batches = 2200/' cfg/yolov3_traffic_signal.cfg
!sed -i 's/steps=400000,450000/steps=1600,1800/' cfg/yolov3_traffic_signal.cfg
!sed -i 's/filters=255/filters=18/g' cfg/yolov3_traffic_signal.cfg
!sed -i 's/classes=80/classes=1/g' cfg/yolov3_traffic_signal.cfg<jupyter_output>/content/darknet<jupyter_text>build darknet<jupyter_code># change makefile to have GPU and OPENCV enabled
!sed -i 's/OPENCV=0/OPENCV=1/' Makefile
!sed -i 's/GPU=0/GPU=1/' Makefile
!sed -i 's/CUDNN=0/CUDNN=1/' Makefile

# verify CUDA
!/usr/local/cuda/bin/nvcc --version

# make darknet (build)
!make<jupyter_output>nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Mon_Oct_12_20:09:46_PDT_2020
Cuda compilation tools, release 11.1, V11.1.105
Build cuda_11.1.TC455_06.29190527_0
mkdir -p ./obj/
mkdir -p backup
chmod +x *.sh
g++ -std=c++11 -std=c++11 -Iinclude/ -I3rdparty/stb/include -DOPENCV `pkg-config --cflags opencv4 2> /dev/null || pkg-config --cflags opencv` -DGPU -I/usr/local/cuda/include/ -DCUDNN -Wall -Wfatal-errors -Wno-unused-result -Wno-unknown-pragmas -fPIC -Ofast -DOPENCV -DGPU -DCUDNN -I/usr/local/cudnn/include -c ./src/image_opencv.cpp -o obj/image_opencv.o
[01m[K./src/image_opencv.cpp:[m[K In function ‘[01m[Kvoid draw_detections_cv_v3(void**, detection*, int, float, char**, image**, int, int)[m[K’:
[01m[K./src/image_opencv.cpp:946:23:[m[K [01;35m[Kwarning: [m[Kvariable ‘[01m[Krgb[m[K’ set but not used [[01;35m[K-Wunused-but-set-variable[m[K]
                 float [01;35m[Krgb[m[K[3];
                       [01;35m[[...]<jupyter_text>Download Pre-trained Weight<jupyter_code># get yolov3 pretrained coco dataset weights
!wget https://pjreddie.com/media/files/yolov3.weights
# upload pretrained convolutional layer weights
!wget http://pjreddie.com/media/files/darknet53.conv.74


# define helper functions
def imShow(path):
  import cv2
  import matplotlib.pyplot as plt
  %matplotlib inline

  image = cv2.imread(path)
  height, width = image.shape[:2]
  resized_image = cv2.resize(image,(3*width, 3*height), interpolation = cv2.INTER_CUBIC)

  fig = plt.gcf()
  fig.set_size_inches(18, 10)
  plt.axis("off")
  plt.imshow(cv2.cvtColor(resized_image, cv2.COLOR_BGR2RGB))
  plt.show()

# use this to upload files
def upload():
  from google.colab import files
  uploaded = files.upload() 
  for name, data in uploaded.items():
    with open(name, 'wb') as f:
      f.write(data)
      print ('saved file', name)

# use this to download a file  
def download(path):
  from google.colab import files
  files.download(path)<jupyter_output><empty_output><jupyter_text>training with my data<jupyter_code># train your custom detector
!./darknet detector train data/obj.data cfg/yolov3_traffic_signal.cfg darknet53.conv.74 -dont_show<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16073047532703016, 'fraction_numerical': 0.043258645253205545, 'mean_word_length': 4.480482611781405, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 46, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '501579', 'license': 'Apache-2.0', 'n_tokens_mistral': 3237, 'n_tokens_neox': 2976, 'n_words': 621, 'path': 'Yolo_Trafiic_Sign_Detection.ipynb', 'repo_name': 'JacobYim/Traffic-Sign-Detection-Dataset', 'size': '7721'}