-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfix_test_set.py
66 lines (54 loc) · 2.26 KB
/
fix_test_set.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
# # Copyright (c) 2019.
# # AAU, Student project group sw504e19, 2019.
# # Use this as reference to coding conventions in Python: https://github.com/kengz/python
import pandas as pd
import csv
import os
from classification.definitions import SIGN_TO_ID_SWITCHER, ID_TO_SIGN_SWITCHER
# classIds = [0, 1, 2, 3, 4, 5]
# import os
# import csv
# import pandas as pd
# image_dir_path = 'path/to/image/'
# input_csv_path = 'path/to/csv.csv'
# output_csv_path = 'path/to/new_csv.csv'
#
# with open(output_csv_path, mode='w', newline='') as output_file:
# writer = csv.writer(output_file, delimiter=';')
# writer.writerow(['Filename', 'ClassId'])
#
# input_file = pd.read_csv(input_csv_path, sep=';')
# for filename, class_id in zip(list(input_file['Filename']), list(input_file['ClassId'])):
# if os.path.exists(image_dir_path + filename):
# writer.writerow([filename, class_id])
# training_images_path = 'test_data/training_images/'
# training_output_path = 'test_data/training_images/'
# test_images_path = 'test_data/test_images/'
# input_csv_path = 'test_data/test_file.csv'
# test_output_csv_path = 'test_data/test_file_new.csv'
#
#
# with open(test_output_csv_path, mode='w', newline='') as output_csv_file:
# writer = csv.writer(output_csv_file, delimiter=';')
# writer.writerow(['Filename', 'ClassId'])
#
# test = pd.read_csv(input_csv_path, sep=';')
# pic_count = 0
# for filename, class_id in zip(list(test['Filename']), list(test['ClassId'])):
# writer.writerow([filename, SIGN_TO_ID_SWITCHER.get(class_id)])
input_images_path = 'test_data/training_images_binary/'
output_path = 'test_data/val_images_binary/'
# test_images_path = 'test_data/test_images/'
input_csv_path = 'test_data/trainingdata_file.csv'
# test_output_csv_path = 'test_data/test_file.csv'
test = pd.read_csv(input_csv_path, sep=';')
count = 0
for filename, class_id in zip(list(test['Filename']), list(test['ClassId'])):
input_path = input_images_path + str(class_id) + '/' + filename
if os.path.exists(input_path):
count += 1
if count % 5 == 0:
output_dir = output_path + str(class_id) + '/'
os.makedirs(output_dir, exist_ok=True)
os.replace(input_path,
output_dir + filename)