Created
January 22, 2020 11:19
-
-
Save e96031413/10f10cae4a554273d3ff208e106cbf3f to your computer and use it in GitHub Desktop.
How to split YOLOv3 data set to training set and validation set?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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