-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreshuffle_files.py
70 lines (55 loc) · 2.63 KB
/
reshuffle_files.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
import pathlib
import pandas as pd
import shutil
from tqdm import tqdm
def reshuffle_files(folder_name, class_type=''):
test_img_files = pd.Series(list(folder_name.joinpath('test', 'images').glob('*.png')))
valid_img_files = pd.Series(list(folder_name.joinpath('valid', 'images').glob('*.png')))
train_img_files = pd.Series(list(folder_name.joinpath('train', 'images').glob('*.png')))
test_labels_files = pd.Series(list(folder_name.joinpath('test', 'labels').glob('*.txt')))
valid_labels_files = pd.Series(list(folder_name.joinpath('valid', 'labels').glob('*.txt')))
train_labels_files = pd.Series(list(folder_name.joinpath('train', 'labels').glob('*.txt')))
print(folder_name.joinpath('test', 'images').exists())
print('moving test images...')
for test_file in tqdm(test_img_files, total=len(test_img_files)):
try:
shutil.move(test_file, folder_name.joinpath('images', test_file.name))
except Exception as e:
print(e)
print('moving test labels...')
for test_file in tqdm(test_labels_files, total=len(test_labels_files)):
try:
shutil.move(test_file, folder_name.joinpath('labels%s' % class_type, test_file.name))
except Exception as e:
print(e)
print('moving valid images...')
for valid_file in tqdm(valid_img_files, total=len(valid_img_files)):
try:
shutil.move(valid_file, folder_name.joinpath('images', valid_file.name))
except Exception as e:
print(e)
print('moving valid labels...')
for valid_file in tqdm(valid_labels_files, total=len(valid_labels_files)):
try:
shutil.move(valid_file, folder_name.joinpath('labels%s' % class_type, valid_file.name))
except Exception as e:
print(e)
print('moving train images...')
for train_file in tqdm(train_img_files, total=len(train_img_files)):
try:
shutil.move(train_file, folder_name.joinpath('images', train_file.name))
except Exception as e:
print(e)
print('moving train labels...')
for train_file in tqdm(train_labels_files, total=len(train_labels_files)):
try:
shutil.move(train_file, folder_name.joinpath('labels%s' % class_type, train_file.name))
except Exception as e:
print(e)
if __name__ == '__main__':
main_folder = pathlib.Path(input('Where is the folder to reshuffle?'))
class_name = input('class name?')
if class_name != '':
class_name = '_' + class_name
confirm = input('press any key to start, reshuffling to: %s' % class_name)
reshuffle_files(main_folder, class_name)