Skip to content

Instantly share code, notes, and snippets.

@AkashiSN
Created December 16, 2019 03:59
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 AkashiSN/c110ae9656a5fb25094560424f03adb4 to your computer and use it in GitHub Desktop.
Save AkashiSN/c110ae9656a5fb25094560424f03adb4 to your computer and use it in GitHub Desktop.
generate yolo training and validation(test)
#!/usr/bin/env python3
import glob, os, sys
# Current directory
data_dir = sys.argv[1]
print(data_dir)
# Percentage of images to be used for the test set
percentage_test = 10
# 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(data_dir, "*.png")):
title, ext = os.path.splitext(os.path.basename(pathAndFilename))
if counter == index_test:
counter = 1
file_test.write(os.path.join(data_dir, title + '.png' + "\n"))
else:
file_train.write(os.path.join(data_dir, title + '.png' + "\n"))
counter += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment