pyerualjetwork 4.3.8.dev15__py3-none-any.whl → 4.3.9__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 +1 -1
- pyerualjetwork/activation_functions.py +2 -2
- pyerualjetwork/activation_functions_cuda.py +63 -114
- pyerualjetwork/data_operations_cuda.py +1 -1
- pyerualjetwork/fitness_functions.py +72 -0
- pyerualjetwork/fitness_functions_cuda.py +85 -0
- pyerualjetwork/model_operations.py +14 -14
- pyerualjetwork/model_operations_cuda.py +16 -17
- pyerualjetwork/plan.py +159 -382
- pyerualjetwork/plan_cuda.py +149 -387
- pyerualjetwork/planeat.py +24 -54
- pyerualjetwork/planeat_cuda.py +11 -47
- pyerualjetwork/visualizations.py +33 -30
- pyerualjetwork/visualizations_cuda.py +22 -24
- {pyerualjetwork-4.3.8.dev15.dist-info → pyerualjetwork-4.3.9.dist-info}/METADATA +3 -19
- pyerualjetwork-4.3.9.dist-info/RECORD +24 -0
- pyerualjetwork-4.3.9.dist-info/top_level.txt +1 -0
- pyerualjetwork/loss_functions.py +0 -21
- pyerualjetwork/loss_functions_cuda.py +0 -21
- pyerualjetwork-4.3.8.dev15.dist-info/RECORD +0 -45
- pyerualjetwork-4.3.8.dev15.dist-info/top_level.txt +0 -2
- pyerualjetwork_afterburner/__init__.py +0 -11
- pyerualjetwork_afterburner/activation_functions.py +0 -290
- pyerualjetwork_afterburner/activation_functions_cuda.py +0 -289
- pyerualjetwork_afterburner/data_operations.py +0 -406
- pyerualjetwork_afterburner/data_operations_cuda.py +0 -461
- pyerualjetwork_afterburner/help.py +0 -17
- pyerualjetwork_afterburner/loss_functions.py +0 -21
- pyerualjetwork_afterburner/loss_functions_cuda.py +0 -21
- pyerualjetwork_afterburner/memory_operations.py +0 -298
- pyerualjetwork_afterburner/metrics.py +0 -190
- pyerualjetwork_afterburner/metrics_cuda.py +0 -163
- pyerualjetwork_afterburner/model_operations.py +0 -408
- pyerualjetwork_afterburner/model_operations_cuda.py +0 -420
- pyerualjetwork_afterburner/parallel.py +0 -118
- pyerualjetwork_afterburner/plan.py +0 -432
- pyerualjetwork_afterburner/plan_cuda.py +0 -441
- pyerualjetwork_afterburner/planeat.py +0 -793
- pyerualjetwork_afterburner/planeat_cuda.py +0 -752
- pyerualjetwork_afterburner/ui.py +0 -22
- pyerualjetwork_afterburner/visualizations.py +0 -823
- pyerualjetwork_afterburner/visualizations_cuda.py +0 -825
- {pyerualjetwork-4.3.8.dev15.dist-info → pyerualjetwork-4.3.9.dist-info}/WHEEL +0 -0
pyerualjetwork/__init__.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
__version__ = "4.3.
|
1
|
+
__version__ = "4.3.9"
|
2
2
|
__update__ = "* Changes: https://github.com/HCB06/PyerualJetwork/blob/main/CHANGES\n* PyerualJetwork Homepage: https://github.com/HCB06/PyerualJetwork/tree/main\n* PyerualJetwork document: https://github.com/HCB06/PyerualJetwork/blob/main/Welcome_to_PyerualJetwork/PYERUALJETWORK_USER_MANUEL_AND_LEGAL_INFORMATION(EN).pdf\n* YouTube tutorials: https://www.youtube.com/@HasanCanBeydili"
|
3
3
|
|
4
4
|
def print_version(__version__):
|
@@ -217,124 +217,73 @@ def scaled_cubic(x, alpha=1.0):
|
|
217
217
|
def sine_offset(x, beta=0.0):
|
218
218
|
return cp.sin(x + beta)
|
219
219
|
|
220
|
-
|
221
|
-
def safe_add(current_sum, new_value):
|
222
|
-
try:
|
223
|
-
return current_sum + new_value
|
224
|
-
except OverflowError:
|
225
|
-
return cp.array(current_sum) + cp.array(new_value)
|
226
220
|
|
227
221
|
def apply_activation(Input, activation_list):
|
228
222
|
"""
|
229
|
-
|
230
|
-
|
231
|
-
Args:
|
232
|
-
Input (cupy.ndarray): The input to apply activations to.
|
233
|
-
activation_list (list): A list of activation function names to apply.
|
234
|
-
|
235
|
-
Returns:
|
236
|
-
cupy.ndarray: The input after all activations have been applied.
|
237
|
-
"""
|
223
|
+
Applies activation functions for inputs
|
238
224
|
|
225
|
+
Args:
|
226
|
+
Input (cupy.ndarray):
|
227
|
+
activation_list (list):
|
228
|
+
"""
|
239
229
|
origin_input = cp.copy(Input)
|
230
|
+
|
231
|
+
activation_functions = {
|
232
|
+
'sigmoid': Sigmoid,
|
233
|
+
'swish': swish,
|
234
|
+
'mod_circular': modular_circular_activation,
|
235
|
+
'tanh_circular': tanh_circular_activation,
|
236
|
+
'leaky_relu': leaky_relu,
|
237
|
+
'relu': Relu,
|
238
|
+
'softplus': softplus,
|
239
|
+
'elu': elu,
|
240
|
+
'gelu': gelu,
|
241
|
+
'selu': selu,
|
242
|
+
'tanh': tanh,
|
243
|
+
'sinakt': sinakt,
|
244
|
+
'p_squared': p_squared,
|
245
|
+
'sglu': lambda x: sglu(x, alpha=1.0),
|
246
|
+
'dlrelu': dlrelu,
|
247
|
+
'exsig': exsig,
|
248
|
+
'sin_plus': sin_plus,
|
249
|
+
'acos': lambda x: acos(x, alpha=1.0, beta=0.0),
|
250
|
+
'gla': lambda x: gla(x, alpha=1.0, mu=0.0),
|
251
|
+
'srelu': srelu,
|
252
|
+
'qelu': qelu,
|
253
|
+
'isra': isra,
|
254
|
+
'waveakt': waveakt,
|
255
|
+
'arctan': arctan,
|
256
|
+
'bent_identity': bent_identity,
|
257
|
+
'sech': sech,
|
258
|
+
'softsign': softsign,
|
259
|
+
'pwl': pwl,
|
260
|
+
'cubic': cubic,
|
261
|
+
'gaussian': gaussian,
|
262
|
+
'sine': sine,
|
263
|
+
'tanh_square': tanh_square,
|
264
|
+
'mod_sigmoid': mod_sigmoid,
|
265
|
+
'linear': lambda x: x,
|
266
|
+
'quartic': quartic,
|
267
|
+
'square_quartic': square_quartic,
|
268
|
+
'cubic_quadratic': cubic_quadratic,
|
269
|
+
'exp_cubic': exp_cubic,
|
270
|
+
'sine_square': sine_square,
|
271
|
+
'logarithmic': logarithmic,
|
272
|
+
'scaled_cubic': lambda x: scaled_cubic(x, 1.0),
|
273
|
+
'sine_offset': lambda x: sine_offset(x, 1.0),
|
274
|
+
'spiral': spiral_activation,
|
275
|
+
'circular': circular_activation
|
276
|
+
}
|
277
|
+
|
278
|
+
try:
|
279
|
+
|
280
|
+
valid_mask = cp.array([act in activation_functions for act in activation_list])
|
281
|
+
valid_activations = cp.array(activation_list)[valid_mask]
|
282
|
+
|
283
|
+
activation_outputs = cp.array([activation_functions[act](origin_input) for act in valid_activations])
|
240
284
|
|
241
|
-
|
242
|
-
try:
|
243
|
-
if activation_list[i] == 'sigmoid':
|
244
|
-
Input = safe_add(Input, Sigmoid(origin_input))
|
245
|
-
elif activation_list[i] == 'swish':
|
246
|
-
Input = safe_add(Input, swish(origin_input))
|
247
|
-
elif activation_list[i] == 'mod_circular':
|
248
|
-
Input = safe_add(Input, modular_circular_activation(origin_input))
|
249
|
-
elif activation_list[i] == 'tanh_circular':
|
250
|
-
Input = safe_add(Input, tanh_circular_activation(origin_input))
|
251
|
-
elif activation_list[i] == 'leaky_relu':
|
252
|
-
Input = safe_add(Input, leaky_relu(origin_input))
|
253
|
-
elif activation_list[i] == 'relu':
|
254
|
-
Input = safe_add(Input, Relu(origin_input))
|
255
|
-
elif activation_list[i] == 'softplus':
|
256
|
-
Input = safe_add(Input, softplus(origin_input))
|
257
|
-
elif activation_list[i] == 'elu':
|
258
|
-
Input = safe_add(Input, elu(origin_input))
|
259
|
-
elif activation_list[i] == 'gelu':
|
260
|
-
Input = safe_add(Input, gelu(origin_input))
|
261
|
-
elif activation_list[i] == 'selu':
|
262
|
-
Input = safe_add(Input, selu(origin_input))
|
263
|
-
elif activation_list[i] == 'tanh':
|
264
|
-
Input = safe_add(Input, tanh(origin_input))
|
265
|
-
elif activation_list[i] == 'sinakt':
|
266
|
-
Input = safe_add(Input, sinakt(origin_input))
|
267
|
-
elif activation_list[i] == 'p_squared':
|
268
|
-
Input = safe_add(Input, p_squared(origin_input))
|
269
|
-
elif activation_list[i] == 'sglu':
|
270
|
-
Input = safe_add(Input, sglu(origin_input, alpha=1.0))
|
271
|
-
elif activation_list[i] == 'dlrelu':
|
272
|
-
Input = safe_add(Input, dlrelu(origin_input))
|
273
|
-
elif activation_list[i] == 'exsig':
|
274
|
-
Input = safe_add(Input, exsig(origin_input))
|
275
|
-
elif activation_list[i] == 'sin_plus':
|
276
|
-
Input = safe_add(Input, sin_plus(origin_input))
|
277
|
-
elif activation_list[i] == 'acos':
|
278
|
-
Input = safe_add(Input, acos(origin_input, alpha=1.0, beta=0.0))
|
279
|
-
elif activation_list[i] == 'gla':
|
280
|
-
Input = safe_add(Input, gla(origin_input, alpha=1.0, mu=0.0))
|
281
|
-
elif activation_list[i] == 'srelu':
|
282
|
-
Input = safe_add(Input, srelu(origin_input))
|
283
|
-
elif activation_list[i] == 'qelu':
|
284
|
-
Input = safe_add(Input, qelu(origin_input))
|
285
|
-
elif activation_list[i] == 'isra':
|
286
|
-
Input = safe_add(Input, isra(origin_input))
|
287
|
-
elif activation_list[i] == 'waveakt':
|
288
|
-
Input = safe_add(Input, waveakt(origin_input))
|
289
|
-
elif activation_list[i] == 'arctan':
|
290
|
-
Input = safe_add(Input, arctan(origin_input))
|
291
|
-
elif activation_list[i] == 'bent_identity':
|
292
|
-
Input = safe_add(Input, bent_identity(origin_input))
|
293
|
-
elif activation_list[i] == 'sech':
|
294
|
-
Input = safe_add(Input, sech(origin_input))
|
295
|
-
elif activation_list[i] == 'softsign':
|
296
|
-
Input = safe_add(Input, softsign(origin_input))
|
297
|
-
elif activation_list[i] == 'pwl':
|
298
|
-
Input = safe_add(Input, pwl(origin_input))
|
299
|
-
elif activation_list[i] == 'cubic':
|
300
|
-
Input = safe_add(Input, cubic(origin_input))
|
301
|
-
elif activation_list[i] == 'gaussian':
|
302
|
-
Input = safe_add(Input, gaussian(origin_input))
|
303
|
-
elif activation_list[i] == 'sine':
|
304
|
-
Input = safe_add(Input, sine(origin_input))
|
305
|
-
elif activation_list[i] == 'tanh_square':
|
306
|
-
Input = safe_add(Input, tanh_square(origin_input))
|
307
|
-
elif activation_list[i] == 'mod_sigmoid':
|
308
|
-
Input = safe_add(Input, mod_sigmoid(origin_input))
|
309
|
-
elif activation_list[i] == 'linear':
|
310
|
-
Input = safe_add(Input, origin_input)
|
311
|
-
elif activation_list[i] == 'quartic':
|
312
|
-
Input = safe_add(Input, quartic(origin_input))
|
313
|
-
elif activation_list[i] == 'square_quartic':
|
314
|
-
Input = safe_add(Input, square_quartic(origin_input))
|
315
|
-
elif activation_list[i] == 'cubic_quadratic':
|
316
|
-
Input = safe_add(Input, cubic_quadratic(origin_input))
|
317
|
-
elif activation_list[i] == 'exp_cubic':
|
318
|
-
Input = safe_add(Input, exp_cubic(origin_input))
|
319
|
-
elif activation_list[i] == 'sine_square':
|
320
|
-
Input = safe_add(Input, sine_square(origin_input))
|
321
|
-
elif activation_list[i] == 'logarithmic':
|
322
|
-
Input = safe_add(Input, logarithmic(origin_input))
|
323
|
-
elif activation_list[i] == 'scaled_cubic':
|
324
|
-
Input = safe_add(Input, scaled_cubic(origin_input, 1.0))
|
325
|
-
elif activation_list[i] == 'sine_offset':
|
326
|
-
Input = safe_add(Input, sine_offset(origin_input, 1.0))
|
327
|
-
elif activation_list[i] == 'spiral':
|
328
|
-
Input = safe_add(Input, spiral_activation(origin_input))
|
329
|
-
elif activation_list[i] == 'circular':
|
330
|
-
Input = safe_add(Input, circular_activation(origin_input))
|
285
|
+
return Input + cp.sum(activation_outputs, axis=0)
|
331
286
|
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
Input = cp.array(Input)
|
336
|
-
if not isinstance(origin_input, cp.ndarray):
|
337
|
-
origin_input = cp.array(origin_input)
|
338
|
-
continue
|
339
|
-
|
340
|
-
return Input
|
287
|
+
except Exception as e:
|
288
|
+
warnings.warn(f"Error in activation processing: {str(e)}", RuntimeWarning)
|
289
|
+
return Input
|
@@ -0,0 +1,72 @@
|
|
1
|
+
import numpy as np
|
2
|
+
from scipy.spatial.distance import pdist
|
3
|
+
|
4
|
+
def diversity_score(population):
|
5
|
+
"""
|
6
|
+
Calculates the diversity score of a population based on the
|
7
|
+
Euclidean distances between individuals in the population.
|
8
|
+
|
9
|
+
:param population: That calculates the diversity score of a population based on the Euclidean distances between
|
10
|
+
individuals in the population
|
11
|
+
:return: The function returns the diversity score,
|
12
|
+
which is a measure of how spread out or diverse the population is in terms of their characteristics.
|
13
|
+
"""
|
14
|
+
if len(population) < 2:
|
15
|
+
return 0
|
16
|
+
|
17
|
+
population = np.nan_to_num(population, nan=0.0)
|
18
|
+
|
19
|
+
distances = pdist(population, metric='euclidean')
|
20
|
+
distances = np.maximum(distances, 1e-10)
|
21
|
+
|
22
|
+
avg_distance = np.mean(distances)
|
23
|
+
if population.shape[1] == 0:
|
24
|
+
return 0
|
25
|
+
|
26
|
+
max_possible_distance = np.sqrt(population.shape[1])
|
27
|
+
max_possible_distance = max(max_possible_distance, 1e-10)
|
28
|
+
|
29
|
+
diversity = avg_distance / max_possible_distance
|
30
|
+
return diversity
|
31
|
+
|
32
|
+
def multi_head_fitness(y_true, y_pred, diversity_score, accuracy, alpha=2, beta=1.5, lambda_div=0.05):
|
33
|
+
"""
|
34
|
+
The function calculates a fitness score based on accuracy, margin loss, and diversity score using
|
35
|
+
specified parameters.
|
36
|
+
|
37
|
+
@param y_true The `y_true` parameter represents the true labels of the data points. It is an array
|
38
|
+
or list containing the actual labels of the data points.
|
39
|
+
@param y_pred The `y_pred` parameter in the `multi_head_fitness` function represents the
|
40
|
+
predicted values for a given dataset. It is a NumPy array containing the predicted values for each
|
41
|
+
sample in the dataset.
|
42
|
+
@param diversity_score The `diversity_score` parameter in the `multi_head_fitness` function
|
43
|
+
represents a measure of diversity in the predictions. It is used as a factor in calculating the
|
44
|
+
fitness of the model. The function combines accuracy, margin loss, and diversity score to evaluate
|
45
|
+
the overall performance of the model
|
46
|
+
@param accuracy Accuracy is a measure of the correct predictions made by a model. It is typically
|
47
|
+
calculated as the number of correct predictions divided by the total number of predictions. In the
|
48
|
+
context of the `multi_head_fitness` function, the accuracy parameter represents the accuracy
|
49
|
+
of the model's predictions.
|
50
|
+
@param alpha Alpha is a parameter that controls the impact of accuracy on the overall fitness score
|
51
|
+
in the multi_head_fitness function. It is used as an exponent to raise the accuracy value
|
52
|
+
to, influencing its contribution to the fitness calculation.
|
53
|
+
@param beta The `beta` parameter in the `multi_head_fitness` function is used as an exponent
|
54
|
+
in the fitness calculation formula. It controls the impact of the margin loss term on the overall
|
55
|
+
fitness value. A higher value of `beta` will amplify the effect of the margin loss term, making it
|
56
|
+
@param lambda_div The `lambda_div` parameter in the `multi_head_fitness` function represents
|
57
|
+
the weight given to the diversity score in calculating the fitness value. It is a hyperparameter
|
58
|
+
that controls the impact of diversity score on the overall fitness calculation. A higher value of
|
59
|
+
`lambda_div` will increase the importance
|
60
|
+
@return The function `multi_head_fitness` returns the fitness value calculated based on the
|
61
|
+
input parameters `y_true`, `y_pred`, `diversity_score`, `accuracy`, and optional parameters `alpha`,
|
62
|
+
`beta`, and `lambda_div`. The fitness value is computed using a formula that combines accuracy,
|
63
|
+
margin loss, and diversity score with specified weights and coefficients.
|
64
|
+
"""
|
65
|
+
incorrect = y_true != y_pred
|
66
|
+
margin_loss = np.abs(y_true[incorrect] - y_pred[incorrect]).mean() if np.any(incorrect) else 0
|
67
|
+
|
68
|
+
margin_loss = np.nan_to_num(margin_loss, nan=0.0)
|
69
|
+
accuracy = max(accuracy, 1e-10)
|
70
|
+
|
71
|
+
fitness = (accuracy ** alpha) * ((1 - margin_loss) ** beta) * (1 + lambda_div * diversity_score)
|
72
|
+
return fitness
|
@@ -0,0 +1,85 @@
|
|
1
|
+
import cupy as cp
|
2
|
+
|
3
|
+
def cupy_pairwise_distances(X):
|
4
|
+
"""
|
5
|
+
Pairwise Euclidean distances
|
6
|
+
"""
|
7
|
+
r = cp.sum(X * X, 1)
|
8
|
+
r = r.reshape(-1, 1)
|
9
|
+
|
10
|
+
distances = cp.maximum(r - 2 * cp.dot(X, X.T) + r.T, 0.0)
|
11
|
+
|
12
|
+
triu_indices = cp.triu_indices(distances.shape[0], k=1)
|
13
|
+
return cp.sqrt(distances[triu_indices])
|
14
|
+
|
15
|
+
|
16
|
+
def diversity_score(population):
|
17
|
+
"""
|
18
|
+
Calculates the diversity score of a population based on the
|
19
|
+
Euclidean distances between individuals in the population.
|
20
|
+
|
21
|
+
:param population: That calculates the diversity score of a population based on the Euclidean distances between
|
22
|
+
individuals in the population
|
23
|
+
:return: The function returns the diversity score,
|
24
|
+
which is a measure of how spread out or diverse the population is in terms of their characteristics.
|
25
|
+
"""
|
26
|
+
if len(population) < 2:
|
27
|
+
return 0
|
28
|
+
|
29
|
+
population = cp.nan_to_num(population, nan=0.0)
|
30
|
+
|
31
|
+
distances = cupy_pairwise_distances(population)
|
32
|
+
distances = cp.maximum(distances, 1e-10)
|
33
|
+
|
34
|
+
avg_distance = cp.mean(distances)
|
35
|
+
if population.shape[1] == 0:
|
36
|
+
return 0
|
37
|
+
|
38
|
+
max_possible_distance = cp.sqrt(population.shape[1])
|
39
|
+
max_possible_distance = float(max(max_possible_distance, 1e-10))
|
40
|
+
|
41
|
+
diversity = float(avg_distance / max_possible_distance)
|
42
|
+
return diversity
|
43
|
+
|
44
|
+
|
45
|
+
def multi_head_fitness(y_true, y_pred, diversity_score, accuracy, alpha=2, beta=1.5, lambda_div=0.05):
|
46
|
+
"""
|
47
|
+
The function calculates a fitness score based on accuracy, margin loss, and diversity score using
|
48
|
+
specified parameters.
|
49
|
+
|
50
|
+
@param y_true The `y_true` parameter represents the true labels of the data points. It is an array
|
51
|
+
or list containing the actual labels of the data points.
|
52
|
+
@param y_pred The `y_pred` parameter in the `multi_head_fitness` function represents the
|
53
|
+
predicted values for a given dataset. It is a NumPy array containing the predicted values for each
|
54
|
+
sample in the dataset.
|
55
|
+
@param diversity_score The `diversity_score` parameter in the `multi_head_fitness` function
|
56
|
+
represents a measure of diversity in the predictions. It is used as a factor in calculating the
|
57
|
+
fitness of the model. The function combines accuracy, margin loss, and diversity score to evaluate
|
58
|
+
the overall performance of the model
|
59
|
+
@param accuracy Accuracy is a measure of the correct predictions made by a model. It is typically
|
60
|
+
calculated as the number of correct predictions divided by the total number of predictions. In the
|
61
|
+
context of the `multi_head_fitness` function, the accuracy parameter represents the accuracy
|
62
|
+
of the model's predictions.
|
63
|
+
@param alpha Alpha is a parameter that controls the impact of accuracy on the overall fitness score
|
64
|
+
in the multi_head_fitness function. It is used as an exponent to raise the accuracy value
|
65
|
+
to, influencing its contribution to the fitness calculation.
|
66
|
+
@param beta The `beta` parameter in the `multi_head_fitness` function is used as an exponent
|
67
|
+
in the fitness calculation formula. It controls the impact of the margin loss term on the overall
|
68
|
+
fitness value. A higher value of `beta` will amplify the effect of the margin loss term, making it
|
69
|
+
@param lambda_div The `lambda_div` parameter in the `multi_head_fitness` function represents
|
70
|
+
the weight given to the diversity score in calculating the fitness value. It is a hyperparameter
|
71
|
+
that controls the impact of diversity score on the overall fitness calculation. A higher value of
|
72
|
+
`lambda_div` will increase the importance
|
73
|
+
@return The function `multi_head_fitness` returns the fitness value calculated based on the
|
74
|
+
icput parameters `y_true`, `y_pred`, `diversity_score`, `accuracy`, and optional parameters `alpha`,
|
75
|
+
`beta`, and `lambda_div`. The fitness value is computed using a formula that combines accuracy,
|
76
|
+
margin loss, and diversity score with specified weights and coefficients.
|
77
|
+
"""
|
78
|
+
incorrect = y_true != y_pred
|
79
|
+
margin_loss = cp.abs(y_true[incorrect] - y_pred[incorrect]).mean() if cp.any(incorrect) else 0
|
80
|
+
|
81
|
+
margin_loss = cp.nan_to_num(margin_loss, nan=0.0)
|
82
|
+
accuracy = max(accuracy, 1e-10)
|
83
|
+
|
84
|
+
fitness = (accuracy ** alpha) * ((1 - margin_loss) ** beta) * (1 + lambda_div * diversity_score)
|
85
|
+
return fitness
|
@@ -258,7 +258,7 @@ def predict_model_ssd(Input, model_name, model_path='', dtype=np.float32):
|
|
258
258
|
ndarray: Output from the model.
|
259
259
|
"""
|
260
260
|
|
261
|
-
from .
|
261
|
+
from .activation_functions import apply_activation
|
262
262
|
from .data_operations import standard_scaler
|
263
263
|
|
264
264
|
model = load_model(model_name, model_path)
|
@@ -269,12 +269,12 @@ def predict_model_ssd(Input, model_name, model_path='', dtype=np.float32):
|
|
269
269
|
|
270
270
|
Input = standard_scaler(None, Input, scaler_params, dtype=dtype)
|
271
271
|
|
272
|
-
|
273
|
-
|
274
|
-
neural_layer = neural_layer.ravel()
|
272
|
+
Input = np.array(Input, dtype=dtype, copy=False)
|
273
|
+
Input = Input.ravel()
|
275
274
|
|
276
275
|
try:
|
277
|
-
|
276
|
+
Input = apply_activation(Input, activation_potentiation)
|
277
|
+
neural_layer = Input @ W.T
|
278
278
|
return neural_layer
|
279
279
|
except:
|
280
280
|
print(Fore.RED + "ERROR: Unexpected Output or wrong model parameters from: predict_model_ssd." + Style.RESET_ALL)
|
@@ -304,7 +304,7 @@ def reverse_predict_model_ssd(output, model_name, model_path='', dtype=np.float3
|
|
304
304
|
W = model[get_weights()]
|
305
305
|
|
306
306
|
try:
|
307
|
-
Input =
|
307
|
+
Input = W.T @ output
|
308
308
|
return Input
|
309
309
|
except:
|
310
310
|
print(Fore.RED + "ERROR: Unexpected Output or wrong model parameters from: reverse_predict_model_ssd." + Style.RESET_ALL)
|
@@ -334,18 +334,18 @@ def predict_model_ram(Input, W, scaler_params=None, activation_potentiation=['li
|
|
334
334
|
ndarray: Output from the model.
|
335
335
|
"""
|
336
336
|
|
337
|
-
from data_operations import standard_scaler
|
338
|
-
from
|
337
|
+
from .data_operations import standard_scaler
|
338
|
+
from .activation_functions import apply_activation
|
339
339
|
|
340
340
|
Input = standard_scaler(None, Input, scaler_params, dtype=dtype)
|
341
341
|
|
342
|
+
Input = np.array(Input, dtype=dtype, copy=False)
|
343
|
+
Input = Input.ravel()
|
344
|
+
|
342
345
|
try:
|
343
346
|
|
344
|
-
|
345
|
-
neural_layer =
|
346
|
-
neural_layer = neural_layer.ravel()
|
347
|
-
|
348
|
-
neural_layer = feed_forward(neural_layer, np.copy(W.astype(dtype, copy=False)), is_training=False, Class='?', activation_potentiation=activation_potentiation)
|
347
|
+
Input = apply_activation(Input, activation_potentiation)
|
348
|
+
neural_layer = Input @ W.T
|
349
349
|
|
350
350
|
return neural_layer
|
351
351
|
|
@@ -371,7 +371,7 @@ def reverse_predict_model_ram(output, W, dtype=np.float32):
|
|
371
371
|
"""
|
372
372
|
|
373
373
|
try:
|
374
|
-
Input =
|
374
|
+
Input = W.T @ output
|
375
375
|
return Input
|
376
376
|
|
377
377
|
except:
|
@@ -263,10 +263,10 @@ def predict_model_ssd(Input, model_name, model_path='', dtype=cp.float32):
|
|
263
263
|
Returns:
|
264
264
|
ndarray: Output from the model.
|
265
265
|
"""
|
266
|
-
|
266
|
+
|
267
267
|
Input = cp.array(Input, dtype=dtype, copy=False)
|
268
|
-
|
269
|
-
from .
|
268
|
+
|
269
|
+
from .activation_functions_cuda import apply_activation
|
270
270
|
from .data_operations_cuda import standard_scaler
|
271
271
|
|
272
272
|
model = load_model(model_name, model_path)
|
@@ -277,13 +277,14 @@ def predict_model_ssd(Input, model_name, model_path='', dtype=cp.float32):
|
|
277
277
|
|
278
278
|
Input = standard_scaler(None, Input, scaler_params)
|
279
279
|
|
280
|
-
|
281
|
-
|
282
|
-
neural_layer = neural_layer.ravel()
|
280
|
+
Input = cp.array(Input, dtype=dtype, copy=False)
|
281
|
+
Input = Input.ravel()
|
283
282
|
|
284
283
|
try:
|
285
|
-
|
284
|
+
Input = apply_activation(Input, activation_potentiation)
|
285
|
+
neural_layer = Input @ W.T
|
286
286
|
return neural_layer
|
287
|
+
|
287
288
|
except:
|
288
289
|
print(Fore.RED + "ERROR: Unexpected Output or wrong model parameters from: predict_model_ssd." + Style.RESET_ALL)
|
289
290
|
sys.exit()
|
@@ -314,7 +315,7 @@ def reverse_predict_model_ssd(output, model_name, model_path='', dtype=cp.float3
|
|
314
315
|
W = model[get_weights()]
|
315
316
|
|
316
317
|
try:
|
317
|
-
Input =
|
318
|
+
Input = W.T @ output
|
318
319
|
return Input
|
319
320
|
except:
|
320
321
|
print(Fore.RED + "ERROR: Unexpected Output or wrong model parameters from: reverse_predict_model_ssd." + Style.RESET_ALL)
|
@@ -344,19 +345,17 @@ def predict_model_ram(Input, W, scaler_params=None, activation_potentiation=['li
|
|
344
345
|
"""
|
345
346
|
|
346
347
|
from .data_operations_cuda import standard_scaler
|
347
|
-
from .
|
348
|
+
from .activation_functions_cuda import apply_activation
|
348
349
|
|
349
|
-
Input = cp.array(Input, dtype=dtype, copy=False)
|
350
|
-
|
351
350
|
Input = standard_scaler(None, Input, scaler_params)
|
352
351
|
|
352
|
+
Input = cp.array(Input, dtype=dtype, copy=False)
|
353
|
+
Input = Input.ravel()
|
354
|
+
|
353
355
|
try:
|
354
356
|
|
355
|
-
|
356
|
-
neural_layer =
|
357
|
-
neural_layer = neural_layer.ravel()
|
358
|
-
|
359
|
-
neural_layer = feed_forward(neural_layer, cp.copy(W), is_training=False, Class='?', activation_potentiation=activation_potentiation)
|
357
|
+
Input = apply_activation(Input, activation_potentiation)
|
358
|
+
neural_layer = Input @ W.T
|
360
359
|
|
361
360
|
return neural_layer
|
362
361
|
|
@@ -384,7 +383,7 @@ def reverse_predict_model_ram(output, W, dtype=cp.float32):
|
|
384
383
|
output = cp.array(output, dtype=dtype, copy=False)
|
385
384
|
|
386
385
|
try:
|
387
|
-
Input =
|
386
|
+
Input = W.T @ output
|
388
387
|
return Input
|
389
388
|
|
390
389
|
except:
|