Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added custom object detection folder with all required files #8048

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions custom_data/custom.names
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Insulator
5,654 changes: 5,654 additions & 0 deletions custom_data/custom_object_darknet.ipynb

Large diffs are not rendered by default.

95 changes: 95 additions & 0 deletions custom_data/custom_object_darknet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# -*- coding: utf-8 -*-
"""custom_object_darknet

Automatically generated by Colaboratory.

Original file is located at
https://colab.research.google.com/drive/1W-Vc-pp7NMYxP7Lzj7YrbeMYsLgxGT_C

Mounting the google drive
"""

from google.colab import drive
drive.mount('/content/drive')

"""Navigating to required directory"""

# Commented out IPython magic to ensure Python compatibility.
# %cd drive
# %cd MyDrive
# %cd "Vidrona- Object Detection"
# %cd darknet

"""Printing contents of current directory"""

!ls

"""Make command to run makefile"""

# !make

"""Command to give permissions"""

!chmod +x ./darknet

"""Command to run yolov3 train file (original command unmodified)"""

!./darknet detector train custom_data/detector.data custom_data/cfg/yolov3-custom.cfg darknet53.conv.74 -dont_show

"""Command to continue training from a particular weight"""

!./darknet detector train custom_data/detector.data custom_data/cfg/yolov3-custom.cfg backup/yolov3-custom_3600.weights -dont_show

"""Command for prediction-"""

!./darknet detector test custom_data/detector.data custom_data/cfg/yolov3-custom2.cfg backup/yolov3-custom2_2000.weights custom_data/test/test1/DJI_0528_JPG.rf.f271180da4406abec44e765177c81dc8.jpg -dont_show
from IPython.display import Image
from google.colab import files
files.download("predictions.jpg")
Image('predictions.jpg')

"""Command to download weights"""

# !wget https://pjreddie.com/media/files/yolov3.weights

# !wget https://pjreddie.com/media/files/darknet53.conv.74

"""Code snippet to make train.txt and test.txt files which are required to run model"""

import random
import os
import subprocess
import sys

def split_data_set(image_dir):

f_val = open("custom_data/test.txt", 'w')
f_train = open("custom_data/train.txt", 'w')

path, dirs, files = next(os.walk(image_dir))
data_size = len(files)

ind = 0
data_test_size = int(0.1 * data_size)
test_array = random.sample(range(data_size), k=data_test_size)

for f in os.listdir(image_dir):
if(f.split(".")[3] == "jpg"):
f_train.write("custom_data/images"+'/'+f+'\n')

split_data_set("custom_data/upload")

WINDOWS_LINE_ENDING = b'\r\n'
UNIX_LINE_ENDING = b'\n'

sou="custom_data/train.txt"
file_path = sou

with open(file_path, 'rb') as open_file:
content = open_file.read()

content = content.replace(WINDOWS_LINE_ENDING, UNIX_LINE_ENDING)

with open(file_path, 'wb') as open_file:
open_file.write(content)

5 changes: 5 additions & 0 deletions custom_data/detector.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
classes=1
train=custom_data/train.txt
valid=custom_data/test.txt
names=custom_data/custom.names
backup=backup/
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0 0.43017578125 0.4809027777777778 0.05908203125 0.2421875
0 0.3251953125 0.5130208333333334 0.14892578125 0.1892361111111111
0 0.544921875 0.3967013888888889 0.0234375 0.13802083333333334
6 changes: 6 additions & 0 deletions custom_data/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/content/darknet/custom_data/images/DJI_0011_JPG.rf.ae69c3af8ff170d71d775a99c8e3d5b1.jpg
/content/darknet/custom_data/images/DJI_0024_JPG.rf.ef832ad5dcf77f947087f263230787e4.jpg
/content/darknet/custom_data/images/DJI_0179_JPG.rf.bb08572af787380d95ca62b056f4772a.jpg
/content/darknet/custom_data/images/DJI_0179_JPG.rf.fd6eca573ba33b9cbdac350d27caa8be.jpg
/content/darknet/custom_data/images/DJI_0181_JPG.rf.7515cd0fe267cf19e134c62d1c8ac084.jpg
/content/darknet/custom_data/images/DJI_0422_JPG.rf.e1a2b8cd5badad0830c37f690200823e.jpg
1 change: 1 addition & 0 deletions custom_data/train.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
custom_data/images/DJI_0012_JPG.rf.0214a043549d470e288a0e7be080710c.jpg