-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmain.py
108 lines (94 loc) · 4.43 KB
/
main.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# ************************************************************
# Author : Bumsoo Kim, 2017
# Github : https://github.com/meliketoy/cellnet.pytorch
#
# Korea University, Data-Mining Lab
# Deep Convolutional Network Preprocessing Implementation
#
# Module : 1_preprocessor
# Description : main.py
# The main code for data mangement.
# ***********************************************************
import cv2
import os
import sys
import file_function as ff
import config as cf
def print_menu():
print("\nSelect a mode by its name or number.\nType [exit] to terminate.\n")
print("################## [ Options ] ###########################")
print("# Mode 1 'print' : Print names of image data file")
print("# Mode 2 'read' : [original/resized] Read names data")
print("# Mode 3 'resize' : [target_size] Resize & Orgnaize data")
print("# Mode 4 'split' : Create a train-validation split of data")
print("# Mode 5 'count' : Check the distribution of raw data")
print("# Mode 6 'check' : Check the distribution of train/val split")
print("# Mode 7 'aug' : Augment the training data samples")
print("# Mode 8 'meanstd': Return the meanstd value of the training set")
print("# Mode 9 'test' : Preprocess the test data samples")
print("##########################################################")
if __name__ == "__main__":
while(1):
print_menu()
mode = raw_input('\nEnter mode name : ')
##############################################
# @ Module 1 : Print names of image data file
if (mode == 'print' or mode == '1'):
ff.print_all_imgs(cf.data_base)
#############################################
# @ Module 2 : Read all images
elif (mode == 'read' or mode == '2'):
path = raw_input('Enter [original/resized] : ')
if (not path in ['original', 'resized']):
print("[Error] : Please define the mode between [original/resized].")
else:
if(path == 'original'):
ff.read_all_imgs(cf.data_base)
elif(path == 'resized'):
ff.read_all_imgs(cf.resize_dir)
#############################################
# @ Module 3 : Resize and check images
elif (mode == 'resize' or mode == '3'):
ff.check_and_mkdir(cf.resize_base)
target_size = int(raw_input('Enter size : '))
ff.resize_images(cf.data_base, cf.resize_dir, target_size)
# ff.resize_and_contrast(cf.data_base, cf.resize_dir, target_size)
#############################################
# @ Module 4 : Train-Validation split
elif (mode == 'split' or mode == '4'):
ff.check_and_mkdir(cf.split_base)
split_dir = ff.create_train_val_split(cf.resize_dir, cf.split_dir)
print("Train-Validation split directory = " + cf.split_dir)
############################################
# @ Module 5 : Check the dataset
elif (mode == 'count' or mode == '5'):
print("| " + cf.resize_dir.split("/")[-1] + " dataset : ")
ff.count_each_class(cf.resize_dir)
elif (mode == 'check' or mode == '6'):
ff.get_split_info(cf.split_dir)
############################################
# @ Module 6 : Training data augmentation
elif (mode == 'aug' or mode == '7'):
#if (len(sys.argv) < 3):
# print("[Error] : Please define size in the second arguement.")
#else:
ff.aug_train(cf.split_dir, cf.rotate_mode)#sys.argv[2])
#############################################
# @ Module 7 : Retrieve Training data meanstd
elif (mode == 'meanstd' or mode == '8'):
mean = ff.train_mean(cf.split_dir)
std = ff.train_std(cf.split_dir, mean)
print("mean = " + str(mean))
print("std = " + str(std))
#############################################
# @ Module 8 : Preprocess test data
elif (mode == 'test' or mode == '9'):
# [TO DO] : Implement Test Preprocessor
print("[TO DO] : Implement Test Preprocessor")
#############################################
elif (mode == 'exit'):
print("\nGood Bye!\n")
sys.exit(0)
else:
print("[Error] : Wrong input in 'mode name', please enter again.")
#############################################