pyerualjetwork 5.0.2b1__py3-none-any.whl → 5.1__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.
- pyerualjetwork/__init__.py +7 -3
- pyerualjetwork/activation_functions_cpu.py +3 -71
- pyerualjetwork/activation_functions_cuda.py +2 -74
- pyerualjetwork/data_operations_cpu.py +3 -5
- pyerualjetwork/ene_cuda.py +5 -5
- pyerualjetwork/issue_solver.py +2 -2
- pyerualjetwork/model_operations_cpu.py +126 -54
- pyerualjetwork/model_operations_cuda.py +123 -49
- pyerualjetwork/neu_cpu.py +169 -52
- pyerualjetwork/neu_cuda.py +170 -55
- {pyerualjetwork-5.0.2b1.dist-info → pyerualjetwork-5.1.dist-info}/METADATA +3 -3
- pyerualjetwork-5.1.dist-info/RECORD +26 -0
- pyerualjetwork-5.0.2b1.dist-info/RECORD +0 -26
- {pyerualjetwork-5.0.2b1.dist-info → pyerualjetwork-5.1.dist-info}/WHEEL +0 -0
- {pyerualjetwork-5.0.2b1.dist-info → pyerualjetwork-5.1.dist-info}/top_level.txt +0 -0
@@ -28,6 +28,12 @@ Module functions:
|
|
28
28
|
- get_acc()
|
29
29
|
- get_scaler()
|
30
30
|
- get_model_type()
|
31
|
+
- get_weights_type()
|
32
|
+
- get_weights_format()
|
33
|
+
- get_model_version()
|
34
|
+
- get_model_df()
|
35
|
+
- get_act_pot()
|
36
|
+
|
31
37
|
|
32
38
|
Examples: https://github.com/HCB06/PyerualJetwork/tree/main/Welcome_to_PyerualJetwork/ExampleCodes
|
33
39
|
|
@@ -58,6 +64,7 @@ def save_model(model_name,
|
|
58
64
|
test_acc=None,
|
59
65
|
model_path='',
|
60
66
|
activations=['linear'],
|
67
|
+
activation_potentiation=[],
|
61
68
|
weights_type='npy',
|
62
69
|
weights_format='raw',
|
63
70
|
show_architecture=False,
|
@@ -71,7 +78,7 @@ def save_model(model_name,
|
|
71
78
|
model_name: (str): Name of the model.
|
72
79
|
W: Weights of the model.
|
73
80
|
|
74
|
-
model_type: (str): Type of the model. Options: 'PLAN', 'MLP'.
|
81
|
+
model_type: (str): Type of the model. Options: 'PLAN', 'MLP', 'PTNN'.
|
75
82
|
|
76
83
|
scaler_params: (list[num, num]): standard scaler params list: mean,std. If not used standard scaler then be: None.
|
77
84
|
|
@@ -83,6 +90,8 @@ def save_model(model_name,
|
|
83
90
|
|
84
91
|
activations: (list[str]): For deeper PLAN networks, activation function parameters. Or activation function parameters for MLP layers. For more information please run this code: plan.activations_list() default: ['linear']
|
85
92
|
|
93
|
+
activation_potentiation (list, optional): Extra activation potentiation list (PLAN layers activations) for just PTNN models. Default = None.
|
94
|
+
|
86
95
|
weights_type: (str): Type of weights to save (options: 'txt', 'pkl', 'npy', 'mat'). default: 'npy'
|
87
96
|
|
88
97
|
weights_format: (str): Format of the weights (options: 'f', 'raw'). default: 'raw'
|
@@ -97,10 +106,14 @@ def save_model(model_name,
|
|
97
106
|
"""
|
98
107
|
|
99
108
|
from .visualizations_cuda import draw_model_architecture
|
109
|
+
from .__init__ import __version__
|
100
110
|
|
101
|
-
if model_type != 'PLAN' and model_type != 'MLP':
|
102
|
-
raise ValueError("model_type parameter must be 'PLAN' or '
|
111
|
+
if model_type != 'PLAN' and model_type != 'MLP' and model_type != 'PTNN':
|
112
|
+
raise ValueError("model_type parameter must be 'PLAN', 'MLP' or 'PTNN'.")
|
103
113
|
|
114
|
+
if model_type == 'PTNN' and activation_potentiation == []:
|
115
|
+
raise ValueError('PTNN models need extra activation_potentiation parameter.')
|
116
|
+
|
104
117
|
if isinstance(W, list):
|
105
118
|
W = W.copy()
|
106
119
|
|
@@ -112,7 +125,15 @@ def save_model(model_name,
|
|
112
125
|
else:
|
113
126
|
activations = [item if isinstance(item, list) else [item] for item in activations]
|
114
127
|
|
115
|
-
|
128
|
+
activations = activations.copy()
|
129
|
+
|
130
|
+
if model_type == 'PTNN':
|
131
|
+
if isinstance(activation_potentiation, str):
|
132
|
+
activation_potentiation = [activation_potentiation]
|
133
|
+
else:
|
134
|
+
activation_potentiation = [item if isinstance(item, list) else [item] for item in activation_potentiation]
|
135
|
+
|
136
|
+
activation_potentiation = activation_potentiation.copy()
|
116
137
|
|
117
138
|
if test_acc is not None:
|
118
139
|
test_acc= float(test_acc)
|
@@ -140,7 +161,7 @@ def save_model(model_name,
|
|
140
161
|
print(Fore.RED + "ERROR: Weight matrices have a problem from: save_model" + Style.RESET_ALL)
|
141
162
|
sys.exit()
|
142
163
|
|
143
|
-
elif model_type == 'MLP':
|
164
|
+
elif model_type == 'MLP' or model_type == 'PTNN':
|
144
165
|
|
145
166
|
for i in range(len(W)):
|
146
167
|
W[i] = W[i].get()
|
@@ -162,37 +183,45 @@ def save_model(model_name,
|
|
162
183
|
|
163
184
|
SynapseCount.append(' ')
|
164
185
|
|
165
|
-
|
166
|
-
|
186
|
+
activations.append('')
|
187
|
+
activations.insert(0, '')
|
167
188
|
|
168
|
-
if len(
|
169
|
-
|
170
|
-
|
189
|
+
if len(activations) == 1 and model_type == 'PLAN':
|
190
|
+
activations = [activations]
|
191
|
+
activations.append('')
|
192
|
+
|
193
|
+
if model_type == 'PTNN':
|
194
|
+
if len(activations) > len(activation_potentiation):
|
195
|
+
for i in range(len(activations) - len(activation_potentiation)):
|
196
|
+
activation_potentiation.append('')
|
171
197
|
|
172
|
-
|
173
|
-
|
198
|
+
if len(activation_potentiation) > len(activations):
|
199
|
+
for i in range(len(activation_potentiation) - len(activations)):
|
200
|
+
activations.append('')
|
201
|
+
|
202
|
+
if len(activations) > len(NeuronCount):
|
203
|
+
for i in range(len(activations) - len(NeuronCount)):
|
174
204
|
NeuronCount.append('')
|
175
|
-
|
176
|
-
if len(
|
177
|
-
for i in range(len(
|
205
|
+
|
206
|
+
if len(activations) > len(SynapseCount):
|
207
|
+
for i in range(len(activations) - len(SynapseCount)):
|
178
208
|
SynapseCount.append('')
|
179
209
|
|
180
210
|
if scaler_params != None:
|
181
211
|
|
182
|
-
if len(scaler_params) > len(
|
212
|
+
if len(scaler_params) > len(activations):
|
183
213
|
|
184
|
-
|
214
|
+
activations += ['']
|
185
215
|
|
186
|
-
elif len(
|
216
|
+
elif len(activations) > len(scaler_params):
|
187
217
|
|
188
|
-
for i in range(len(
|
218
|
+
for i in range(len(activations) - len(scaler_params)):
|
189
219
|
|
190
220
|
scaler_params.append(' ')
|
191
221
|
|
192
222
|
scaler_params[0] = scaler_params[0].get()
|
193
223
|
scaler_params[1] = scaler_params[1].get()
|
194
224
|
|
195
|
-
from .__init__ import __version__
|
196
225
|
|
197
226
|
data = {'MODEL NAME': model_name,
|
198
227
|
'MODEL TYPE': model_type,
|
@@ -204,9 +233,9 @@ def save_model(model_name,
|
|
204
233
|
'SAVE DATE': datetime.now(),
|
205
234
|
'WEIGHTS TYPE': weights_type,
|
206
235
|
'WEIGHTS FORMAT': weights_format,
|
207
|
-
'MODEL PATH': model_path,
|
208
236
|
'STANDARD SCALER': scaler_params,
|
209
|
-
'ACTIVATION FUNCTIONS':
|
237
|
+
'ACTIVATION FUNCTIONS': activations,
|
238
|
+
'ACTIVATION POTENTIATION': activation_potentiation
|
210
239
|
}
|
211
240
|
|
212
241
|
df = pd.DataFrame(data)
|
@@ -284,8 +313,10 @@ def load_model(model_name,
|
|
284
313
|
model_path (str): Path where the model is saved.
|
285
314
|
|
286
315
|
Returns:
|
287
|
-
lists: (list[df_elements])
|
316
|
+
lists: Weights, None, test_accuracy, activations, scaler_params, None, model_type, weight_type, weight_format, device_version, (list[df_elements])=Pandas DataFrame of the model
|
288
317
|
"""
|
318
|
+
|
319
|
+
from .__init__ import __version__
|
289
320
|
|
290
321
|
try:
|
291
322
|
|
@@ -297,13 +328,6 @@ def load_model(model_name,
|
|
297
328
|
|
298
329
|
sys.exit()
|
299
330
|
|
300
|
-
try:
|
301
|
-
activations = list(df['ACTIVATION FUNCTIONS']) # for PyerualJetwork >=5 Versions.
|
302
|
-
except KeyError:
|
303
|
-
activations = list(df['ACTIVATION POTENTIATION']) # for PyerualJetwork <5 Versions.
|
304
|
-
|
305
|
-
activations = [x for x in activations if not (isinstance(x, float) and cp.isnan(x))]
|
306
|
-
activations = [item for item in activations if item != '']
|
307
331
|
|
308
332
|
scaler_params_cpu = df['STANDARD SCALER'].tolist()
|
309
333
|
|
@@ -324,7 +348,14 @@ def load_model(model_name,
|
|
324
348
|
WeightFormat = str(df['WEIGHTS FORMAT'].iloc[0])
|
325
349
|
test_acc = str(df['TEST ACCURACY'].iloc[0])
|
326
350
|
|
327
|
-
|
351
|
+
activations = list(df['ACTIVATION FUNCTIONS'])
|
352
|
+
activations = [x for x in activations if not (isinstance(x, float) and np.isnan(x))]
|
353
|
+
activations = [item for item in activations if item != '']
|
354
|
+
|
355
|
+
activation_potentiation = list(df['ACTIVATION POTENTIATION'])
|
356
|
+
activation_potentiation = [x for x in activation_potentiation if not (isinstance(x, float) and np.isnan(x))]
|
357
|
+
activation_potentiation = [item for item in activation_potentiation if item != '']
|
358
|
+
|
328
359
|
|
329
360
|
device_version = __version__
|
330
361
|
|
@@ -340,7 +371,7 @@ def load_model(model_name,
|
|
340
371
|
except:
|
341
372
|
pass # Version check only in >= 5.0.2
|
342
373
|
|
343
|
-
if model_type == 'MLP': allow_pickle = True
|
374
|
+
if model_type == 'MLP' or model_type == 'PTNN': allow_pickle = True
|
344
375
|
else: allow_pickle = False
|
345
376
|
|
346
377
|
if WeightType == 'txt':
|
@@ -364,7 +395,7 @@ def load_model(model_name,
|
|
364
395
|
W = W.tolist()
|
365
396
|
W = [cp.array(item) for item in W]
|
366
397
|
|
367
|
-
return W, None, test_acc, activations, scaler_params, None, model_type, WeightType, WeightFormat, device_version, df
|
398
|
+
return W, None, test_acc, activations, scaler_params, None, model_type, WeightType, WeightFormat, device_version, df, activation_potentiation
|
368
399
|
|
369
400
|
|
370
401
|
|
@@ -399,6 +430,7 @@ def predict_from_storage(Input, model_name, model_path='', dtype=cp.float32):
|
|
399
430
|
scaler_params = model[get_scaler()]
|
400
431
|
W = model[get_weights()]
|
401
432
|
model_type = model[get_model_type()]
|
433
|
+
activation_potentiation = model[get_act_pot()]
|
402
434
|
|
403
435
|
if isinstance(activations, str):
|
404
436
|
activations = [activations]
|
@@ -408,20 +440,37 @@ def predict_from_storage(Input, model_name, model_path='', dtype=cp.float32):
|
|
408
440
|
Input = standard_scaler(None, Input, scaler_params)
|
409
441
|
|
410
442
|
if model_type == 'MLP':
|
411
|
-
|
412
443
|
layer = Input
|
413
444
|
for i in range(len(W)):
|
414
445
|
if i != len(W) - 1 and i != 0: layer = apply_activation(layer, activations[i])
|
446
|
+
|
415
447
|
layer = layer @ W[i].T
|
416
|
-
|
417
|
-
return layer
|
418
448
|
|
419
|
-
|
449
|
+
result = layer
|
450
|
+
|
451
|
+
if model_type == 'PLAN':
|
420
452
|
|
421
453
|
Input = apply_activation(Input, activations)
|
422
454
|
result = Input @ W.T
|
455
|
+
|
456
|
+
if model_type == 'PTNN':
|
457
|
+
|
458
|
+
if isinstance(activation_potentiation, str):
|
459
|
+
activation_potentiation = [activation_potentiation]
|
460
|
+
elif isinstance(activation_potentiation, list):
|
461
|
+
activation_potentiation = [item if isinstance(item, list) or isinstance(item, str) else [item] for item in activation_potentiation]
|
423
462
|
|
424
|
-
|
463
|
+
Input = apply_activation(Input, activation_potentiation)
|
464
|
+
layer = Input @ W[0].T
|
465
|
+
|
466
|
+
for i in range(1, len(W)):
|
467
|
+
if i != len(W) - 1: layer = apply_activation(layer, activations[i])
|
468
|
+
|
469
|
+
layer = layer @ W[i].T
|
470
|
+
|
471
|
+
result = layer
|
472
|
+
|
473
|
+
return result
|
425
474
|
|
426
475
|
except:
|
427
476
|
print(Fore.RED + "ERROR: Unexpected Output or wrong model parameters from: predict_model_ssd." + Style.RESET_ALL)
|
@@ -461,7 +510,7 @@ def reverse_predict_from_storage(output, model_name, model_path='', dtype=cp.flo
|
|
461
510
|
sys.exit()
|
462
511
|
|
463
512
|
|
464
|
-
def predict_from_memory(Input, W, scaler_params=None, activations=['linear'],
|
513
|
+
def predict_from_memory(Input, W, scaler_params=None, activations=['linear'], activation_potentiation=None, model_type='PLAN'):
|
465
514
|
|
466
515
|
"""
|
467
516
|
Function to make a prediction
|
@@ -476,7 +525,10 @@ def predict_from_memory(Input, W, scaler_params=None, activations=['linear'], is
|
|
476
525
|
|
477
526
|
activations (list[str]): activation list for deep PLAN or activation list for MLP layers. Default: ['linear']
|
478
527
|
|
479
|
-
|
528
|
+
activation_potentiation (list, optional): Extra activation potentiation list (PLAN layers activations) for just PTNN models. Default = None.
|
529
|
+
|
530
|
+
model_type: (str): Type of the model. Options: 'PLAN', 'MLP', 'PTNN'. Default: PLAN
|
531
|
+
|
480
532
|
Returns:
|
481
533
|
cupyarray: Output from the model.
|
482
534
|
"""
|
@@ -490,24 +542,41 @@ def predict_from_memory(Input, W, scaler_params=None, activations=['linear'], is
|
|
490
542
|
activations = [activations]
|
491
543
|
elif isinstance(activations, list):
|
492
544
|
activations = [item if isinstance(item, list) or isinstance(item, str) else [item] for item in activations]
|
493
|
-
|
545
|
+
|
494
546
|
Input = standard_scaler(None, Input, scaler_params)
|
495
|
-
|
496
|
-
if
|
497
|
-
|
547
|
+
|
548
|
+
if model_type == 'MLP':
|
498
549
|
layer = Input
|
499
550
|
for i in range(len(W)):
|
500
551
|
if i != len(W) - 1 and i != 0: layer = apply_activation(layer, activations[i])
|
552
|
+
|
501
553
|
layer = layer @ W[i].T
|
502
|
-
|
503
|
-
return layer
|
504
554
|
|
505
|
-
|
555
|
+
result = layer
|
556
|
+
|
557
|
+
if model_type == 'PLAN':
|
506
558
|
|
507
559
|
Input = apply_activation(Input, activations)
|
508
560
|
result = Input @ W.T
|
561
|
+
|
562
|
+
if model_type == 'PTNN':
|
563
|
+
|
564
|
+
if isinstance(activation_potentiation, str):
|
565
|
+
activation_potentiation = [activation_potentiation]
|
566
|
+
elif isinstance(activation_potentiation, list):
|
567
|
+
activation_potentiation = [item if isinstance(item, list) or isinstance(item, str) else [item] for item in activation_potentiation]
|
568
|
+
|
569
|
+
Input = apply_activation(Input, activation_potentiation)
|
570
|
+
layer = Input @ W[0].T
|
571
|
+
|
572
|
+
for i in range(1, len(W)):
|
573
|
+
if i != len(W) - 1: layer = apply_activation(layer, activations[i])
|
509
574
|
|
510
|
-
|
575
|
+
layer = layer @ W[i].T
|
576
|
+
|
577
|
+
result = layer
|
578
|
+
|
579
|
+
return result
|
511
580
|
|
512
581
|
except:
|
513
582
|
print(Fore.RED + "ERROR: Unexpected input or wrong model parameters from: predict_model_ram." + Style.RESET_ALL)
|
@@ -594,4 +663,9 @@ def get_model_version():
|
|
594
663
|
|
595
664
|
def get_model_df():
|
596
665
|
|
597
|
-
return 10
|
666
|
+
return 10
|
667
|
+
|
668
|
+
|
669
|
+
def get_act_pot():
|
670
|
+
|
671
|
+
return 11
|