pyerualjetwork 2.6.3__py3-none-any.whl → 2.6.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- plan/plan.py +66 -137
- pyerualjetwork-2.6.5.dist-info/METADATA +8 -0
- pyerualjetwork-2.6.5.dist-info/RECORD +6 -0
- pyerualjetwork-2.6.3.dist-info/METADATA +0 -8
- pyerualjetwork-2.6.3.dist-info/RECORD +0 -6
- {pyerualjetwork-2.6.3.dist-info → pyerualjetwork-2.6.5.dist-info}/WHEEL +0 -0
- {pyerualjetwork-2.6.3.dist-info → pyerualjetwork-2.6.5.dist-info}/top_level.txt +0 -0
plan/plan.py
CHANGED
@@ -15,6 +15,7 @@ import math
|
|
15
15
|
from scipy.special import expit, softmax
|
16
16
|
import matplotlib.pyplot as plt
|
17
17
|
import seaborn as sns
|
18
|
+
from tqdm import tqdm
|
18
19
|
|
19
20
|
# BUILD -----
|
20
21
|
|
@@ -25,7 +26,6 @@ def fit(
|
|
25
26
|
show_training,
|
26
27
|
show_count= None,
|
27
28
|
val= None,
|
28
|
-
val_count= None,
|
29
29
|
x_val= None,
|
30
30
|
y_val= None,
|
31
31
|
activation_potentiation=None # (float): Input activation_potentiation (optional)
|
@@ -39,7 +39,7 @@ def fit(
|
|
39
39
|
y_train (list[num]): List of target labels. (one hot encoded)
|
40
40
|
show_training (bool, str): True, None or'final'
|
41
41
|
show_count (None, int): How many learning steps in total will be displayed in a single figure? (Adjust according to your hardware) Default: 10 (optional)
|
42
|
-
val (None or
|
42
|
+
val (None, True or 'final'): validation in training process ? None, True or 'final' Default: None
|
43
43
|
val_count (None, int): After how many examples learned will an accuracy test be performed? Default: 0.1 (%10) (optional)
|
44
44
|
x_val (list[num]): List of validation data. (optional) Default: x_train
|
45
45
|
y_val (list[num]): (list[num]): List of target labels. (one hot encoded) (optional) Default: y_train
|
@@ -60,14 +60,10 @@ def fit(
|
|
60
60
|
x_val = x_train
|
61
61
|
y_val = y_train
|
62
62
|
|
63
|
-
if val == True
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
if val == True and val_count != None:
|
63
|
+
if val == True or val == 'final':
|
64
|
+
|
65
|
+
val_bar = tqdm(total=1, desc="Training / Validating Accuracy", ncols=120)
|
68
66
|
|
69
|
-
val_count = int(len(x_train) * val_count)
|
70
|
-
val_count_copy = val_count
|
71
67
|
|
72
68
|
if show_count == None:
|
73
69
|
|
@@ -89,25 +85,23 @@ def fit(
|
|
89
85
|
|
90
86
|
neurons = [len(class_count), len(class_count)]
|
91
87
|
layers = ['fex']
|
92
|
-
val_list = [
|
88
|
+
val_list = []
|
93
89
|
|
94
90
|
x_train[0] = np.array(x_train[0])
|
95
91
|
x_train[0] = x_train[0].ravel()
|
96
92
|
x_train_size = len(x_train[0])
|
97
93
|
|
98
|
-
|
99
|
-
len(layers) - 1, len(class_count), neurons, x_train_size)
|
94
|
+
STPW = weight_identification(
|
95
|
+
len(layers) - 1, len(class_count), neurons, x_train_size) # STPW = SHORT TIME POTENTIATION WEIGHT
|
96
|
+
|
97
|
+
LTPW = [1] * len(STPW) # LTPW = LONG TIME POTENTIATION WEIGHT
|
100
98
|
|
101
|
-
trained_W = [1] * len(W)
|
102
|
-
print(Fore.GREEN + "Train Started with 0 ERROR" + Style.RESET_ALL)
|
103
|
-
start_time = time.time()
|
104
99
|
y = decode_one_hot(y_train)
|
105
100
|
|
106
101
|
for index, inp in enumerate(x_train):
|
107
|
-
|
102
|
+
|
108
103
|
progress = index / len(x_train) * 100
|
109
104
|
|
110
|
-
uni_start_time = time.time()
|
111
105
|
inp = np.array(inp)
|
112
106
|
inp = inp.ravel()
|
113
107
|
|
@@ -123,48 +117,37 @@ def fit(
|
|
123
117
|
neural_layer = normalization(neural_layer)
|
124
118
|
|
125
119
|
if Layer == 'fex':
|
126
|
-
|
120
|
+
STPW[Lindex] = fex(neural_layer, STPW[Lindex], True, y[index], activation_potentiation)
|
127
121
|
|
128
|
-
for i, w in enumerate(
|
129
|
-
|
122
|
+
for i, w in enumerate(STPW):
|
123
|
+
LTPW[i] = LTPW[i] + w
|
130
124
|
|
131
125
|
|
132
126
|
if val == True:
|
127
|
+
|
128
|
+
if show_training == True:
|
129
|
+
try:
|
130
|
+
plt.close(fig)
|
133
131
|
|
134
|
-
|
135
|
-
|
136
|
-
if show_training == True:
|
137
|
-
try:
|
138
|
-
plt.close(fig)
|
139
|
-
|
140
|
-
except:
|
141
|
-
pass
|
142
|
-
|
143
|
-
val_count += val_count_copy
|
144
|
-
|
145
|
-
layers.append('cat')
|
146
|
-
trained_W.append(np.eye(len(class_count)))
|
147
|
-
|
148
|
-
validation_model = evaluate(x_val, y_val, None, trained_W)
|
149
|
-
|
150
|
-
layers.pop()
|
151
|
-
trained_W.pop()
|
152
|
-
|
153
|
-
val_acc = validation_model[get_acc()]
|
132
|
+
except:
|
133
|
+
pass
|
154
134
|
|
155
|
-
|
135
|
+
validation_model = evaluate(x_val, y_val, None, LTPW, activation_potentiation, None)
|
136
|
+
|
137
|
+
val_acc = validation_model[get_acc()]
|
156
138
|
|
139
|
+
val_list.append(val_acc)
|
140
|
+
|
141
|
+
if index == 0:
|
142
|
+
|
143
|
+
val_bar.update(val_acc)
|
144
|
+
|
145
|
+
if index != 0:
|
157
146
|
|
158
|
-
|
159
|
-
color='r')
|
147
|
+
val_acc = val_acc - val_list[index - 1]
|
160
148
|
|
161
|
-
|
162
|
-
|
163
|
-
plt.xlabel('Learning Progress')
|
164
|
-
plt.ylabel('Accuracy')
|
165
|
-
plt.ylim(0, 1)
|
166
|
-
plt.draw()
|
167
|
-
plt.pause(0.1)
|
149
|
+
val_bar.update(val_acc)
|
150
|
+
|
168
151
|
|
169
152
|
if show_training == True:
|
170
153
|
|
@@ -220,21 +203,6 @@ def fit(
|
|
220
203
|
W = weight_identification(
|
221
204
|
len(layers) - 1, len(class_count), neurons, x_train_size)
|
222
205
|
|
223
|
-
uni_end_time = time.time()
|
224
|
-
|
225
|
-
calculating_est = round(
|
226
|
-
(uni_end_time - uni_start_time) * (len(x_train) - index), 3)
|
227
|
-
|
228
|
-
if calculating_est < 60:
|
229
|
-
print('\rest......(sec):', calculating_est, '\n', end="")
|
230
|
-
|
231
|
-
elif calculating_est > 60 and calculating_est < 3600:
|
232
|
-
print('\rest......(min):', calculating_est/60, '\n', end="")
|
233
|
-
|
234
|
-
elif calculating_est > 3600:
|
235
|
-
print('\rest......(h):', calculating_est/3600, '\n', end="")
|
236
|
-
|
237
|
-
print('\rTraining: ', index, "/", len(x_train), "\n", end="")
|
238
206
|
|
239
207
|
if show_training == 'final':
|
240
208
|
|
@@ -257,26 +225,18 @@ def fit(
|
|
257
225
|
plt.pause(0.1)
|
258
226
|
|
259
227
|
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
if calculating_est < 60:
|
267
|
-
print('Total training time(sec): ', calculating_est)
|
268
|
-
|
269
|
-
elif calculating_est > 60 and calculating_est < 3600:
|
270
|
-
print('Total training time(min): ', calculating_est/60)
|
271
|
-
|
272
|
-
elif calculating_est > 3600:
|
273
|
-
print('Total training time(h): ', calculating_est/3600)
|
228
|
+
if val == 'final':
|
229
|
+
|
230
|
+
validation_model = evaluate(x_val, y_val, None, LTPW, activation_potentiation, None)
|
231
|
+
|
232
|
+
val_acc = validation_model[get_acc()]
|
274
233
|
|
275
|
-
|
276
|
-
|
234
|
+
val_list.append(val_acc)
|
235
|
+
|
236
|
+
val_bar.update(val_acc)
|
277
237
|
|
278
238
|
|
279
|
-
return
|
239
|
+
return LTPW
|
280
240
|
|
281
241
|
# FUNCTIONS -----
|
282
242
|
|
@@ -491,7 +451,8 @@ def evaluate(
|
|
491
451
|
y_test, # list[num]: Test labels.
|
492
452
|
show_metrices, # show_metrices (bool): (True or False)
|
493
453
|
W, # list[num]: Weight matrix list of the neural network.
|
494
|
-
activation_potentiation=None # activation_potentiation (float or None): Threshold value for comparison. (optional)
|
454
|
+
activation_potentiation=None, # activation_potentiation (float or None): Threshold value for comparison. (optional)
|
455
|
+
acc_bar_status = True
|
495
456
|
) -> tuple:
|
496
457
|
infoTestModel = """
|
497
458
|
Tests the neural network model with the given test data.
|
@@ -502,12 +463,13 @@ def evaluate(
|
|
502
463
|
show_metrices (bool): (True or False)
|
503
464
|
W (list[num]): Weight matrix list of the neural network.
|
504
465
|
activation_potentiation (float or None): Threshold value for comparison. (optional)
|
466
|
+
acc_bar_status (bool): Loading bar for accuracy (True or None)
|
505
467
|
|
506
468
|
Returns:
|
507
469
|
tuple: A tuple containing the predicted labels and the accuracy of the model.
|
508
470
|
"""
|
509
471
|
|
510
|
-
layers = ['fex'
|
472
|
+
layers = ['fex']
|
511
473
|
|
512
474
|
try:
|
513
475
|
Wc = [0] * len(W) # Wc = Weight copy
|
@@ -518,9 +480,10 @@ def evaluate(
|
|
518
480
|
for i, w in enumerate(W):
|
519
481
|
Wc[i] = np.copy(w)
|
520
482
|
print('\rCopying weights.....', i+1, '/', len(W), end="")
|
521
|
-
|
522
|
-
|
523
|
-
|
483
|
+
|
484
|
+
# print(Fore.GREEN + "\n\nTest Started with 0 ERROR\n" + Style.RESET_ALL)
|
485
|
+
if acc_bar_status == True:
|
486
|
+
acc_bar = tqdm(total=1, desc="Test Accuracy", ncols=75)
|
524
487
|
for inpIndex, Input in enumerate(x_test):
|
525
488
|
Input = np.array(Input)
|
526
489
|
Input = Input.ravel()
|
@@ -533,8 +496,7 @@ def evaluate(
|
|
533
496
|
|
534
497
|
if Layer == 'fex':
|
535
498
|
neural_layer = fex(neural_layer, W[index], False, None, activation_potentiation)
|
536
|
-
|
537
|
-
neural_layer = np.dot(W[index], neural_layer)
|
499
|
+
|
538
500
|
|
539
501
|
for i, w in enumerate(Wc):
|
540
502
|
W[i] = np.copy(w)
|
@@ -543,56 +505,25 @@ def evaluate(
|
|
543
505
|
if RealOutput == PredictedOutput:
|
544
506
|
true += 1
|
545
507
|
acc = true / len(y_test)
|
546
|
-
if show_metrices == True:
|
547
|
-
acc_list.append(acc)
|
548
|
-
y_preds[inpIndex] = PredictedOutput
|
549
508
|
|
550
|
-
uni_end_time = time.time()
|
551
|
-
|
552
|
-
calculating_est = round(
|
553
|
-
(uni_end_time - uni_start_time) * (len(x_test) - inpIndex), 3)
|
554
509
|
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
510
|
+
acc_list.append(acc)
|
511
|
+
y_preds[inpIndex] = PredictedOutput
|
512
|
+
|
513
|
+
if acc_bar_status == True:
|
514
|
+
if inpIndex == 0:
|
515
|
+
acc_bar.update(acc)
|
516
|
+
|
517
|
+
else:
|
518
|
+
acc = acc - acc_list[inpIndex - 1]
|
519
|
+
acc_bar.update(acc)
|
520
|
+
|
566
521
|
if show_metrices == True:
|
567
522
|
plot_evaluate(y_test, y_preds, acc_list)
|
568
523
|
|
569
|
-
|
524
|
+
|
570
525
|
for i, w in enumerate(Wc):
|
571
526
|
W[i] = np.copy(w)
|
572
|
-
|
573
|
-
calculating_est = round(EndTime - start_time, 2)
|
574
|
-
|
575
|
-
print(Fore.GREEN + "\nTest Finished with 0 ERROR\n")
|
576
|
-
|
577
|
-
if calculating_est < 60:
|
578
|
-
print('Total testing time(sec): ', calculating_est)
|
579
|
-
|
580
|
-
elif calculating_est > 60 and calculating_est < 3600:
|
581
|
-
print('Total testing time(min): ', calculating_est/60)
|
582
|
-
|
583
|
-
elif calculating_est > 3600:
|
584
|
-
print('Total testing time(h): ', calculating_est/3600)
|
585
|
-
|
586
|
-
if acc >= 0.8:
|
587
|
-
print(Fore.GREEN + '\nTotal Test accuracy: ',
|
588
|
-
acc, '\n' + Style.RESET_ALL)
|
589
|
-
|
590
|
-
elif acc < 0.8 and acc > 0.6:
|
591
|
-
print(Fore.MAGENTA + '\nTotal Test accuracy: ',
|
592
|
-
acc, '\n' + Style.RESET_ALL)
|
593
|
-
|
594
|
-
elif acc <= 0.6:
|
595
|
-
print(Fore.RED + '\nTotal Test accuracy: ', acc, '\n' + Style.RESET_ALL)
|
596
527
|
|
597
528
|
except:
|
598
529
|
|
@@ -656,8 +587,6 @@ def multiple_evaluate(
|
|
656
587
|
|
657
588
|
if Layer == 'fex':
|
658
589
|
neural_layer = fex(neural_layer, W[index], False, None, activation_potentiation)
|
659
|
-
elif Layer == 'cat':
|
660
|
-
neural_layer = np.dot(W[index], neural_layer)
|
661
590
|
|
662
591
|
output_layer += neural_layer
|
663
592
|
|
@@ -765,7 +694,7 @@ def save_model(model_name,
|
|
765
694
|
# Operations to be performed by the function will be written here
|
766
695
|
pass
|
767
696
|
|
768
|
-
layers = ['fex'
|
697
|
+
layers = ['fex']
|
769
698
|
|
770
699
|
if weights_type != 'txt' and weights_type != 'npy' and weights_type != 'mat':
|
771
700
|
print(Fore.RED + "ERROR110: Save Weight type (File Extension) Type must be 'txt' or 'npy' or 'mat' from: save_model" +
|
@@ -976,7 +905,7 @@ def predict_model_ssd(Input, model_name, model_path):
|
|
976
905
|
non_scaled = True
|
977
906
|
|
978
907
|
|
979
|
-
layers = ['fex'
|
908
|
+
layers = ['fex']
|
980
909
|
|
981
910
|
Wc = [0] * len(W)
|
982
911
|
for i, w in enumerate(W):
|
@@ -1022,7 +951,7 @@ def predict_model_ram(Input, scaler_params, W, activation_potentiation=None):
|
|
1022
951
|
|
1023
952
|
Input = standard_scaler(None, Input, scaler_params)
|
1024
953
|
|
1025
|
-
layers = ['fex'
|
954
|
+
layers = ['fex']
|
1026
955
|
|
1027
956
|
Wc = [0] * len(W)
|
1028
957
|
for i, w in enumerate(W):
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: pyerualjetwork
|
3
|
+
Version: 2.6.5
|
4
|
+
Summary: Visual improvements, new option added for val paramater in fit function: 'final'. Removed: val_count parameter.
|
5
|
+
Author: Hasan Can Beydili
|
6
|
+
Author-email: tchasancan@gmail.com
|
7
|
+
Keywords: model evaluation,classifcation,potentiation learning artficial neural networks
|
8
|
+
|
@@ -0,0 +1,6 @@
|
|
1
|
+
plan/__init__.py,sha256=gmaz8lnQfl18MbOQwabBUPmShajK5S99jfyY-hQe8tc,502
|
2
|
+
plan/plan.py,sha256=QP0z-MfKFhSnWqAEBLZ2L1sJUhTnkefeXAsgJTA_fYU,53321
|
3
|
+
pyerualjetwork-2.6.5.dist-info/METADATA,sha256=GbAd2Jfv-c3Lt_Ut0MgjmHg1ETBNvAePdVqRiXA-pWw,338
|
4
|
+
pyerualjetwork-2.6.5.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
5
|
+
pyerualjetwork-2.6.5.dist-info/top_level.txt,sha256=G0Al3HuNJ88434XneyDtRKAIUaLCizOFYFYNhd7e2OM,5
|
6
|
+
pyerualjetwork-2.6.5.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: pyerualjetwork
|
3
|
-
Version: 2.6.3
|
4
|
-
Summary: New optional parameters added for fit function, x_val, y_val show_count, val_count, val. For more information please read user document
|
5
|
-
Author: Hasan Can Beydili
|
6
|
-
Author-email: tchasancan@gmail.com
|
7
|
-
Keywords: model evaluation,classifcation,pruning learning artficial neural networks
|
8
|
-
|
@@ -1,6 +0,0 @@
|
|
1
|
-
plan/__init__.py,sha256=gmaz8lnQfl18MbOQwabBUPmShajK5S99jfyY-hQe8tc,502
|
2
|
-
plan/plan.py,sha256=fUVW_bUadJjTPoXN3YQwU_1b-FSr64fCH3_WUAoDcn8,56253
|
3
|
-
pyerualjetwork-2.6.3.dist-info/METADATA,sha256=uc5OY2rYco6MWnILvfmZ4rR9-9xheUTsR7MMOlg1J9Q,357
|
4
|
-
pyerualjetwork-2.6.3.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
5
|
-
pyerualjetwork-2.6.3.dist-info/top_level.txt,sha256=G0Al3HuNJ88434XneyDtRKAIUaLCizOFYFYNhd7e2OM,5
|
6
|
-
pyerualjetwork-2.6.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|