pyerualjetwork 5.1__py3-none-any.whl → 5.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.
Files changed (29) hide show
  1. pyerualjetwork/__init__.py +15 -14
  2. pyerualjetwork/cpu/__init__.py +24 -0
  3. pyerualjetwork/{activation_functions_cpu.py → cpu/activation_functions.py} +40 -4
  4. pyerualjetwork/{data_operations_cpu.py → cpu/data_ops.py} +17 -19
  5. pyerualjetwork/{metrics_cpu.py → cpu/metrics.py} +3 -1
  6. pyerualjetwork/{visualizations_cpu.py → cpu/visualizations.py} +96 -139
  7. pyerualjetwork/cuda/__init__.py +24 -0
  8. pyerualjetwork/{activation_functions_cuda.py → cuda/activation_functions.py} +54 -5
  9. pyerualjetwork/{data_operations_cuda.py → cuda/data_ops.py} +16 -16
  10. pyerualjetwork/{metrics_cuda.py → cuda/metrics.py} +1 -1
  11. pyerualjetwork/{visualizations_cuda.py → cuda/visualizations.py} +8 -244
  12. pyerualjetwork/{ene_cpu.py → ene.py} +29 -95
  13. pyerualjetwork/fitness_functions.py +0 -1
  14. pyerualjetwork/help.py +5 -5
  15. pyerualjetwork/issue_solver.py +39 -11
  16. pyerualjetwork/{memory_operations.py → memory_ops.py} +1 -1
  17. pyerualjetwork/model_ops.py +734 -0
  18. pyerualjetwork/{neu_cpu.py → nn.py} +199 -91
  19. pyerualjetwork/{model_operations_cpu.py → old_cpu_model_ops.py} +62 -59
  20. pyerualjetwork/{model_operations_cuda.py → old_cuda_model_ops.py} +99 -86
  21. {pyerualjetwork-5.1.dist-info → pyerualjetwork-5.5.dist-info}/METADATA +16 -18
  22. pyerualjetwork-5.5.dist-info/RECORD +27 -0
  23. pyerualjetwork/ene_cuda.py +0 -962
  24. pyerualjetwork/neu_cuda.py +0 -588
  25. pyerualjetwork-5.1.dist-info/RECORD +0 -26
  26. /pyerualjetwork/{loss_functions_cpu.py → cpu/loss_functions.py} +0 -0
  27. /pyerualjetwork/{loss_functions_cuda.py → cuda/loss_functions.py} +0 -0
  28. {pyerualjetwork-5.1.dist-info → pyerualjetwork-5.5.dist-info}/WHEEL +0 -0
  29. {pyerualjetwork-5.1.dist-info → pyerualjetwork-5.5.dist-info}/top_level.txt +0 -0
@@ -38,7 +38,7 @@ Examples: https://github.com/HCB06/PyerualJetwork/tree/main/Welcome_to_PyerualJe
38
38
 
39
39
  PyerualJetwork document: https://github.com/HCB06/PyerualJetwork/blob/main/Welcome_to_PyerualJetwork/PYERUALJETWORK_USER_MANUEL_AND_LEGAL_INFORMATION(EN).pdf
40
40
 
41
- - Author: Hasan Can Beydili
41
+ - Creator: Hasan Can Beydili
42
42
  - YouTube: https://www.youtube.com/@HasanCanBeydili
43
43
  - Linkedin: https://www.linkedin.com/in/hasan-can-beydili-77a1b9270/
44
44
  - Instagram: https://www.instagram.com/canbeydilj
@@ -47,7 +47,6 @@ PyerualJetwork document: https://github.com/HCB06/PyerualJetwork/blob/main/Welco
47
47
 
48
48
  import numpy as np
49
49
  from colorama import Fore, Style
50
- import sys
51
50
  from datetime import datetime
52
51
  import pickle
53
52
  from scipy import io
