Skip to content

Commit c15243e

Browse files
author
Sekhar Roy
committed
result dir added, learning rate fixed
1 parent 1907e9a commit c15243e

14 files changed

+71
-19
lines changed

ReadME_Run_melNET.pdf

95.2 KB
Binary file not shown.

ReadME_Run_melNET.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
09) Set �Python Interpreter� to the new Conda Environment (E.g.:melNET_env)
1212
10) Go to Run >> Run >> melNET
1313
11) Follow the prompt!
14+
15+
N.B.: Follow the provided pdf for more detail
-1.15 KB
Binary file not shown.
-6.89 KB
Binary file not shown.
-1.15 KB
Binary file not shown.
-3.24 KB
Binary file not shown.
-3.72 KB
Binary file not shown.
-3.85 KB
Binary file not shown.
-2.5 KB
Binary file not shown.
-33.7 KB
Binary file not shown.

melNET_augData.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ def file_naming(_img, process_initial, _folder, _set_counter):
285285
if rotationAngle is not None:
286286
# Rotation Code
287287
for angle in range(0, 360, rotationAngle):
288+
"""
289+
# No Artifact Code:
288290
_scaleFactor = 1
289291
(h, w) = _img.shape[:2]
290292
(cX, cY) = (w // 2, h // 2)
@@ -307,6 +309,14 @@ def file_naming(_img, process_initial, _folder, _set_counter):
307309
308310
_imgRotated = cv2.warpAffine(_img, M, (nW, nH), flags=cv2.INTER_LINEAR,
309311
borderMode=cv2.BORDER_REFLECT_101)
312+
"""
313+
# Artifact Code:
314+
dim = _img.shape
315+
_scaleFactor = 1
316+
rotationMatrix = cv2.getRotationMatrix2D((dim[1] / 2, dim[0] / 2), angle, _scaleFactor)
317+
_imgRotated = cv2.warpAffine(_img, rotationMatrix, (dim[1], dim[0]), flags=cv2.INTER_LINEAR,
318+
borderMode=cv2.BORDER_REFLECT_101)
319+
310320
_savingName = dst_root + _folder + "/" + _folder + "_" + str(name_counter) + "_" \
311321
+ process_initial + "_Rot_" + str(angle) + ".jpg"
312322
cv2.imwrite(_savingName, _imgRotated)

melNET_confusion_mat.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,18 @@ def quit_button_applied():
6565
fold_num = 5
6666
if five_fold:
6767
for fold in range(fold_num):
68-
root = os.getcwd() + "/aug_Data/Five_Fold_(Aug)/Fold_"+str(fold+1)+"/Test"
68+
root = os.getcwd() + "/Results/Fold_0"+str(fold+1)
6969
result_path = root + "/_result.csv"
7070
conf_mat_path = root + "/conf_mat.csv"
7171
error_path = root + "/error_analysis.csv"
7272
err_thresh = 70
7373
conf_mat_make(result_path, conf_mat_path, error_path, err_thresh, pos_class, neg_class)
7474

7575
else:
76-
result_path = os.getcwd() + "/aug_Data/Single_Fold_(Aug)/Test/_result.csv"
77-
conf_mat_path = os.getcwd() + "/aug_Data/Single_Fold_(Aug)/Test/conf_mat.csv"
78-
error_path = os.getcwd() + "/aug_Data/Single_Fold_(Aug)/Test/error_analysis.csv"
76+
root = os.getcwd() + "/Results/Fold_01"
77+
result_path = root + "/_result.csv"
78+
conf_mat_path = root + "/conf_mat.csv"
79+
error_path = root + "/error_analysis.csv"
7980
err_thresh = 70
8081
conf_mat_make(result_path, conf_mat_path, error_path, err_thresh, pos_class, neg_class)
8182

melNET_test.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,19 @@ def quit_button_applied():
5353
accessories_path = os.getcwd() + "/Accessories" # same name in malNET_train_src
5454
aug_data_path = os.getcwd() + "/aug_Data"
5555

56+
result_root = os.getcwd() + "/Results"
57+
if tf.gfile.Exists(result_root):
58+
tf.gfile.DeleteRecursively(result_root)
59+
tf.gfile.MakeDirs(result_root)
60+
5661
# Starting Test
5762
if tf.gfile.Exists(accessories_path) and tf.gfile.Exists(aug_data_path):
5863
if five_fold:
5964
fold_num = 5 # Five-Fold
6065
root = aug_data_path + "/Five_Fold_(Aug)"
6166
for num in range(fold_num):
67+
result_path = result_root + "/Fold_0" + str(num+1)
68+
tf.gfile.MakeDirs(result_path)
6269
test_path = root + "/Fold_" + str(num+1) + "/Test"
6370
weight_path = accessories_path + "/Five_Fold_Trained/Trained_Fold_" + str(num+1)
6471
delete_all_csv(test_path) # Deleting old results
@@ -68,14 +75,16 @@ def quit_button_applied():
6875
ground_truth = re.sub(r'[^a-z0-9]+', ' ', str(folder).lower())
6976
class_path = test_path + "/" + folder
7077
classes = melNET_test_src.main(class_path, weight_path, save_performance, show_detection,
71-
ground_truth, test_path)
78+
ground_truth, result_path)
7279
if save_performance:
73-
merge_csv(test_path)
80+
merge_csv(result_path)
7481
else:
7582
print("Either [Test Data] or [Weight] is NOT available!")
7683
exit()
7784

7885
else: # Single-Fold
86+
result_path = result_root + "/Fold_01"
87+
tf.gfile.MakeDirs(result_path)
7988
root = aug_data_path + "/Single_Fold_(Aug)"
8089
test_path = root + "/Test"
8190
weight_path = accessories_path + "/Single_Fold_Trained"
@@ -86,7 +95,7 @@ def quit_button_applied():
8695
ground_truth = re.sub(r'[^a-z0-9]+', ' ', str(folder).lower())
8796
class_path = test_path + "/" + folder
8897
classes = melNET_test_src.main(class_path, weight_path, save_performance, show_detection,
89-
ground_truth, test_path)
98+
ground_truth, result_path)
9099
if save_performance:
91100
merge_csv(test_path)
92101
else:

melNET_train.py

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,16 @@ def quit_button_applied():
2828

2929
# Variables
3030
_five_fold = BooleanVar()
31-
_learning_rate = IntVar(0)
31+
_learning_rate1 = BooleanVar()
32+
_learning_rate2 = BooleanVar()
33+
_learning_rate3 = BooleanVar()
34+
_learning_rate4 = BooleanVar()
3235
_batch_size = IntVar(0)
3336
_iteration = IntVar(0)
3437

3538
# UI
3639
Checkbutton(root, text="Five-Fold (Default: Single-Fold)", variable=_five_fold).grid(row=1, column=3, sticky=W)
3740

38-
Label(root, text="Learning Rate: ").grid(row=2, column=0)
39-
Label(root, text="(Default: 0.01)").grid(row=3, column=0)
40-
Entry(root, textvariable=_learning_rate).grid(row=2, column=1)
41-
4241
Label(root, text="Batch Size: ").grid(row=4, column=0)
4342
Label(root, text="(Default: 100)").grid(row=5, column=0)
4443
Entry(root, textvariable=_batch_size).grid(row=4, column=1)
@@ -47,32 +46,62 @@ def quit_button_applied():
4746
Label(root, text="(Default: 4000)").grid(row=7, column=0)
4847
Entry(root, textvariable=_iteration).grid(row=6, column=1)
4948

50-
Button(root, text="Quit", command=quit_button_applied, width=15).grid(row=8, column=2, sticky=W)
51-
Button(root, text="Apply", command=apply_button_applied, width=15).grid(row=8, column=3, sticky=W)
49+
Checkbutton(root, text="Learning Rate: 0.005", variable=_learning_rate1).grid(row=8, column=0, sticky=W)
50+
Checkbutton(root, text="Learning Rate: 0.001", variable=_learning_rate2).grid(row=9, column=0, sticky=W)
51+
Checkbutton(root, text="Learning Rate: 0.01", variable=_learning_rate3).grid(row=10, column=0, sticky=W)
52+
Checkbutton(root, text="Learning Rate: 0.015", variable=_learning_rate4).grid(row=11, column=0, sticky=W)
53+
Label(root, text="If NONE or more than one is chosen, default Learning Rate is 0.01").grid(row=12, column=0)
54+
55+
Button(root, text="Quit", command=quit_button_applied, width=15).grid(row=14, column=2, sticky=W)
56+
Button(root, text="Apply", command=apply_button_applied, width=15).grid(row=14, column=3, sticky=W)
5257

5358
root.mainloop()
5459

5560
if applied:
5661
five_fold = _five_fold.get()
57-
learning_rate = _learning_rate.get()
62+
63+
learning_rate1 = _learning_rate1.get()
64+
learning_rate2 = _learning_rate2.get()
65+
learning_rate3 = _learning_rate3.get()
66+
learning_rate4 = _learning_rate4.get()
67+
5868
batch_size = _batch_size.get()
5969
iteration = _iteration.get()
6070

6171
# Default Values
62-
if learning_rate is 0:
63-
learning_rate = 0.01
6472
if batch_size is 0:
6573
batch_size = 100
6674
if iteration is 0:
6775
iteration = 4000
6876

77+
if learning_rate1:
78+
learning_rate = 0.005
79+
elif learning_rate2:
80+
learning_rate = 0.001
81+
elif learning_rate3:
82+
learning_rate = 0.01
83+
elif learning_rate4:
84+
learning_rate = 0.015
85+
86+
learning_rate_sum = int(learning_rate1) + int(learning_rate2) + int(learning_rate3) + int(learning_rate4)
87+
88+
if learning_rate_sum > 1 or learning_rate_sum == 0:
89+
learning_rate = 0.01
90+
6991
# Managing directories
7092
accessories_path = os.getcwd() + "/Accessories" # same name in malNET_train_src
7193
if tf.gfile.Exists(accessories_path):
7294
tf.gfile.DeleteRecursively(accessories_path)
7395

7496
tf.gfile.MakeDirs(accessories_path)
7597

98+
# Save hyper-parameters
99+
hyper_path = accessories_path + "/hyper_parameters.csv"
100+
hyper = open(hyper_path, 'w')
101+
hyper.write('Learning Rate, Iterations, Batch Size, Five-Fold\n' + str(learning_rate) + ',' + str(iteration) +
102+
',' + str(batch_size) + ',' + str(five_fold))
103+
hyper.close()
104+
76105
# Getting Train-data directory
77106
aug_data_path = os.getcwd() + "/aug_Data"
78107
if tf.gfile.Exists(aug_data_path):
@@ -84,7 +113,8 @@ def quit_button_applied():
84113
weight_path = accessories_path + "/Five_Fold_Trained/Trained_Fold_" + str(num+1)
85114
tf.gfile.MakeDirs(weight_path)
86115
if tf.gfile.Exists(train_path):
87-
melNET_train_src.main(train_path, weight_path, learning_rate, batch_size, iteration)
116+
melNET_train_src.main(train_path, weight_path, float(learning_rate), int(batch_size),
117+
int(iteration))
88118
else:
89119
print("Training Data is NOT available!")
90120
else: # Single-Fold
@@ -93,7 +123,7 @@ def quit_button_applied():
93123
weight_path = accessories_path + "/Single_Fold_Trained"
94124
tf.gfile.MakeDirs(weight_path)
95125
if tf.gfile.Exists(train_path):
96-
melNET_train_src.main(train_path, weight_path, learning_rate, batch_size, iteration)
126+
melNET_train_src.main(train_path, weight_path, float(learning_rate), int(batch_size), int(iteration))
97127
else:
98128
print("Training Data is NOT available!")
99129
else:

0 commit comments

Comments
 (0)