Skip to content

Instantly share code, notes, and snippets.

@e96031413
Created January 22, 2020 11:19
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 e96031413/10f10cae4a554273d3ff208e106cbf3f to your computer and use it in GitHub Desktop.
Save e96031413/10f10cae4a554273d3ff208e106cbf3f to your computer and use it in GitHub Desktop.
How to split YOLOv3 data set to training set and validation set?
import glob
import os
import numpy as np
import sys
current_dir = "./data/dataset/images"
split_pct = 10;
file_train = open("data/dataset/train.txt", "w")
file_val = open("data/dataset/val.txt", "w")
counter = 1
index_test = round(100 / split_pct)
for pathAndFilename in glob.iglob(os.path.join(current_dir, "*.jpg")):
title, ext = os.path.splitext(os.path.basename(pathAndFilename))
if counter == index_test:
counter = 1
file_val.write(current_dir + "/" + title + '.jpg' + "\n")
else:
file_train.write(current_dir + "/" + title + '.jpg' + "\n")
counter = counter + 1
file_train.close()
file_val.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment