pyerualjetwork 4.5__py3-none-any.whl → 4.5.2__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/data_operations.py +51 -46
- pyerualjetwork/data_operations_cuda.py +48 -51
- pyerualjetwork/fitness_functions.py +3 -8
- pyerualjetwork/memory_operations.py +9 -23
- pyerualjetwork/model_operations.py +43 -55
- pyerualjetwork/model_operations_cuda.py +43 -53
- pyerualjetwork/plan.py +50 -72
- pyerualjetwork/plan_cuda.py +57 -85
- pyerualjetwork/planeat.py +1 -1
- pyerualjetwork/planeat_cuda.py +3 -3
- pyerualjetwork/ui.py +10 -9
- pyerualjetwork/visualizations.py +17 -17
- pyerualjetwork/visualizations_cuda.py +17 -17
- {pyerualjetwork-4.5.dist-info → pyerualjetwork-4.5.2.dist-info}/METADATA +1 -1
- pyerualjetwork-4.5.2.dist-info/RECORD +25 -0
- pyerualjetwork-4.5.dist-info/RECORD +0 -25
- {pyerualjetwork-4.5.dist-info → pyerualjetwork-4.5.2.dist-info}/WHEEL +0 -0
- {pyerualjetwork-4.5.dist-info → pyerualjetwork-4.5.2.dist-info}/top_level.txt +0 -0
pyerualjetwork/__init__.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
__version__ = "4.5"
|
1
|
+
__version__ = "4.5.2"
|
2
2
|
__update__ = """* Changes: https://github.com/HCB06/PyerualJetwork/blob/main/CHANGES
|
3
3
|
* PyerualJetwork Homepage: https://github.com/HCB06/PyerualJetwork/tree/main
|
4
4
|
* PyerualJetwork document: https://github.com/HCB06/PyerualJetwork/blob/main/Welcome_to_PyerualJetwork/PYERUALJETWORK_USER_MANUEL_AND_LEGAL_INFORMATION(EN).pdf
|
@@ -17,9 +17,6 @@ def encode_one_hot(y_train, y_test=None, summary=False):
|
|
17
17
|
tuple: One-hot encoded y_train and (if given) y_test.
|
18
18
|
"""
|
19
19
|
from .memory_operations import optimize_labels
|
20
|
-
|
21
|
-
y_train = optimize_labels(y_train, one_hot_encoded=False, cuda=False)
|
22
|
-
y_test = optimize_labels(y_test, one_hot_encoded=False, cuda=False)
|
23
20
|
|
24
21
|
classes = np.unique(y_train)
|
25
22
|
class_count = len(classes)
|
@@ -34,11 +31,14 @@ def encode_one_hot(y_train, y_test=None, summary=False):
|
|
34
31
|
y_train_encoded = np.zeros((y_train.shape[0], class_count), dtype=y_train.dtype)
|
35
32
|
for i, label in enumerate(y_train):
|
36
33
|
y_train_encoded[i, class_to_index[label]] = 1
|
34
|
+
y_train_encoded = optimize_labels(y_train_encoded, one_hot_encoded=True, cuda=False)
|
37
35
|
|
38
36
|
if y_test is not None:
|
39
37
|
y_test_encoded = np.zeros((y_test.shape[0], class_count), dtype=y_test.dtype)
|
40
38
|
for i, label in enumerate(y_test):
|
41
39
|
y_test_encoded[i, class_to_index[label]] = 1
|
40
|
+
y_test_encoded = optimize_labels(y_test_encoded, one_hot_encoded=True, cuda=False)
|
41
|
+
|
42
42
|
return y_train_encoded, y_test_encoded
|
43
43
|
|
44
44
|
return y_train_encoded
|
@@ -77,11 +77,7 @@ def split(X, y, test_size, random_state=42, dtype=np.float32):
|
|
77
77
|
Returns:
|
78
78
|
tuple: x_train, x_test, y_train, y_test as ordered training and testing data subsets.
|
79
79
|
"""
|
80
|
-
|
81
|
-
|
82
|
-
X = transfer_to_cpu(X, dtype=dtype)
|
83
|
-
y = optimize_labels(y, one_hot_encoded=False, cuda=False)
|
84
|
-
|
80
|
+
|
85
81
|
num_samples = X.shape[0]
|
86
82
|
|
87
83
|
if isinstance(test_size, float):
|
@@ -114,17 +110,23 @@ def manuel_balancer(x_train, y_train, target_samples_per_class, dtype=np.float32
|
|
114
110
|
"""
|
115
111
|
Generates synthetic examples to balance classes to the specified number of examples per class.
|
116
112
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
113
|
+
Args:
|
114
|
+
|
115
|
+
x_train: numpy array format
|
116
|
+
|
117
|
+
y_train (one-hot encoded): numpy array format
|
118
|
+
|
119
|
+
target_samples_per_class (int): Desired number of samples per class
|
120
|
+
|
121
|
+
dtype (numpy.dtype): Data type for the arrays. np.float32 by default. Example: np.float64 or np.float16.
|
122
|
+
|
123
|
+
shuffle_in_cpu (bool): If True, output will be same cpu's manuel_balancer function. Default: False. (Use this for direct comparison of cpu training.)
|
122
124
|
|
123
125
|
Returns:
|
124
|
-
|
125
|
-
|
126
|
+
x_balanced -- Balanced input dataset (numpy array format)
|
127
|
+
y_balanced -- Balanced class labels (one-hot encoded, numpy array format)
|
126
128
|
"""
|
127
|
-
from .ui import loading_bars
|
129
|
+
from .ui import loading_bars, get_loading_bar_style
|
128
130
|
from .memory_operations import transfer_to_cpu
|
129
131
|
|
130
132
|
x_train = transfer_to_cpu(x_train, dtype=dtype)
|
@@ -136,7 +138,7 @@ def manuel_balancer(x_train, y_train, target_samples_per_class, dtype=np.float32
|
|
136
138
|
x_balanced = []
|
137
139
|
y_balanced = []
|
138
140
|
|
139
|
-
for class_label in tqdm(range(class_count),leave=False, ascii=
|
141
|
+
for class_label in tqdm(range(class_count),leave=False, ascii=get_loading_bar_style(),
|
140
142
|
bar_format=bar_format,desc='Augmenting Data',ncols= 52):
|
141
143
|
class_indices = np.where(np.argmax(y_train, axis=1) == class_label)[0]
|
142
144
|
num_samples = len(class_indices)
|
@@ -185,17 +187,21 @@ def manuel_balancer(x_train, y_train, target_samples_per_class, dtype=np.float32
|
|
185
187
|
def auto_balancer(x_train, y_train, dtype=np.float32):
|
186
188
|
|
187
189
|
"""
|
188
|
-
|
190
|
+
Function to balance (to min) the training data across different classes.
|
189
191
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
192
|
+
Args:
|
193
|
+
x_train (list): Input data for training.
|
194
|
+
|
195
|
+
y_train (list): Labels corresponding to the input data. (one-hot encoded)
|
196
|
+
|
197
|
+
dtype (numpy.dtype): Data type for the arrays. np.float32 by default. Example: np.float64 or np.float16.
|
194
198
|
|
195
|
-
|
196
|
-
|
199
|
+
shuffle_in_cpu (bool): If True, output will be same cpu's auto_balancer function. Default: False. (Use this for direct comparison of cpu training.)
|
200
|
+
|
201
|
+
Returns:
|
202
|
+
tuple: A tuple containing balanced input data and labels.
|
197
203
|
"""
|
198
|
-
from .ui import loading_bars
|
204
|
+
from .ui import loading_bars, get_loading_bar_style
|
199
205
|
from .memory_operations import transfer_to_cpu
|
200
206
|
|
201
207
|
x_train = transfer_to_cpu(x_train, dtype=dtype)
|
@@ -216,7 +222,7 @@ def auto_balancer(x_train, y_train, dtype=np.float32):
|
|
216
222
|
MinCount = min(classes)
|
217
223
|
|
218
224
|
BalancedIndices = []
|
219
|
-
for i in tqdm(range(class_count),leave=False, ascii=
|
225
|
+
for i in tqdm(range(class_count),leave=False, ascii=get_loading_bar_style(),
|
220
226
|
bar_format= bar_format, desc='Balancing Data',ncols=70):
|
221
227
|
if len(ClassIndices[i]) > MinCount:
|
222
228
|
SelectedIndices = np.random.choice(
|
@@ -248,18 +254,20 @@ def auto_balancer(x_train, y_train, dtype=np.float32):
|
|
248
254
|
|
249
255
|
def synthetic_augmentation(x, y, dtype=np.float32):
|
250
256
|
"""
|
251
|
-
Generates synthetic examples to balance classes with fewer examples.
|
257
|
+
Generates synthetic examples to balance classes with fewer examples using numpy.
|
258
|
+
Args:
|
259
|
+
x_train: numpy array format
|
252
260
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
261
|
+
y_train: numpy array format
|
262
|
+
|
263
|
+
dtype (numpy.dtype): Data type for the arrays. cp.float32 by default. Example: cp.float64 or cp.float16.
|
264
|
+
|
265
|
+
shuffle_in_cpu (bool): If True, output will be same cpu's synthetic_augmentation function. Default: False. (Use this for direct comparison of cpu training.)
|
257
266
|
|
258
267
|
Returns:
|
259
|
-
|
260
|
-
y_balanced -- Balanced class labels (one-hot encoded, array format)
|
268
|
+
x_train_balanced, y_train_balanced (numpy array format)
|
261
269
|
"""
|
262
|
-
from .ui import loading_bars
|
270
|
+
from .ui import loading_bars, get_loading_bar_style
|
263
271
|
from .memory_operations import transfer_to_cpu
|
264
272
|
|
265
273
|
x = transfer_to_cpu(x, dtype=dtype)
|
@@ -278,7 +286,7 @@ def synthetic_augmentation(x, y, dtype=np.float32):
|
|
278
286
|
y_balanced = list(y)
|
279
287
|
|
280
288
|
|
281
|
-
for class_label in tqdm(range(class_count), leave=False, ascii=
|
289
|
+
for class_label in tqdm(range(class_count), leave=False, ascii=get_loading_bar_style(),
|
282
290
|
bar_format=bar_format,desc='Augmenting Data',ncols= 52):
|
283
291
|
class_indices = [i for i, label in enumerate(
|
284
292
|
y) if np.argmax(label) == class_label]
|
@@ -313,19 +321,16 @@ def standard_scaler(x_train=None, x_test=None, scaler_params=None, dtype=np.floa
|
|
313
321
|
Standardizes training and test datasets. x_test may be None.
|
314
322
|
|
315
323
|
Args:
|
316
|
-
x_train
|
324
|
+
x_train (numpy.ndarray):
|
317
325
|
|
318
|
-
x_test
|
326
|
+
x_test (numpy.ndarray): (optional)
|
319
327
|
|
320
|
-
scaler_params (optional for using model)
|
328
|
+
scaler_params (tuple): (optional for using model)
|
321
329
|
|
322
|
-
dtype (numpy.dtype): Data type for the arrays. np.float32 by default. Example: np.float64 or np.float16.
|
330
|
+
dtype (numpy.dtype): Data type for the arrays. np.float32 by default. Example: np.float64 or np.float16.
|
323
331
|
|
324
332
|
Returns:
|
325
|
-
|
326
|
-
Scaler parameters: mean and std
|
327
|
-
tuple
|
328
|
-
Standardized training and test datasets
|
333
|
+
Scaler parameters, Standardized training (and if test given) datasets. (tuple)
|
329
334
|
"""
|
330
335
|
if x_train is not None and scaler_params is None and x_test is not None:
|
331
336
|
x_train = x_train.astype(dtype, copy=False)
|
@@ -381,12 +386,12 @@ def non_neg_normalization(
|
|
381
386
|
Normalizes the input data [0-1] range.
|
382
387
|
|
383
388
|
Args:
|
384
|
-
Input (
|
389
|
+
Input (numpy): Input data to be normalized.
|
385
390
|
|
386
|
-
dtype (
|
391
|
+
dtype (numpy.dtype): Data type for the arrays. cp.float32 by default. Example: cp.float64 or cp.float16.
|
387
392
|
|
388
393
|
Returns:
|
389
|
-
(
|
394
|
+
(numpy) Scaled input data after normalization.
|
390
395
|
"""
|
391
396
|
|
392
397
|
MaxAbs = np.max(np.abs(Input.astype(dtype, copy=False)))
|
@@ -14,14 +14,11 @@ def encode_one_hot(y_train, y_test=None, summary=False):
|
|
14
14
|
summary (bool): If True, prints the class-to-index mapping. Default: False
|
15
15
|
|
16
16
|
Returns:
|
17
|
-
tuple: One-hot encoded y_train and (if given
|
17
|
+
tuple: One-hot encoded y_train and (if given: y_test).
|
18
18
|
"""
|
19
19
|
|
20
20
|
from .memory_operations import optimize_labels, transfer_to_cpu
|
21
21
|
|
22
|
-
y_train = optimize_labels(y_train, one_hot_encoded=False, cuda=True)
|
23
|
-
y_test = optimize_labels(y_test, one_hot_encoded=False, cuda=True)
|
24
|
-
|
25
22
|
y_train = transfer_to_cpu(y_train,dtype=y_train.dtype)
|
26
23
|
y_test = transfer_to_cpu(y_test,dtype=y_test.dtype)
|
27
24
|
|
@@ -38,14 +35,17 @@ def encode_one_hot(y_train, y_test=None, summary=False):
|
|
38
35
|
y_train_encoded = np.zeros((y_train.shape[0], class_count), dtype=y_train.dtype)
|
39
36
|
for i, label in enumerate(y_train):
|
40
37
|
y_train_encoded[i, class_to_index[label]] = 1
|
38
|
+
y_train_encoded = optimize_labels(y_train_encoded, one_hot_encoded=True, cuda=True)
|
41
39
|
|
42
40
|
if y_test is not None:
|
43
41
|
y_test_encoded = np.zeros((y_test.shape[0], class_count), dtype=y_test.dtype)
|
44
42
|
for i, label in enumerate(y_test):
|
45
43
|
y_test_encoded[i, class_to_index[label]] = 1
|
46
|
-
|
44
|
+
y_test_encoded = optimize_labels(y_test_encoded, one_hot_encoded=True, cuda=True)
|
45
|
+
|
46
|
+
return y_train_encoded, y_test_encoded
|
47
47
|
|
48
|
-
return
|
48
|
+
return y_train_encoded
|
49
49
|
|
50
50
|
|
51
51
|
def decode_one_hot(encoded_data):
|
@@ -77,7 +77,7 @@ def split(X, y, test_size, random_state=42, dtype=cp.float32, shuffle_in_cpu=Fal
|
|
77
77
|
|
78
78
|
random_state (int or None): Seed for random state. Default: 42.
|
79
79
|
|
80
|
-
dtype (cupy.dtype): Data type for the arrays. np.float32 by default. Example: cp.float64 or cp.float16.
|
80
|
+
dtype (cupy.dtype): Data type for the arrays. np.float32 by default. Example: cp.float64 or cp.float16.
|
81
81
|
|
82
82
|
shuffle_in_cpu (bool): If True, output will be same cpu's split function. Default: False. (Use this for direct comparison of cpu training.)
|
83
83
|
Returns:
|
@@ -126,23 +126,23 @@ def manuel_balancer(x_train, y_train, target_samples_per_class, dtype=cp.float32
|
|
126
126
|
"""
|
127
127
|
Generates synthetic examples to balance classes to the specified number of examples per class.
|
128
128
|
|
129
|
-
|
129
|
+
Args:
|
130
130
|
|
131
|
-
|
131
|
+
x_train: cupy array format
|
132
132
|
|
133
|
-
|
133
|
+
y_train (one-hot encoded): cupy array format
|
134
134
|
|
135
|
-
|
135
|
+
target_samples_per_class (int): Desired number of samples per class
|
136
136
|
|
137
|
-
|
137
|
+
dtype (cupy.dtype): Data type for the arrays. cp.float32 by default. Example: cp.float64 or cp.float16.
|
138
138
|
|
139
|
-
|
139
|
+
shuffle_in_cpu (bool): If True, output will be same cpu's manuel_balancer function. Default: False. (Use this for direct comparison of cpu training.)
|
140
140
|
|
141
141
|
Returns:
|
142
|
-
|
143
|
-
|
142
|
+
x_balanced -- Balanced input dataset (cupy array format)
|
143
|
+
y_balanced -- Balanced class labels (one-hot encoded, cupy array format)
|
144
144
|
"""
|
145
|
-
from .ui import loading_bars
|
145
|
+
from .ui import loading_bars, get_loading_bar_style
|
146
146
|
from .memory_operations import transfer_to_gpu
|
147
147
|
|
148
148
|
bar_format = loading_bars()[0]
|
@@ -155,7 +155,7 @@ def manuel_balancer(x_train, y_train, target_samples_per_class, dtype=cp.float32
|
|
155
155
|
x_balanced = []
|
156
156
|
y_balanced = []
|
157
157
|
|
158
|
-
for class_label in tqdm(range(class_count),leave=False, ascii=
|
158
|
+
for class_label in tqdm(range(class_count),leave=False, ascii=get_loading_bar_style(),
|
159
159
|
bar_format=bar_format,desc='Augmenting Data',ncols= 52):
|
160
160
|
class_indices = cp.where(cp.argmax(y_train, axis=1) == class_label)[0]
|
161
161
|
num_samples = len(class_indices)
|
@@ -216,20 +216,22 @@ def manuel_balancer(x_train, y_train, target_samples_per_class, dtype=cp.float32
|
|
216
216
|
def auto_balancer(x_train, y_train, dtype=cp.float32, shuffle_in_cpu=False):
|
217
217
|
|
218
218
|
"""
|
219
|
-
Function to balance the training data across different classes.
|
219
|
+
Function to balance (to min) the training data across different classes.
|
220
220
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
221
|
+
Args:
|
222
|
+
x_train (list): Input data for training.
|
223
|
+
|
224
|
+
y_train (list): Labels corresponding to the input data. (one-hot encoded)
|
225
|
+
|
226
|
+
dtype (cupy.dtype): Data type for the arrays. cp.float32 by default. Example: cp.float64 or cp.float16.
|
227
|
+
|
228
|
+
shuffle_in_cpu (bool): If True, output will be same cpu's auto_balancer function. Default: False. (Use this for direct comparison of cpu training.)
|
227
229
|
|
228
|
-
shuffle_in_cpu (bool): If True, output will be same cpu's auto_balancer function. Default: False. (Use this for direct comparison of cpu training.)
|
229
230
|
Returns:
|
230
|
-
|
231
|
+
tuple: A tuple containing balanced input data and labels.
|
231
232
|
"""
|
232
|
-
|
233
|
+
|
234
|
+
from .ui import loading_bars, get_loading_bar_style
|
233
235
|
from .memory_operations import transfer_to_gpu
|
234
236
|
|
235
237
|
x_train = transfer_to_gpu(x_train, dtype=dtype)
|
@@ -252,7 +254,7 @@ def auto_balancer(x_train, y_train, dtype=cp.float32, shuffle_in_cpu=False):
|
|
252
254
|
MinCount = min(classes)
|
253
255
|
|
254
256
|
BalancedIndices = []
|
255
|
-
for i in tqdm(range(class_count),leave=False, ascii=
|
257
|
+
for i in tqdm(range(class_count),leave=False, ascii=get_loading_bar_style(),
|
256
258
|
bar_format= bar_format, desc='Balancing Data',ncols=70):
|
257
259
|
if len(ClassIndices[i]) > MinCount:
|
258
260
|
if shuffle_in_cpu:
|
@@ -287,21 +289,19 @@ def auto_balancer(x_train, y_train, dtype=cp.float32, shuffle_in_cpu=False):
|
|
287
289
|
def synthetic_augmentation(x_train, y_train, dtype=cp.float32, shuffle_in_cpu=False):
|
288
290
|
"""
|
289
291
|
Generates synthetic examples to balance classes with fewer examples using CuPy.
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
shuffle_in_cpu (bool): If True, output will be same cpu's synthetic_augmentation function. Default: False. (Use this for direct comparison of cpu training.)
|
292
|
+
Args:
|
293
|
+
x_train: cupy array format
|
294
|
+
|
295
|
+
y_train: cupy array format
|
296
|
+
|
297
|
+
dtype (cupy.dtype): Data type for the arrays. cp.float32 by default. Example: cp.float64 or cp.float16.
|
298
|
+
|
299
|
+
shuffle_in_cpu (bool): If True, output will be same cpu's synthetic_augmentation function. Default: False. (Use this for direct comparison of cpu training.)
|
299
300
|
|
300
301
|
Returns:
|
301
|
-
|
302
|
-
y_train_balanced -- Balanced class labels (one-hot encoded, cupy array format)
|
302
|
+
x_train_balanced, y_train_balanced (cupy array format)
|
303
303
|
"""
|
304
|
-
from .ui import loading_bars
|
304
|
+
from .ui import loading_bars, get_loading_bar_style
|
305
305
|
from .memory_operations import transfer_to_gpu
|
306
306
|
|
307
307
|
x = transfer_to_gpu(x_train, dtype=dtype)
|
@@ -320,7 +320,7 @@ def synthetic_augmentation(x_train, y_train, dtype=cp.float32, shuffle_in_cpu=Fa
|
|
320
320
|
x_balanced = list(x)
|
321
321
|
y_balanced = list(y)
|
322
322
|
|
323
|
-
for class_label in tqdm(range(class_count), leave=False, ascii=
|
323
|
+
for class_label in tqdm(range(class_count), leave=False, ascii=get_loading_bar_style(),
|
324
324
|
bar_format=bar_format, desc='Augmenting Data', ncols=52):
|
325
325
|
class_indices = [i for i, label in enumerate(y) if cp.argmax(label) == class_label]
|
326
326
|
num_samples = len(class_indices)
|
@@ -360,19 +360,16 @@ def standard_scaler(x_train=None, x_test=None, scaler_params=None, dtype=cp.floa
|
|
360
360
|
Standardizes training and test datasets. x_test may be None.
|
361
361
|
|
362
362
|
Args:
|
363
|
-
x_train
|
363
|
+
x_train (cupy.ndarray):
|
364
364
|
|
365
|
-
x_test
|
365
|
+
x_test (cupy.ndarray): (optional)
|
366
366
|
|
367
|
-
scaler_params (optional for using model)
|
367
|
+
scaler_params (tuple): (optional for using model)
|
368
368
|
|
369
|
-
dtype (cupy.dtype): Data type for the arrays. cp.float32 by default. Example: cp.float64 or cp.float16.
|
369
|
+
dtype (cupy.dtype): Data type for the arrays. cp.float32 by default. Example: cp.float64 or cp.float16.
|
370
370
|
|
371
371
|
Returns:
|
372
|
-
|
373
|
-
Scaler parameters: mean and std
|
374
|
-
tuple
|
375
|
-
Standardized training and test datasets
|
372
|
+
Scaler parameters, Standardized training (and if test given) datasets. (tuple)
|
376
373
|
"""
|
377
374
|
if x_train is not None and scaler_params is None and x_test is not None:
|
378
375
|
x_train = x_train.astype(dtype, copy=False)
|
@@ -412,7 +409,7 @@ def normalization(
|
|
412
409
|
Args:
|
413
410
|
Input (num): Input data to be normalized.
|
414
411
|
|
415
|
-
dtype (cupy.dtype): Data type for the arrays. cp.float32 by default. Example: cp.float64 or cp.float16.
|
412
|
+
dtype (cupy.dtype): Data type for the arrays. cp.float32 by default. Example: cp.float64 or cp.float16.
|
416
413
|
|
417
414
|
Returns:
|
418
415
|
(num) Scaled input data after normalization.
|
@@ -432,7 +429,7 @@ def non_neg_normalization(
|
|
432
429
|
Args:
|
433
430
|
Input (cupy): Input data to be normalized.
|
434
431
|
|
435
|
-
dtype (cupy.dtype): Data type for the arrays. cp.float32 by default. Example: cp.float64 or cp.float16.
|
432
|
+
dtype (cupy.dtype): Data type for the arrays. cp.float32 by default. Example: cp.float64 or cp.float16.
|
436
433
|
|
437
434
|
Returns:
|
438
435
|
(cupy) Scaled input data after normalization.
|
@@ -5,14 +5,9 @@ def wals(acc, loss, acc_impact, loss_impact):
|
|
5
5
|
The WALS(weighted accuracy-loss score) function calculates a weighted sum of accuracy and loss based on their respective impacts.
|
6
6
|
|
7
7
|
:param acc: The `acc` parameter represents the accuracy of a model or system
|
8
|
-
:param loss: The `loss` parameter in the `wals` function represents the amount of loss incurred. It
|
9
|
-
|
10
|
-
|
11
|
-
:param acc_impact: The `acc_impact` parameter represents the impact of accuracy on the overall score
|
12
|
-
calculation in the `wals` function. It is a multiplier that determines how much the accuracy
|
13
|
-
contributes to the final result
|
14
|
-
:param loss_impact: The `loss_impact` parameter in the `wals` function represents the weight of loss value when calculating the overall impact. It is used to determine how
|
15
|
-
much the loss affects the final result compared to the accuracy impact
|
8
|
+
:param loss: The `loss` parameter in the `wals` function represents the amount of loss incurred. It is used in the calculation to determine the overall impact based on the accuracy and loss impacts provided
|
9
|
+
:param acc_impact: The `acc_impact` parameter represents the impact of accuracy on the overall score calculation in the `wals` function. It is a multiplier that determines how much the accuracy contributes to the final result
|
10
|
+
:param loss_impact: The `loss_impact` parameter in the `wals` function represents the weight of loss value when calculating the overall impact. It is used to determine how much the loss affects the final result compared to the accuracy impact
|
16
11
|
:return: the weighted sum of accuracy and loss based on their respective impacts.
|
17
12
|
"""
|
18
13
|
loss += np.finfo(float).eps
|
@@ -34,11 +34,11 @@ def transfer_to_cpu(x, dtype=np.float32):
|
|
34
34
|
The `transfer_to_cpu` function converts data to a specified data type on the CPU, handling memory constraints
|
35
35
|
by batching the conversion process and ensuring complete GPU memory cleanup.
|
36
36
|
|
37
|
-
param x: Input data to transfer to CPU (CuPy array)
|
37
|
+
:param x: Input data to transfer to CPU (CuPy array)
|
38
38
|
|
39
|
-
param dtype: Target NumPy dtype for the output array (default: np.float32)
|
39
|
+
:param dtype: Target NumPy dtype for the output array (default: np.float32)
|
40
40
|
|
41
|
-
return: NumPy array with the specified dtype
|
41
|
+
:return: NumPy array with the specified dtype
|
42
42
|
"""
|
43
43
|
from .ui import loading_bars, initialize_loading_bar
|
44
44
|
try:
|
@@ -125,11 +125,8 @@ def get_optimal_batch_size_for_gpu(x, data_size_bytes):
|
|
125
125
|
The function calculates the optimal batch size for a GPU based on available memory and data size.
|
126
126
|
|
127
127
|
:param x: A list or array containing the data elements that will be processed on the GPU
|
128
|
-
:param data_size_bytes: The `data_size_bytes` parameter represents the total size of the data in
|
129
|
-
|
130
|
-
total size of the dataset, depending on how you are structuring your computations
|
131
|
-
:return: the optimal batch size that can be used for processing the given data on the GPU, based on
|
132
|
-
the available free memory on the GPU and the size of the data elements.
|
128
|
+
:param data_size_bytes: The `data_size_bytes` parameter represents the total size of the data in bytes that you want to process on the GPU. This could be the size of a single batch of data or the total size of the dataset, depending on how you are structuring your computations
|
129
|
+
:return: the optimal batch size that can be used for processing the given data on the GPU, based on the available free memory on the GPU and the size of the data elements.
|
133
130
|
"""
|
134
131
|
free_memory = cp.get_default_memory_pool().free_bytes()
|
135
132
|
device_memory = cp.cuda.runtime.memGetInfo()[0]
|
@@ -246,21 +243,10 @@ def optimize_labels(y, one_hot_encoded=True, cuda=False):
|
|
246
243
|
The function `optimize_labels` optimizes the data type of labels based on their length and encoding
|
247
244
|
format.
|
248
245
|
|
249
|
-
:param y: The `optimize_labels` function is designed to optimize the data type of the input labels
|
250
|
-
`
|
251
|
-
|
252
|
-
:
|
253
|
-
whether the labels are in one-hot encoded format or not. If `one_hot_encoded` is set to `True`, it
|
254
|
-
means that the labels are in one-hot encoded format, and the function will check the length of the,
|
255
|
-
defaults to True (optional)
|
256
|
-
:param cuda: The `cuda` parameter in the `optimize_labels` function is a boolean flag that indicates
|
257
|
-
whether to use CUDA for computations. If `cuda` is set to `True`, the function will use the CuPy
|
258
|
-
library for array operations, which can leverage GPU acceleration. If `cuda` is `False, defaults to
|
259
|
-
False (optional)
|
260
|
-
:return: The function `optimize_labels` returns the input array `y` after optimizing its data type
|
261
|
-
based on the specified conditions. If `one_hot_encoded` is True, it checks the length of the
|
262
|
-
elements in `y` and converts the data type to uint8, uint16, or uint32 accordingly. If
|
263
|
-
`one_hot_encoded` is False, it checks the length of `y` itself and
|
246
|
+
:param y: The `optimize_labels` function is designed to optimize the data type of the input labels `y` based on certain conditions. The function checks if the labels are in one-hot encoded format or not, and then based on the length of the labels and the specified data types (`uint8`, `uint
|
247
|
+
:param one_hot_encoded: The `one_hot_encoded` parameter in the `optimize_labels` function indicates whether the labels are in one-hot encoded format or not. If `one_hot_encoded` is set to `True`, it means that the labels are in one-hot encoded format, and the function will check the length of the, defaults to True (optional)
|
248
|
+
:param cuda: The `cuda` parameter in the `optimize_labels` function is a boolean flag that indicates whether to use CUDA for computations. If `cuda` is set to `True`, the function will use the CuPy library for array operations, which can leverage GPU acceleration. If `cuda` is `False, defaults to False (optional)
|
249
|
+
:return: The function `optimize_labels` returns the input array `y` after optimizing its data type based on the specified conditions. If `one_hot_encoded` is True, it checks the length of the elements in `y` and converts the data type to uint8, uint16, or uint32 accordingly. If `one_hot_encoded` is False, it checks the length of `y` itself and
|
264
250
|
"""
|
265
251
|
|
266
252
|
if cuda: array_type = cp
|