@@ -62,7 +61,7 @@ def save_model(model_name,
62
61
  test_acc=None,
63
62
  model_path='',
64
63
  activations=['linear'],
65
- activation_potentiation=[],
64
+ activation_potentiation=None,
66
65
  weights_type='npy',
67
66
  weights_format='raw',
68
67
  show_architecture=False,
@@ -100,8 +99,8 @@ def save_model(model_name,
100
99
  No return.
101
100
  """
102
101
 
103
- from .visualizations_cpu import draw_model_architecture
104
- from .__init__ import __version__
102
+ from .visualizations import draw_model_architecture
103
+ from .. import __version__
105
104
 
106
105
  if model_type != 'PLAN' and model_type != 'MLP' and model_type != 'PTNN':
107
106
  raise ValueError("model_type parameter must be 'PLAN', 'MLP' or 'PTNN'.")
@@ -128,13 +127,11 @@ def save_model(model_name,
128
127
  test_acc= float(test_acc)
129
128
 
130
129
  if weights_type != 'txt' and weights_type != 'npy' and weights_type != 'mat' and weights_type != 'pkl':
131
- print(Fore.RED + "ERROR110: Save Weight type (File Extension) Type must be 'txt' or 'npy' or 'mat' or 'pkl' from: save_model" + Style.RESET_ALL)
132
- sys.exit()
130
+ raise ValueError(Fore.RED + "ERROR: Save Weight type (File Extension) Type must be 'txt' or 'npy' or 'mat' or 'pkl' from: save_model" + Style.RESET_ALL)
133
131
 
134
132
  if weights_format != 'd' and weights_format != 'f' and weights_format != 'raw':
135
- print(Fore.RED + "ERROR111: Weight Format Type must be 'd' or 'f' or 'raw' from: save_model" + Style.RESET_ALL)
136
- sys.exit()
137
-
133
+ raise ValueError(Fore.RED + "ERROR: Weight Format Type must be 'd' or 'f' or 'raw' from: save_model" + Style.RESET_ALL)
134
+
138
135
  NeuronCount = []
139
136
  SynapseCount = []
140
137
 
@@ -145,10 +142,14 @@ def save_model(model_name,
145
142
  NeuronCount.append(np.shape(W)[1])
146
143
  NeuronCount.append(np.shape(W)[0])
147
144
  SynapseCount.append(np.shape(W)[0] * np.shape(W)[1])
148
- except:
149
-
150
- print(Fore.RED + "ERROR: Weight matrices have a problem from: save_model" + Style.RESET_ALL)
151
- sys.exit()
145
+ except AttributeError as e:
146
+ raise AttributeError(Fore.RED + "ERROR: W does not have a shape attribute. Check if W is a valid matrix." + Style.RESET_ALL) from e
147
+ except IndexError as e:
148
+ raise IndexError(Fore.RED + "ERROR: W has an unexpected shape format. Ensure it has two dimensions." + Style.RESET_ALL) from e
149
+ except (TypeError, ValueError) as e:
150
+ raise TypeError(Fore.RED + "ERROR: W is not a valid numeric matrix." + Style.RESET_ALL) from e
151
+ except Exception as e:
152
+ raise RuntimeError(Fore.RED + f"ERROR: An unexpected error occurred in save_model: {e}" + Style.RESET_ALL) from e
152
153
 
153
154
  elif model_type == 'MLP' or model_type == 'PTNN':
154
155
 
@@ -160,10 +161,14 @@ def save_model(model_name,
160
161
  try:
161
162
  NeuronCount.append(np.shape(W[i])[0])
162
163
  SynapseCount.append(np.shape(W[i])[0] * np.shape(W[i])[1])
163
- except:
164
-
165
- print(Fore.RED + "ERROR: Weight matrices have a problem from: save_model" + Style.RESET_ALL)
166
- sys.exit()
164
+ except AttributeError as e:
165
+ raise AttributeError(Fore.RED + "ERROR: W does not have a shape attribute. Check if W is a valid matrix." + Style.RESET_ALL) from e
166
+ except IndexError as e:
167
+ raise IndexError(Fore.RED + "ERROR: W has an unexpected shape format. Ensure it has two dimensions." + Style.RESET_ALL) from e
168
+ except (TypeError, ValueError) as e:
169
+ raise TypeError(Fore.RED + "ERROR: W is not a valid numeric matrix." + Style.RESET_ALL) from e
170
+ except Exception as e:
171
+ raise RuntimeError(Fore.RED + f"ERROR: An unexpected error occurred in save_model: {e}" + Style.RESET_ALL) from e
167
172
 
168
173
 
169
174
  SynapseCount.append(' ')
@@ -267,10 +272,9 @@ def save_model(model_name,
267
272
  w = {'w': W}
268
273
  io.savemat(model_path + model_name + f'_weights.mat', w)
269
274
 
270
- except:
271
275
 
272
- print(Fore.RED + "ERROR: Model Weights not saved. Check the Weight parameters. SaveFilePath expl: 'C:/Users/hasancanbeydili/Desktop/denemePLAN/' from: save_model" + Style.RESET_ALL)
273
- sys.exit()
276
+ except OSError as e:
277
+ raise OSError(Fore.RED + f"ERROR: An OSError error occurred in save_model at saving weights. Maybe model name or path or administration issue: {e}" + Style.RESET_ALL) from e
274
278
 
275
279
  if show_info:
276
280
  print(df)
@@ -303,17 +307,15 @@ def load_model(model_name,
303
307
  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
304
308
  """
305
309
 
306
- from .__init__ import __version__
310
+ from .. import __version__
307
311
 
308
312
  try:
309
313
 
310
314
  df = pd.read_pickle(model_path + model_name + '.pkl')
311
315
 
312
- except:
313
-
314
- print(Fore.RED + "ERROR: Model Path or Model Name error. acceptable form: 'C:/Users/hasancanbeydili/Desktop/denemePLAN/' from: load_model" + Style.RESET_ALL)
316
+ except OSError as e:
317
+ raise OSError(Fore.RED + f"ERROR: An OSError error occurred in load_model at loading model params. Maybe model name or path or administration issue: {e}" + Style.RESET_ALL) from e
315
318
 
316
- sys.exit()
317
319
 
318
320
 
319
321
  scaler_params = df['STANDARD SCALER'].tolist()
@@ -357,20 +359,25 @@ def load_model(model_name,
357
359
  if model_type == 'MLP' or model_type == 'PTNN': allow_pickle = True
358
360
  else: allow_pickle = False
359
361
 
360
- if WeightType == 'txt':
361
- W = (np.loadtxt(model_path + model_name + f'_weights.txt'))
362
- elif WeightType == 'npy':
363
- W = (np.load(model_path + model_name + f'_weights.npy', allow_pickle=allow_pickle))
364
- elif WeightType == 'mat':
365
- W = (sio.loadmat(model_path + model_name + f'_weights.mat'))
366
- elif WeightType == 'pkl':
367
- with open(model_path + model_name + f'_weights.pkl', 'rb') as f:
368
- W = pickle.load(f)
369
- else:
362
+ try:
363
+ if WeightType == 'txt':
364
+ W = (np.loadtxt(model_path + model_name + f'_weights.txt'))
365
+ elif WeightType == 'npy':
366
+ W = (np.load(model_path + model_name + f'_weights.npy', allow_pickle=allow_pickle))
367
+ elif WeightType == 'mat':
368
+ W = (sio.loadmat(model_path + model_name + f'_weights.mat'))
369
+ elif WeightType == 'pkl':
370
+ with open(model_path + model_name + f'_weights.pkl', 'rb') as f:
371
+ W = pickle.load(f)
372
+ else:
373
+
374
+ raise ValueError(
375
+ Fore.RED + "Incorrect weight type value. Value must be 'txt', 'npy', 'pkl' or 'mat' from: load_model." + Style.RESET_ALL)
376
+
377
+ except OSError as e:
378
+ raise OSError(Fore.RED + f"ERROR: An OSError error occurred in load_model at loading weights. Maybe model name or path or administration issue: {e}" + Style.RESET_ALL) from e
379
+
370
380
 
371
- raise ValueError(
372
- Fore.RED + "Incorrect weight type value. Value must be 'txt', 'npy', 'pkl' or 'mat' from: load_model." + Style.RESET_ALL)
373
-
374
381
  if WeightType == 'mat':
375
382
  W = W['w']
376
383
 
@@ -385,7 +392,7 @@ def predict_from_storage(Input, model_name, model_path=''):
385
392
  from storage
386
393
 
387
394
  Args:
388
- Input (list or ndarray): Input data for the model (single vector or single matrix).
395
+ Input (list or ndarray): Input data for the model.
389
396
 
390
397
  model_name (str): Name of the model.
391
398
 
@@ -395,8 +402,8 @@ def predict_from_storage(Input, model_name, model_path=''):
395
402
  ndarray: Output from the model.
396
403
  """
397
404
 
398
- from .activation_functions_cpu import apply_activation
399
- from .data_operations_cpu import standard_scaler
405
+ from .activation_functions import apply_activation
406
+ from .data_ops import standard_scaler
400
407
 
401
408
  try:
402
409
 
@@ -448,9 +455,8 @@ def predict_from_storage(Input, model_name, model_path=''):
448
455
 
449
456
  return result
450
457
 
451
- except:
452
- print(Fore.RED + "ERROR: Unexpected Output or wrong model parameters from: predict_model_storage." + Style.RESET_ALL)
453
- sys.exit()
458
+ except Exception as e:
459
+ raise RuntimeError(Fore.RED + f"ERROR: An error occurred in predict_from_storage {e}" + Style.RESET_ALL) from e
454
460
 
455
461
 
456
462
  def reverse_predict_from_storage(output, model_name, model_path=''):
@@ -459,7 +465,7 @@ def reverse_predict_from_storage(output, model_name, model_path=''):
459
465
  reverse prediction function from storage
460
466
  Args:
461
467
 
462
- output (list or ndarray): output layer for the model (single probability vector, output layer of trained model).
468
+ output (list or ndarray): output layer for the model .
463
469
 
464
470
  model_name (str): Name of the model.
465
471
 
@@ -476,9 +482,8 @@ def reverse_predict_from_storage(output, model_name, model_path=''):
476
482
  try:
477
483
  Input = W.T @ output
478
484
  return Input
479
- except:
480
- print(Fore.RED + "ERROR: Unexpected Output or wrong model parameters from: reverse_predict_model_storage." + Style.RESET_ALL)
481
- sys.exit()
485
+ except Exception as e:
486
+ raise RuntimeError(Fore.RED + f"ERROR: An error occurred {e}" + Style.RESET_ALL) from e
482
487
 
483
488
 
484
489
 
@@ -489,7 +494,7 @@ def predict_from_memory(Input, W, scaler_params=None, activations=['linear'], ac
489
494
  from memory.
490
495
 
491
496
  Args:
492
- Input (list or ndarray): Input data for the model (single vector or single matrix).
497
+ Input (list or ndarray): Input data for the model.
493
498
 
494
499
  W (list of ndarrays): Weights of the model.
495
500
 
@@ -505,8 +510,8 @@ def predict_from_memory(Input, W, scaler_params=None, activations=['linear'], ac
505
510
  ndarray: Output from the model.
506
511
  """
507
512
 
508
- from .data_operations_cpu import standard_scaler
509
- from .activation_functions_cpu import apply_activation
513
+ from .data_ops import standard_scaler
514
+ from .activation_functions import apply_activation
510
515
 
511
516
  if model_type != 'PLAN' and model_type != 'MLP' and model_type != 'PTNN': raise ValueError("model_type parameter must be 'PLAN', 'MLP' or 'PTNN'.")
512
517
 
@@ -552,9 +557,8 @@ def predict_from_memory(Input, W, scaler_params=None, activations=['linear'], ac
552
557
 
553
558
  return result
554
559
 
555
- except:
556
- print(Fore.RED + "ERROR: Unexpected input or wrong model parameters from: predict_model_memory." + Style.RESET_ALL)
557
- sys.exit()
560
+ except Exception as e:
561
+ raise RuntimeError(Fore.RED + f"ERROR: An error occurred in predict_from_memory {e}" + Style.RESET_ALL) from e
558
562
 
559
563
  def reverse_predict_from_memory(output, W):
560
564
 
@@ -563,7 +567,7 @@ def reverse_predict_from_memory(output, W):
563
567
 
564
568
  Args:
565
569
 
566
- output (list or ndarray): output layer for the model (single probability vector, output layer of trained model).
570
+ output (list or ndarray): output layer for the model.
567
571
 
568
572
  W (list of ndarrays): Weights of the model.
569
573
 
@@ -575,9 +579,8 @@ def reverse_predict_from_memory(output, W):
575
579
  Input = W.T @ output
576
580
  return Input
577
581
 
578
- except:
579
- print(Fore.RED + "ERROR: Unexpected Output or wrong model parameters from: reverse_predict_model_memory." + Style.RESET_ALL)
580
- sys.exit()
582
+ except Exception as e:
583
+ raise RuntimeError(Fore.RED + f"ERROR: An error occurred {e}" + Style.RESET_ALL) from e
581
584
 
582
585
 
583
586
  def get_weights():
@@ -39,7 +39,7 @@ Examples: https://github.com/HCB06/PyerualJetwork/tree/main/Welcome_to_PyerualJe
39
39
 
40
40
  PyerualJetwork document: https://github.com/HCB06/PyerualJetwork/blob/main/Welcome_to_PyerualJetwork/PYERUALJETWORK_USER_MANUEL_AND_LEGAL_INFORMATION(EN).pdf
41
41
 
42
- - Author: Hasan Can Beydili
42
+ - Creator: Hasan Can Beydili
43
43
  - YouTube: https://www.youtube.com/@HasanCanBeydili
44
44
  - Linkedin: https://www.linkedin.com/in/hasan-can-beydili-77a1b9270/
45
45
  - Instagram: https://www.instagram.com/canbeydilj
@@ -49,7 +49,6 @@ PyerualJetwork document: https://github.com/HCB06/PyerualJetwork/blob/main/Welco
49
49
  import cupy as cp
50
50
  import numpy as np
51
51
  from colorama import Fore, Style
52
- import sys
53
52
  from datetime import datetime
54
53
  import pickle
55
54
  from scipy import io
@@ -64,7 +63,7 @@ def save_model(model_name,
64
63
  test_acc=None,
65
64
  model_path='',
66
65
  activations=['linear'],
67
- activation_potentiation=[],
66
+ activation_potentiation=None,
68
67
  weights_type='npy',
69
68
  weights_format='raw',
70
69
  show_architecture=False,
@@ -105,8 +104,8 @@ def save_model(model_name,
105
104
  No return.
106
105
  """
107
106
 
108
- from .visualizations_cuda import draw_model_architecture
109
- from .__init__ import __version__
107
+ from .visualizations import draw_model_architecture
108
+ from .. import __version__
110
109
 
111
110
  if model_type != 'PLAN' and model_type != 'MLP' and model_type != 'PTNN':
112
111
  raise ValueError("model_type parameter must be 'PLAN', 'MLP' or 'PTNN'.")
@@ -139,27 +138,31 @@ def save_model(model_name,
139
138
  test_acc= float(test_acc)
140
139
 
141
140
  if weights_type != 'txt' and weights_type != 'npy' and weights_type != 'mat' and weights_type != 'pkl':
142
- print(Fore.RED + "ERROR110: Save Weight type (File Extension) Type must be 'txt' or 'npy' or 'mat' or 'pkl' from: save_model" + Style.RESET_ALL)
143
- sys.exit()
141
+ raise ValueError(Fore.RED + "ERROR: Save Weight type (File Extension) Type must be 'txt' or 'npy' or 'mat' or 'pkl' from: save_model" + Style.RESET_ALL)
144
142
 
145
143
  if weights_format != 'd' and weights_format != 'f' and weights_format != 'raw':
146
- print(Fore.RED + "ERROR111: Weight Format Type must be 'd' or 'f' or 'raw' from: save_model" + Style.RESET_ALL)
147
- sys.exit()
144
+ raise ValueError(Fore.RED + "ERROR: Weight Format Type must be 'd' or 'f' or 'raw' from: save_model" + Style.RESET_ALL)
148
145
 
149
146
  NeuronCount = []
150
147
  SynapseCount = []
151
148
 
152
149
  if model_type == 'PLAN':
153
150
  class_count = W.shape[0]
154
-
151
+
155
152
  try:
156
153
  NeuronCount.append(cp.shape(W)[1])
157
154
  NeuronCount.append(cp.shape(W)[0])
158
155
  SynapseCount.append(cp.shape(W)[0] * cp.shape(W)[1])
159
- except:
156
+
157
+ except AttributeError as e:
158
+ raise AttributeError(Fore.RED + "ERROR: W does not have a shape attribute. Check if W is a valid matrix." + Style.RESET_ALL) from e
159
+ except IndexError as e:
160
+ raise IndexError(Fore.RED + "ERROR: W has an unexpected shape format. Ensure it has two dimensions." + Style.RESET_ALL) from e
161
+ except (TypeError, ValueError) as e:
162
+ raise TypeError(Fore.RED + "ERROR: W is not a valid numeric matrix." + Style.RESET_ALL) from e
163
+ except Exception as e:
164
+ raise RuntimeError(Fore.RED + f"ERROR: An unexpected error occurred in save_model: {e}" + Style.RESET_ALL) from e
160
165
 
161
- print(Fore.RED + "ERROR: Weight matrices have a problem from: save_model" + Style.RESET_ALL)
162
- sys.exit()
163
166
 
164
167
  elif model_type == 'MLP' or model_type == 'PTNN':
165
168
 
@@ -176,10 +179,15 @@ def save_model(model_name,
176
179
  try:
177
180
  NeuronCount.append(cp.shape(W[i])[0])
178
181
  SynapseCount.append(cp.shape(W[i])[0] * cp.shape(W[i])[1])
179
- except:
180
182
 
181
- print(Fore.RED + "ERROR: Weight matrices have a problem from: save_model" + Style.RESET_ALL)
182
- sys.exit()
183
+ except AttributeError as e:
184
+ raise AttributeError(Fore.RED + "ERROR: W does not have a shape attribute. Check if W is a valid matrix." + Style.RESET_ALL) from e
185
+ except IndexError as e:
186
+ raise IndexError(Fore.RED + "ERROR: W has an unexpected shape format. Ensure it has two dimensions." + Style.RESET_ALL) from e
187
+ except (TypeError, ValueError) as e:
188
+ raise TypeError(Fore.RED + "ERROR: W is not a valid numeric matrix." + Style.RESET_ALL) from e
189
+ except Exception as e:
190
+ raise RuntimeError(Fore.RED + f"ERROR: An unexpected error occurred in save_model: {e}" + Style.RESET_ALL) from e
183
191
 
184
192
  SynapseCount.append(' ')
185
193
 
@@ -241,50 +249,53 @@ def save_model(model_name,
241
249
  df = pd.DataFrame(data)
242
250
  df.to_pickle(model_path + model_name + '.pkl')
243
251
 
252
+ try:
244
253
 
245
- if weights_type == 'txt' and weights_format == 'f':
254
+ if weights_type == 'txt' and weights_format == 'f':
246
255
 
247
- cp.savetxt(model_path + model_name + f'_weights.txt', W, fmt='%f')
256
+ cp.savetxt(model_path + model_name + f'_weights.txt', W, fmt='%f')
248
257
 
249
- if weights_type == 'txt' and weights_format == 'raw':
258
+ if weights_type == 'txt' and weights_format == 'raw':
250
259
 
251
- cp.savetxt(model_path + model_name + f'_weights.txt', W)
260
+ cp.savetxt(model_path + model_name + f'_weights.txt', W)
252
261
 
253
- ###
262
+ ###
254
263
 
255
-
256
- if weights_type == 'pkl' and weights_format == 'f':
264
+
265
+ if weights_type == 'pkl' and weights_format == 'f':
257
266
 
258
- with open(model_path + model_name + f'_weights.pkl', 'wb') as f:
259
- pickle.dump(W.astype(float), f)
267
+ with open(model_path + model_name + f'_weights.pkl', 'wb') as f:
268
+ pickle.dump(W.astype(float), f)
260
269
 
261
- if weights_type == 'pkl' and weights_format =='raw':
262
-
263
- with open(model_path + model_name + f'_weights.pkl', 'wb') as f:
264
- pickle.dump(W, f)
270
+ if weights_type == 'pkl' and weights_format =='raw':
271
+
272
+ with open(model_path + model_name + f'_weights.pkl', 'wb') as f:
273
+ pickle.dump(W, f)
265
274
 
266
- ###
275
+ ###
267
276
 
268
- if weights_type == 'npy' and weights_format == 'f':
277
+ if weights_type == 'npy' and weights_format == 'f':
269
278
 
270
- cp.save(model_path + model_name + f'_weights.npy', W, W.astype(float))
279
+ cp.save(model_path + model_name + f'_weights.npy', W, W.astype(float))
271
280
 
272
- if weights_type == 'npy' and weights_format == 'raw':
281
+ if weights_type == 'npy' and weights_format == 'raw':
273
282
 
274
- cp.save(model_path + model_name + f'_weights.npy', W)
283
+ cp.save(model_path + model_name + f'_weights.npy', W)
275
284
 
276
- ###
285
+ ###
277
286
 
278
- if weights_type == 'mat' and weights_format == 'f':
287
+ if weights_type == 'mat' and weights_format == 'f':
279
288
 
280
- w = {'w': W.astype(float)}
281
- io.savemat(model_path + model_name + f'_weights.mat', w)
282
-
283
- if weights_type == 'mat' and weights_format == 'raw':
284
-
285
- w = {'w': W}
286
- io.savemat(model_path + model_name + f'_weights.mat', w)
289
+ w = {'w': W.astype(float)}
290
+ io.savemat(model_path + model_name + f'_weights.mat', w)
287
291
 
292
+ if weights_type == 'mat' and weights_format == 'raw':
293
+
294
+ w = {'w': W}
295
+ io.savemat(model_path + model_name + f'_weights.mat', w)
296
+
297
+ except OSError as e:
298
+ raise OSError(Fore.RED + f"ERROR: An OSError error occurred in save_model at saving weights. Maybe model name or path or administration issue: {e}" + Style.RESET_ALL) from e
288
299
 
289
300
  if show_info:
290
301
  print(df)
@@ -316,17 +327,14 @@ def load_model(model_name,
316
327
  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
317
328
  """
318
329
 
319
- from .__init__ import __version__
330
+ from . import __version__
320
331
 
321
332
  try:
322
333
 
323
334
  df = pd.read_pickle(model_path + model_name + '.pkl')
324
335
 
325
- except:
326
-
327
- print(Fore.RED + "ERROR: Model Path or Model Name error. acceptable form: 'C:/Users/hasancanbeydili/Desktop/denemePLAN/' from: load_model" + Style.RESET_ALL)
328
-
329
- sys.exit()
336
+ except OSError as e:
337
+ raise OSError(Fore.RED + f"ERROR: An OSError error occurred in load_model at loading model params. Maybe model name or path or administration issue: {e}" + Style.RESET_ALL) from e
330
338
 
331
339
 
332
340
  scaler_params_cpu = df['STANDARD SCALER'].tolist()
@@ -356,7 +364,6 @@ def load_model(model_name,
356
364
  activation_potentiation = [x for x in activation_potentiation if not (isinstance(x, float) and np.isnan(x))]
357
365
  activation_potentiation = [item for item in activation_potentiation if item != '']
358
366
 
359
-
360
367
  device_version = __version__
361
368
 
362
369
  try:
@@ -374,27 +381,34 @@ def load_model(model_name,
374
381
  if model_type == 'MLP' or model_type == 'PTNN': allow_pickle = True
375
382
  else: allow_pickle = False
376
383
 
377
- if WeightType == 'txt':
378
- W = (np.loadtxt(model_path + model_name + f'_weights.txt'))
379
- elif WeightType == 'npy':
380
- W = (np.load(model_path + model_name + f'_weights.npy', allow_pickle=allow_pickle))
381
- elif WeightType == 'mat':
382
- W = (sio.loadmat(model_path + model_name + f'_weights.mat'))
383
- elif WeightType == 'pkl':
384
- with open(model_path + model_name + f'_weights.pkl', 'rb') as f:
385
- W = pickle.load(f)
386
- else:
387
-
388
- raise ValueError(
384
+ try:
385
+ if WeightType == 'txt':
386
+ W = (np.loadtxt(model_path + model_name + f'_weights.txt'))
387
+ elif WeightType == 'npy':
388
+ W = (np.load(model_path + model_name + f'_weights.npy', allow_pickle=allow_pickle))
389
+ elif WeightType == 'mat':
390
+ W = (sio.loadmat(model_path + model_name + f'_weights.mat'))
391
+ elif WeightType == 'pkl':
392
+ with open(model_path + model_name + f'_weights.pkl', 'rb') as f:
393
+ W = pickle.load(f)
394
+ else:
395
+ raise ValueError(
389
396
  Fore.RED + "Incorrect weight type value. Value must be 'txt', 'npy', 'pkl' or 'mat' from: load_model." + Style.RESET_ALL)
397
+
398
+ except OSError as e:
399
+ raise OSError(Fore.RED + f"ERROR: An OSError error occurred in load_model at loading weights. Maybe model name or path or administration issue: {e}" + Style.RESET_ALL) from e
400
+
390
401
 
391
402
  if WeightType == 'mat':
392
403
  W = W['w']
393
404
 
394
- if model_type == 'MLP':
405
+ if model_type == 'MLP' or model_type == 'PTNN':
395
406
  W = W.tolist()
396
407
  W = [cp.array(item) for item in W]
397
408
 
409
+ elif model_type == 'PLAN':
410
+ W = cp.array(W)
411
+
398
412
  return W, None, test_acc, activations, scaler_params, None, model_type, WeightType, WeightFormat, device_version, df, activation_potentiation
399
413
 
400
414
 
@@ -406,7 +420,7 @@ def predict_from_storage(Input, model_name, model_path='', dtype=cp.float32):
406
420
  from storage
407
421
 
408
422
  Args:
409
- Input (list or ndarray or cupyarray): Input data for the model (single vector or single matrix).
423
+ Input (list or ndarray or cupyarray): Input data for the model.
410
424
 
411
425
  model_name (str): Name of the model.
412
426
 
@@ -419,8 +433,8 @@ def predict_from_storage(Input, model_name, model_path='', dtype=cp.float32):
419
433
 
420
434
  Input = cp.array(Input, dtype=dtype, copy=False)
421
435
 
422
- from .activation_functions_cuda import apply_activation
423
- from .data_operations_cuda import standard_scaler
436
+ from .activation_functions import apply_activation
437
+ from .data_ops import standard_scaler
424
438
 
425
439
  try:
426
440
 
@@ -472,9 +486,8 @@ def predict_from_storage(Input, model_name, model_path='', dtype=cp.float32):
472
486
 
473
487
  return result
474
488
 
475
- except:
476
- print(Fore.RED + "ERROR: Unexpected Output or wrong model parameters from: predict_model_ssd." + Style.RESET_ALL)
477
- sys.exit(),
489
+ except Exception as e:
490
+ raise RuntimeError(Fore.RED + f"ERROR: An error occurred in predict_from_storage {e}" + Style.RESET_ALL) from e
478
491
 
479
492
 
480
493
 
@@ -484,7 +497,7 @@ def reverse_predict_from_storage(output, model_name, model_path='', dtype=cp.flo
484
497
  reverse prediction function from storage
485
498
  Args:
486
499
 
487
- output (list or ndarray): output layer for the model (single probability vector, output layer of trained model).
500
+ output (list or ndarray): output layer for the model.
488
501
 
489
502
  model_name (str): Name of the model.
490
503
 
@@ -505,9 +518,8 @@ def reverse_predict_from_storage(output, model_name, model_path='', dtype=cp.flo
505
518
  try:
506
519
  Input = W.T @ output
507
520
  return Input
508
- except:
509
- print(Fore.RED + "ERROR: Unexpected Output or wrong model parameters from: reverse_predict_model_ssd." + Style.RESET_ALL)
510
- sys.exit()
521
+ except Exception as e:
522
+ raise RuntimeError(Fore.RED + f"ERROR: An error occurred {e}" + Style.RESET_ALL) from e
511
523
 
512
524
 
513
525
  def predict_from_memory(Input, W, scaler_params=None, activations=['linear'], activation_potentiation=None, model_type='PLAN'):
@@ -517,7 +529,7 @@ def predict_from_memory(Input, W, scaler_params=None, activations=['linear'], ac
517
529
  from memory.
518
530
 
519
531
  Args:
520
- Input (list or ndarray): Input data for the model (single vector or single matrix).
532
+ Input (list or ndarray): Input data for the model.
521
533
 
522
534
  W (list of ndarrays): Weights of the model.
523
535
 
@@ -533,18 +545,20 @@ def predict_from_memory(Input, W, scaler_params=None, activations=['linear'], ac
533
545
  cupyarray: Output from the model.
534
546
  """
535
547
 
536
- from .data_operations_cuda import standard_scaler
537
- from .activation_functions_cuda import apply_activation
548
+ from .data_ops import standard_scaler
549
+ from .activation_functions import apply_activation
550
+
551
+ if model_type != 'PLAN' and model_type != 'MLP' and model_type != 'PTNN': raise ValueError("model_type parameter must be 'PLAN', 'MLP' or 'PTNN'.")
538
552
 
539
553
  try:
540
-
554
+
555
+ Input = standard_scaler(None, Input, scaler_params)
556
+
541
557
  if isinstance(activations, str):
542
558
  activations = [activations]
543
559
  elif isinstance(activations, list):
544
560
  activations = [item if isinstance(item, list) or isinstance(item, str) else [item] for item in activations]
545
561
 
546
- Input = standard_scaler(None, Input, scaler_params)
547
-
548
562
  if model_type == 'MLP':
549
563
  layer = Input
550
564
  for i in range(len(W)):
@@ -577,10 +591,10 @@ def predict_from_memory(Input, W, scaler_params=None, activations=['linear'], ac
577
591
  result = layer
578
592
 
579
593
  return result
594
+
595
+ except Exception as e:
596
+ raise RuntimeError(Fore.RED + f"ERROR: An error occurred in predict_from_memory {e}" + Style.RESET_ALL) from e
580
597
 
581
- except:
582
- print(Fore.RED + "ERROR: Unexpected input or wrong model parameters from: predict_model_ram." + Style.RESET_ALL)
583
- sys.exit()
584
598
 
585
599
 
586
600
  def reverse_predict_from_memory(output, W, dtype=cp.float32):
@@ -590,7 +604,7 @@ def reverse_predict_from_memory(output, W, dtype=cp.float32):
590
604
 
591
605
  Args:
592
606
 
593
- output (list or ndarray): output layer for the model (single probability vector, output layer of trained model).
607
+ output (list or ndarray): output layer for the model.
594
608
 
595
609
  W (list of ndarrays): Weights of the model.
596
610
 
@@ -606,9 +620,8 @@ def reverse_predict_from_memory(output, W, dtype=cp.float32):
606
620
  Input = W.T @ output
607
621
  return Input
608
622
 
609
- except:
610
- print(Fore.RED + "ERROR: Unexpected Output or wrong model parameters from: reverse_predict_model_ram." + Style.RESET_ALL)
611
- sys.exit()
623
+ except Exception as e:
624
+ raise RuntimeError(Fore.RED + f"ERROR: An error occurred {e}" + Style.RESET_ALL) from e
612
625
 
613
626
 
614
627
  def get_weights():