pyerualjetwork 4.1.4__py3-none-any.whl → 4.1.6__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.
@@ -2,7 +2,6 @@
2
2
  import subprocess
3
3
  subprocess.check_call(["pip", "install", 'setuptools==75.6.0'])
4
4
  import pkg_resources
5
- from datetime import datetime
6
5
 
7
6
  print("Auto checking and installation dependencies for PyerualJetwork")
8
7
 
@@ -14,7 +13,9 @@ package_names = [
14
13
  'networkx==3.3',
15
14
  'numpy==1.26.4',
16
15
  'matplotlib==3.9.0',
17
- 'colorama==0.4.6'
16
+ 'colorama==0.4.6',
17
+ 'psutil==6.1.1',
18
+ 'cupy-cuda12x==13.3.0'
18
19
  ]
19
20
 
20
21
  installed_packages = pkg_resources.working_set
@@ -47,8 +48,8 @@ for package_name in package_names:
47
48
 
48
49
  print(f"PyerualJetwork is ready to use with {err} errors")
49
50
 
50
- __version__ = "4.1.4"
51
- __update__ = "* Note: CUDA modules need cupy. Enter this command in your terminal: 'pip install cupy-cuda12x' or your cuda version.\n* Changes: https://github.com/HCB06/PyerualJetwork/blob/main/CHANGES\n* PyerualJetwork document: https://github.com/HCB06/Anaplan/blob/main/Welcome_to_PyerualJetwork/PYERUALJETWORK_USER_MANUEL_AND_LEGAL_INFORMATION(EN).pdf\n* YouTube tutorials: https://www.youtube.com/@HasanCanBeydili"
51
+ __version__ = "4.1.6"
52
+ __update__ = "* Changes: https://github.com/HCB06/PyerualJetwork/blob/main/CHANGES\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"
52
53
 
53
54
  def print_version(__version__):
54
55
  print(f"PyerualJetwork Version {__version__}" + '\n')
@@ -37,7 +37,7 @@ def Softmax(
37
37
  Returns:
38
38
  (num): Transformed data after applying softmax function.
39
39
  """
40
-
40
+
41
41
  return cp.array(softmax(x.get()))
42
42
 
43
43
 
@@ -16,26 +16,10 @@ def encode_one_hot(y_train, y_test=None, summary=False):
16
16
  Returns:
17
17
  tuple: One-hot encoded y_train and (if given) y_test.
18
18
  """
19
- if len(y_train) < 256:
20
- if y_train.dtype != np.uint8:
21
- y_train = np.array(y_train, copy=False).astype(np.uint8, copy=False)
22
- elif len(y_train) <= 32767:
23
- if y_train.dtype != np.uint16:
24
- y_train = np.array(y_train, copy=False).astype(np.uint16, copy=False)
25
- else:
26
- if y_train.dtype != np.uint32:
27
- y_train = np.array(y_train, copy=False).astype(np.uint32, copy=False)
28
-
29
- if y_test is not None:
30
- if len(y_test) < 256:
31
- if y_test.dtype != np.uint8:
32
- y_test = np.array(y_test, copy=False).astype(np.uint8, copy=False)
33
- elif len(y_test) <= 32767:
34
- if y_test.dtype != np.uint16:
35
- y_test = np.array(y_test, copy=False).astype(np.uint16, copy=False)
36
- else:
37
- if y_test.dtype != np.uint32:
38
- y_test = np.array(y_test, copy=False).astype(np.uint32, copy=False)
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)
39
23
 
40
24
  classes = np.unique(y_train)
41
25
  class_count = len(classes)
@@ -47,12 +31,12 @@ def encode_one_hot(y_train, y_test=None, summary=False):
47
31
  for cls, idx in class_to_index.items():
48
32
  print(f" {idx}: {cls}")
49
33
 
50
- y_train_encoded = np.zeros((y_train.shape[0], class_count))
34
+ y_train_encoded = np.zeros((y_train.shape[0], class_count), dtype=y_train.dtype)
51
35
  for i, label in enumerate(y_train):
52
36
  y_train_encoded[i, class_to_index[label]] = 1
53
37
 
54
38
  if y_test is not None:
55
- y_test_encoded = np.zeros((y_test.shape[0], class_count))
39
+ y_test_encoded = np.zeros((y_test.shape[0], class_count), dtype=y_test.dtype)
56
40
  for i, label in enumerate(y_test):
57
41
  y_test_encoded[i, class_to_index[label]] = 1
58
42
  return y_train_encoded, y_test_encoded
@@ -90,16 +74,10 @@ def split(X, y, test_size, random_state=42, dtype=np.float32):
90
74
  Returns:
91
75
  tuple: x_train, x_test, y_train, y_test as ordered training and testing data subsets.
92
76
  """
93
- X = X.astype(dtype)
94
- if len(y) < 256:
95
- if y.dtype != np.uint8:
96
- y = np.array(y, copy=False).astype(np.uint8, copy=False)
97
- elif len(y) <= 32767:
98
- if y.dtype != np.uint16:
99
- y = np.array(y, copy=False).astype(np.uint16, copy=False)
100
- else:
101
- if y.dtype != np.uint32:
102
- y = np.array(y, copy=False).astype(np.uint32, copy=False)
77
+ from .memory_operations import transfer_to_cpu, optimize_labels
78
+
79
+ X = transfer_to_cpu(X, dtype=dtype)
80
+ y = optimize_labels(y, one_hot_encoded=False, cuda=False)
103
81
 
104
82
  num_samples = X.shape[0]
105
83
 
@@ -124,6 +102,8 @@ def split(X, y, test_size, random_state=42, dtype=np.float32):
124
102
  x_train, x_test = X[train_indices], X[test_indices]
125
103
  y_train, y_test = y[train_indices], y[test_indices]
126
104
 
105
+ del X, y
106
+
127
107
  return x_train, x_test, y_train, y_test
128
108
 
129
109
 
@@ -142,20 +122,11 @@ def manuel_balancer(x_train, y_train, target_samples_per_class, dtype=np.float32
142
122
  y_balanced -- Balanced class labels (one-hot encoded, NumPy array format)
143
123
  """
144
124
  from .ui import loading_bars
145
-
146
- bar_format = loading_bars()[0]
125
+ from .memory_operations import transfer_to_cpu
147
126
 
148
- x_train = np.array(x_train, copy=False).astype(dtype, copy=False)
149
- if len(y_train[0]) < 256:
150
- if y_train.dtype != np.uint8:
151
- y_train = np.array(y_train, copy=False).astype(np.uint8, copy=False)
152
- elif len(y_train[0]) <= 32767:
153
- if y_train.dtype != np.uint16:
154
- y_train = np.array(y_train, copy=False).astype(np.uint16, copy=False)
155
- else:
156
- if y_train.dtype != np.uint32:
157
- y_train = np.array(y_train, copy=False).astype(np.uint32, copy=False)
127
+ x_train = transfer_to_cpu(x_train, dtype=dtype)
158
128
 
129
+ bar_format = loading_bars()[0]
159
130
  classes = np.arange(y_train.shape[1])
160
131
  class_count = len(classes)
161
132
 
@@ -181,8 +152,8 @@ def manuel_balancer(x_train, y_train, target_samples_per_class, dtype=np.float32
181
152
  if num_samples < target_samples_per_class:
182
153
 
183
154
  samples_to_add = target_samples_per_class - num_samples
184
- additional_samples = np.zeros((samples_to_add, x_train.shape[1]))
185
- additional_labels = np.zeros((samples_to_add, y_train.shape[1]))
155
+ additional_samples = np.zeros((samples_to_add, x_train.shape[1]), dtype=x_train.dtype)
156
+ additional_labels = np.zeros((samples_to_add, y_train.shape[1]), dtype=y_train.dtype)
186
157
 
187
158
  for i in range(samples_to_add):
188
159
 
@@ -200,10 +171,12 @@ def manuel_balancer(x_train, y_train, target_samples_per_class, dtype=np.float32
200
171
  x_balanced.append(additional_samples)
201
172
  y_balanced.append(additional_labels)
202
173
 
203
- x_balanced = np.vstack(x_balanced)
204
- y_balanced = np.vstack(y_balanced)
174
+ x_balanced = np.vstack(x_balanced, dtype=x_train.dtype)
175
+ y_balanced = np.vstack(y_balanced, dtype=y_train.dtype)
176
+
177
+ del x_train, y_train
205
178
 
206
- return x_balanced.astype(dtype), y_balanced.astype(dtype)
179
+ return x_balanced, y_balanced
207
180
 
208
181
 
209
182
  def auto_balancer(x_train, y_train, dtype=np.float32):
@@ -220,20 +193,11 @@ def auto_balancer(x_train, y_train, dtype=np.float32):
220
193
  tuple: A tuple containing balanced input data and labels.
221
194
  """
222
195
  from .ui import loading_bars
223
-
224
- bar_format = loading_bars()[0]
196
+ from .memory_operations import transfer_to_cpu
225
197
 
226
- x_train = np.array(x_train, copy=False).astype(dtype, copy=False)
227
- if len(y_train[0]) < 256:
228
- if y_train.dtype != np.uint8:
229
- y_train = np.array(y_train, copy=False).astype(np.uint8, copy=False)
230
- elif len(y_train[0]) <= 32767:
231
- if y_train.dtype != np.uint16:
232
- y_train = np.array(y_train, copy=False).astype(np.uint16, copy=False)
233
- else:
234
- if y_train.dtype != np.uint32:
235
- y_train = np.array(y_train, copy=False).astype(np.uint32, copy=False)
198
+ x_train = transfer_to_cpu(x_train, dtype=dtype)
236
199
 
200
+ bar_format = loading_bars()[0]
237
201
  classes = np.arange(y_train.shape[1])
238
202
  class_count = len(classes)
239
203
 
@@ -271,10 +235,15 @@ def auto_balancer(x_train, y_train, dtype=np.float32):
271
235
  print(Fore.RED + "ERROR: Inputs and labels must be same length check parameters")
272
236
  sys.exit()
273
237
 
274
- return BalancedInputs.astype(dtype, copy=False), BalancedLabels.astype(dtype, copy=False)
238
+ BalancedInputs = BalancedInputs.astype(dtype, copy=False)
239
+ BalancedLabels = BalancedLabels.astype(dtype=y_train.dtype, copy=False)
275
240
 
241
+ del x_train, y_train
276
242
 
277
- def synthetic_augmentation(x_train, y_train, dtype=np.float32):
243
+ return BalancedInputs, BalancedLabels
244
+
245
+
246
+ def synthetic_augmentation(x, y, dtype=np.float32):
278
247
  """
279
248
  Generates synthetic examples to balance classes with fewer examples.
280
249
 
@@ -288,24 +257,12 @@ def synthetic_augmentation(x_train, y_train, dtype=np.float32):
288
257
  y_balanced -- Balanced class labels (one-hot encoded, array format)
289
258
  """
290
259
  from .ui import loading_bars
291
-
292
- bar_format = loading_bars()[0]
260
+ from .memory_operations import transfer_to_cpu
293
261
 
294
- x_train = x_train.astype(dtype)
295
- if len(y_train[0]) < 256:
296
- if y_train.dtype != np.uint8:
297
- y_train = np.array(y_train, copy=False).astype(np.uint8, copy=False)
298
- elif len(y_train[0]) <= 32767:
299
- if y_train.dtype != np.uint16:
300
- y_train = np.array(y_train, copy=False).astype(np.uint16, copy=False)
301
- else:
302
- if y_train.dtype != np.uint32:
303
- y_train = np.array(y_train, copy=False).astype(np.uint32, copy=False)
304
-
305
- x = x_train
306
- y = y_train
262
+ x = transfer_to_cpu(x, dtype=dtype)
307
263
 
308
- classes = np.arange(y_train.shape[1])
264
+ bar_format = loading_bars()[0]
265
+ classes = np.arange(y.shape[1])
309
266
  class_count = len(classes)
310
267
 
311
268
  class_distribution = {i: 0 for i in range(class_count)}
@@ -340,8 +297,12 @@ def synthetic_augmentation(x_train, y_train, dtype=np.float32):
340
297
 
341
298
  num_samples += 1
342
299
 
300
+ x_balanced = np.array(x_balanced).astype(dtype, copy=False)
301
+ y_balanced = np.array(y_balanced).astype(dtype=y.dtype, copy=False)
302
+
303
+ del x, y
343
304
 
344
- return np.array(x_balanced).astype(dtype, copy=False), np.array(y_balanced).astype(dtype, copy=False)
305
+ return x_balanced, y_balanced
345
306
 
346
307
 
347
308
  def standard_scaler(x_train=None, x_test=None, scaler_params=None, dtype=np.float32):
@@ -1,7 +1,6 @@
1
1
  from tqdm import tqdm
2
2
  import cupy as cp
3
3
  from colorama import Fore, Style
4
- import sys
5
4
  import math
6
5
  import numpy as np
7
6
 
@@ -18,29 +17,13 @@ def encode_one_hot(y_train, y_test=None, summary=False):
18
17
  tuple: One-hot encoded y_train and (if given) y_test.
19
18
  """
20
19
 
21
- if len(y_train) < 256:
22
- if y_train.dtype != cp.uint8:
23
- y_train = cp.array(y_train, copy=False).astype(cp.uint8, copy=False)
24
- elif len(y_train) <= 32767:
25
- if y_train.dtype != cp.uint16:
26
- y_train = cp.array(y_train, copy=False).astype(cp.uint16, copy=False)
27
- else:
28
- if y_train.dtype != cp.uint32:
29
- y_train = cp.array(y_train, copy=False).astype(cp.uint32, copy=False)
30
-
31
- if y_test is not None:
32
- if len(y_test) < 256:
33
- if y_test.dtype != cp.uint8:
34
- y_test = cp.array(y_test, copy=False).astype(cp.uint8, copy=False)
35
- elif len(y_test) <= 32767:
36
- if y_test.dtype != cp.uint16:
37
- y_test = cp.array(y_test, copy=False).astype(cp.uint16, copy=False)
38
- else:
39
- if y_test.dtype != cp.uint32:
40
- y_test = cp.array(y_test, copy=False).astype(cp.uint32, copy=False)
20
+ from .memory_operations import optimize_labels, transfer_to_cpu
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)
41
24
 
42
- y_train = y_train.get()
43
- y_test = y_test.get()
25
+ y_train = transfer_to_cpu(y_train,dtype=y_train.dtype)
26
+ y_test = transfer_to_cpu(y_test,dtype=y_test.dtype)
44
27
 
45
28
  classes = np.unique(y_train)
46
29
  class_count = len(classes)
@@ -52,17 +35,17 @@ def encode_one_hot(y_train, y_test=None, summary=False):
52
35
  for cls, idx in class_to_index.items():
53
36
  print(f" {idx}: {cls}")
54
37
 
55
- y_train_encoded = np.zeros((y_train.shape[0], class_count))
38
+ y_train_encoded = np.zeros((y_train.shape[0], class_count), dtype=y_train.dtype)
56
39
  for i, label in enumerate(y_train):
57
40
  y_train_encoded[i, class_to_index[label]] = 1
58
41
 
59
42
  if y_test is not None:
60
- y_test_encoded = np.zeros((y_test.shape[0], class_count))
43
+ y_test_encoded = np.zeros((y_test.shape[0], class_count), dtype=y_test.dtype)
61
44
  for i, label in enumerate(y_test):
62
45
  y_test_encoded[i, class_to_index[label]] = 1
63
- return cp.array(y_train_encoded), cp.array(y_test_encoded)
46
+ return cp.array(y_train_encoded, dtype=y_train.dtype), cp.array(y_test_encoded, dtype=y_test.dtype)
64
47
 
65
- return cp.array(y_train_encoded)
48
+ return cp.array(y_train_encoded, dtype=y_train.dtype)
66
49
 
67
50
 
68
51
  def decode_one_hot(encoded_data):
@@ -76,9 +59,9 @@ def decode_one_hot(encoded_data):
76
59
  cupy.ndarray: Decoded categorical labels with shape (n_samples,).
77
60
  """
78
61
 
79
- decoded_labels = cp.argmax(encoded_data, axis=1)
62
+ if encoded_data.ndim == 1: return cp.argmax(encoded_data)
63
+ else: return cp.argmax(encoded_data, axis=1)
80
64
 
81
- return decoded_labels
82
65
 
83
66
 
84
67
  def split(X, y, test_size, random_state=42, dtype=cp.float32, use_cpu=False):
@@ -95,17 +78,10 @@ def split(X, y, test_size, random_state=42, dtype=cp.float32, use_cpu=False):
95
78
  Returns:
96
79
  tuple: x_train, x_test, y_train, y_test as ordered training and testing data subsets.
97
80
  """
98
- X = cp.array(X, copy=False).astype(dtype, copy=False)
99
- if len(y) < 256:
100
- if y.dtype != cp.uint8:
101
- y = cp.array(y, copy=False).astype(cp.uint8, copy=False)
102
- elif len(y) <= 32767:
103
- if y.dtype != cp.uint16:
104
- y = cp.array(y, copy=False).astype(cp.uint16, copy=False)
105
- else:
106
- if y.dtype != cp.uint32:
107
- y = cp.array(y, copy=False).astype(cp.uint32, copy=False)
108
-
81
+ from .memory_operations import transfer_to_gpu, optimize_labels
82
+
83
+ X = transfer_to_gpu(X, dtype=dtype)
84
+ y = optimize_labels(y, one_hot_encoded=False, cuda=True)
109
85
 
110
86
  num_samples = X.shape[0]
111
87
 
@@ -135,7 +111,9 @@ def split(X, y, test_size, random_state=42, dtype=cp.float32, use_cpu=False):
135
111
 
136
112
  x_train, x_test = X[train_indices], X[test_indices]
137
113
  y_train, y_test = y[train_indices], y[test_indices]
138
-
114
+ del X
115
+ del y
116
+ cp.cuda.MemoryPool().free_all_blocks()
139
117
  return x_train, x_test, y_train, y_test
140
118
 
141
119
 
@@ -160,21 +138,11 @@ def manuel_balancer(x_train, y_train, target_samples_per_class, dtype=cp.float32
160
138
  y_balanced -- Balanced class labels (one-hot encoded, cupy array format)
161
139
  """
162
140
  from .ui import loading_bars
163
-
164
- bar_format = loading_bars()[0]
141
+ from .memory_operations import transfer_to_gpu
165
142
 
166
- x_train = cp.array(x_train, copy=False).astype(dtype, copy=False)
167
-
168
- if len(y_train[0]) < 256:
169
- if y_train.dtype != cp.uint8:
170
- y_train = cp.array(y_train, copy=False).astype(cp.uint8, copy=False)
171
- elif len(y_train[0]) <= 32767:
172
- if y_train.dtype != cp.uint16:
173
- y_train = cp.array(y_train, copy=False).astype(cp.uint16, copy=False)
174
- else:
175
- if y_train.dtype != cp.uint32:
176
- y_train = cp.array(y_train, copy=False).astype(cp.uint32, copy=False)
177
-
143
+ bar_format = loading_bars()[0]
144
+ x_train = transfer_to_gpu(x_train, dtype=dtype)
145
+ y_train = transfer_to_gpu(y_train, dtype=y_train.dtype)
178
146
 
179
147
  classes = cp.arange(y_train.shape[1])
180
148
  class_count = len(classes)
@@ -191,7 +159,7 @@ def manuel_balancer(x_train, y_train, target_samples_per_class, dtype=cp.float32
191
159
 
192
160
  if use_cpu:
193
161
  selected_indices = np.random.choice(
194
- class_indices, target_samples_per_class, replace=False)
162
+ class_indices.get(), target_samples_per_class, replace=False)
195
163
  else:
196
164
  selected_indices = cp.random.choice(class_indices, target_samples_per_class, replace=False)
197
165
 
@@ -206,8 +174,8 @@ def manuel_balancer(x_train, y_train, target_samples_per_class, dtype=cp.float32
206
174
  if num_samples < target_samples_per_class:
207
175
 
208
176
  samples_to_add = target_samples_per_class - num_samples
209
- additional_samples = cp.zeros((samples_to_add, x_train.shape[1]))
210
- additional_labels = cp.zeros((samples_to_add, y_train.shape[1]))
177
+ additional_samples = cp.zeros((samples_to_add, x_train.shape[1]), dtype=x_train.dtype)
178
+ additional_labels = cp.zeros((samples_to_add, y_train.shape[1]), dtype=y_train.dtype)
211
179
 
212
180
  for i in range(samples_to_add):
213
181
 
@@ -231,8 +199,11 @@ def manuel_balancer(x_train, y_train, target_samples_per_class, dtype=cp.float32
231
199
  x_balanced.append(additional_samples)
232
200
  y_balanced.append(additional_labels)
233
201
 
234
- x_balanced = cp.vstack(x_balanced)
235
- y_balanced = cp.vstack(y_balanced)
202
+ x_balanced = cp.vstack(x_balanced, dtype=x_train.dtype)
203
+ y_balanced = cp.vstack(y_balanced, dtype=y_train.dtype)
204
+
205
+ del x_train, y_train
206
+ cp.cuda.MemoryPool().free_all_blocks()
236
207
 
237
208
  return x_balanced, y_balanced
238
209
 
@@ -245,7 +216,7 @@ def auto_balancer(x_train, y_train, dtype=cp.float32, use_cpu=False):
245
216
  Arguments:
246
217
  x_train (list): Input data for training.
247
218
 
248
- y_train (list): Labels corresponding to the input data.
219
+ y_train (list): Labels corresponding to the input data. (one-hot encoded)
249
220
 
250
221
  dtype (cupy.dtype): Data type for the arrays. np.float32 by default. Example: cp.float64 or cp.float16. [fp32 for balanced devices, fp64 for strong devices, fp16 for weak devices: not reccomended!] (optional)
251
222
 
@@ -254,26 +225,18 @@ def auto_balancer(x_train, y_train, dtype=cp.float32, use_cpu=False):
254
225
  tuple: A tuple containing balanced input data and labels.
255
226
  """
256
227
  from .ui import loading_bars
257
-
258
- x_train = cp.array(x_train, copy=False).astype(dtype, copy=False)
259
-
260
- if len(y_train[0]) < 256:
261
- if y_train.dtype != cp.uint8:
262
- y_train = cp.array(y_train, copy=False).astype(cp.uint8, copy=False)
263
- elif len(y_train[0]) <= 32767:
264
- if y_train.dtype != cp.uint16:
265
- y_train = cp.array(y_train, copy=False).astype(cp.uint16, copy=False)
266
- else:
267
- if y_train.dtype != cp.uint32:
268
- y_train = cp.array(y_train, copy=False).astype(cp.uint32, copy=False)
228
+ from .memory_operations import transfer_to_gpu
229
+
230
+ x_train = transfer_to_gpu(x_train, dtype=dtype)
231
+ y_train = transfer_to_gpu(y_train, dtype=y_train.dtype)
269
232
 
270
233
  bar_format = loading_bars()[0]
271
234
 
272
- classes = cp.arange(y_train.shape[1])
235
+ classes = cp.arange(y_train.shape[1], dtype=y_train.dtype)
273
236
  class_count = len(classes)
274
237
 
275
238
 
276
- ClassIndices = {i: cp.where(cp.array(y_train)[:, i] == 1)[
239
+ ClassIndices = {i: cp.where(y_train[:, i] == 1)[
277
240
  0] for i in range(class_count)}
278
241
  classes = [len(ClassIndices[i]) for i in range(class_count)]
279
242
 
@@ -310,8 +273,9 @@ def auto_balancer(x_train, y_train, dtype=cp.float32, use_cpu=False):
310
273
 
311
274
  print(Fore.GREEN + "Data Succesfully Balanced from: " + str(len(x_train)
312
275
  ) + " to: " + str(len(BalancedInputs)) + ". from: auto_balancer " + Style.RESET_ALL)
276
+ del x_train, y_train
277
+ cp.cuda.MemoryPool().free_all_blocks()
313
278
 
314
-
315
279
  return BalancedInputs, BalancedLabels
316
280
 
317
281
 
@@ -333,23 +297,13 @@ def synthetic_augmentation(x_train, y_train, dtype=cp.float32, use_cpu=False):
333
297
  y_train_balanced -- Balanced class labels (one-hot encoded, cupy array format)
334
298
  """
335
299
  from .ui import loading_bars
336
-
300
+ from .memory_operations import transfer_to_gpu
301
+
302
+ x = transfer_to_gpu(x_train, dtype=dtype)
303
+ y = transfer_to_gpu(y_train, dtype=y_train.dtype)
304
+
337
305
  bar_format = loading_bars()[0]
338
306
 
339
- x = x_train.astype(dtype, copy=False)
340
-
341
- if len(y_train[0]) < 256:
342
- if y_train.dtype != cp.uint8:
343
- y_train = cp.array(y_train, copy=False).astype(cp.uint8, copy=False)
344
- elif len(y_train[0]) <= 32767:
345
- if y_train.dtype != cp.uint16:
346
- y_train = cp.array(y_train, copy=False).astype(cp.uint16, copy=False)
347
- else:
348
- if y_train.dtype != cp.uint32:
349
- y_train = cp.array(y_train, copy=False).astype(cp.uint32, copy=False)
350
-
351
- y = y_train
352
-
353
307
  classes = cp.arange(y_train.shape[1])
354
308
  class_count = len(classes)
355
309
  class_distribution = {i: 0 for i in range(class_count)}
@@ -391,6 +345,9 @@ def synthetic_augmentation(x_train, y_train, dtype=cp.float32, use_cpu=False):
391
345
  x_balanced = cp.array(x_balanced)
392
346
  y_balanced = cp.array(y_balanced)
393
347
 
348
+ del x_train, y_train, x, y
349
+ cp.cuda.MemoryPool().free_all_blocks()
350
+
394
351
  return x_balanced, y_balanced
395
352
 
396
353
  def standard_scaler(x_train=None, x_test=None, scaler_params=None, dtype=cp.float32):
@@ -459,7 +416,6 @@ def normalization(
459
416
  MaxAbs = cp.max(cp.abs(Input.astype(dtype, copy=False)))
460
417
  return (Input / MaxAbs)
461
418
 
462
-
463
419
  def find_closest_factors(a):
464
420
 
465
421
  root = int(math.sqrt(a))