-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_validation_division.py
73 lines (47 loc) · 2.07 KB
/
test_validation_division.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 15 15:57:36 2024
@author: Rita Saraiva
"""
# %% Creating a clean Slate
from IPython import get_ipython
get_ipython().magic('reset -sf')
import os
import shutil
import numpy as np
import pandas as pd
#Directing to the correct working directory
#%%
TrainData_dir = 'C:\\Users\\ritux\\OneDrive - Danmarks Tekniske Universitet\\Skrivebord\\Hackthon\\delightful_lightbulb\\data\\TrainingSet - Copy\\'
os.chdir(TrainData_dir)
for Project in os.listdir( ): # Project = 'Project1'
os.chdir( TrainData_dir + '\\' + Project )
Objects_df = pd.read_csv(Project+'.csv')
Objects_df['Ind'] = Objects_df.index
# Source path
Mask_Folder = os.getcwd() + '\\' + Project + '.masks'
Files = os.listdir(Mask_Folder)
Valid_Files = []
Test_Files = []
Labels = Objects_df[Objects_df.columns[1]].unique()
for Label in Labels: # Label = Labels[0]
Obj_label_df = Objects_df[Objects_df[Objects_df.columns[1]] == Label]
Idx = np.array(Obj_label_df['Ind'])
Valid = np.random.choice(Idx,round(len(Idx)*0.2), replace=False)
Test = np.setdiff1d(Idx, Valid)
Valid_Files += [Files[i] for i in Valid]
Test_Files += [Files[i] for i in Test]
# Create the new folder to copy the files into
Valid_Mask_Folder = "Valid Data Masks"
os.makedirs(Valid_Mask_Folder, exist_ok=True)
destination = os.getcwd() + '\\' + Valid_Mask_Folder
# Copy each valid file from the source to the destination folder
for file in Valid_Files:
shutil.copy(os.path.join(Mask_Folder, file), os.path.join(Valid_Mask_Folder, file))
# Create the new folder to copy the files into
Test_Mask_Folder = "Test Data Masks"
os.makedirs(Test_Mask_Folder, exist_ok=True)
destination = os.getcwd() + '\\' + Test_Mask_Folder
# Copy each valid file from the source to the destination folder
for file in Test_Files:
shutil.copy(os.path.join(Mask_Folder, file), os.path.join(Test_Mask_Folder, file))