Skip to content

Instantly share code, notes, and snippets.

@thecaffeinedev
Created November 21, 2019 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thecaffeinedev/70cd8778c103d55a3539e820d663697e to your computer and use it in GitHub Desktop.
Save thecaffeinedev/70cd8778c103d55a3539e820d663697e to your computer and use it in GitHub Desktop.
YoloV3 Custom model
import glob, os
# change the path of your images folder
dataset_path = '/home/thecaffeinedev/yolov3/training/images'
# Percentage of images to be used for the test set
percentage_test = 30;
# Create and/or truncate train.txt and test.txt
file_train = open('train.txt', 'w')
file_test = open('test.txt', 'w')
# Populate train.txt and test.txt
counter = 1
index_test = round(100 / percentage_test)
for pathAndFilename in glob.iglob(os.path.join(dataset_path, "*.JPG")):
title, ext = os.path.splitext(os.path.basename(pathAndFilename))
if counter == index_test+1:
counter = 1
file_test.write(dataset_path + "/" + title + '.JPG' + "\n")
else:
file_train.write(dataset_path + "/" + title + '.JPG' + "\n")
counter = counter + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment