import os
path = "dataset/images/train/"
img_list_path = os.listdir(path)
img_list = [file for file in img_list_path if file.endswith(".jpg")]
print(img_list)
print("\n\n")
from sklearn.model_selection import train_test_split
train_img_list, val_img_list = train_test_split(img_list, test_size=0.2, random_state=2000)
print(len(train_img_list), len(val_img_list))
print("\n\n")
import shutil
for a in val_img_list:
filename = a
src = 'dataset/images/train/'
dir = 'dataset/images/val/'
shutil.move(src + filename, dir + filename)
print(len(val_img_list),val_img_list)
print("\n\n")
val_txt_list=[]
for a in val_img_list:
temp = a.replace("jpg","txt")
val_txt_list.append(temp)
print(len(val_txt_list),val_txt_list)
print("\n\n")
for a in val_txt_list:
filename = a
src = 'dataset/labels/train/'
dir = 'dataset/labels/val/'
shutil.move(src + filename, dir + filename)