sonusai 0.15.2__py3-none-any.whl → 0.15.4__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.
- sonusai/mixture/augmentation.py +43 -9
- sonusai/mixture/eq_rule_is_valid.py +18 -2
- {sonusai-0.15.2.dist-info → sonusai-0.15.4.dist-info}/METADATA +1 -1
- {sonusai-0.15.2.dist-info → sonusai-0.15.4.dist-info}/RECORD +6 -6
- {sonusai-0.15.2.dist-info → sonusai-0.15.4.dist-info}/WHEEL +0 -0
- {sonusai-0.15.2.dist-info → sonusai-0.15.4.dist-info}/entry_points.txt +0 -0
sonusai/mixture/augmentation.py
CHANGED
@@ -58,11 +58,14 @@ def _expand_rules(expanded_rules: list[dict], rule: dict) -> list[dict]:
|
|
58
58
|
if not eq_rule_is_valid(rule[key]):
|
59
59
|
raise SonusAIError(f'Invalid augmentation value for {key}: {rule[key]}')
|
60
60
|
|
61
|
-
if all(isinstance(el, list) for el in rule[key]):
|
61
|
+
if all(isinstance(el, list) or (isinstance(el, str) and el == 'none') for el in rule[key]):
|
62
62
|
# Expand multiple rules
|
63
63
|
for value in rule[key]:
|
64
64
|
expanded_rule = deepcopy(rule)
|
65
|
-
|
65
|
+
if isinstance(value, str) and value == 'none':
|
66
|
+
expanded_rule[key] = None
|
67
|
+
else:
|
68
|
+
expanded_rule[key] = deepcopy(value)
|
66
69
|
_expand_rules(expanded_rules, expanded_rule)
|
67
70
|
return expanded_rules
|
68
71
|
|
@@ -80,13 +83,31 @@ def _expand_rules(expanded_rules: list[dict], rule: dict) -> list[dict]:
|
|
80
83
|
return expanded_rules
|
81
84
|
else:
|
82
85
|
rule[key] = convert_string_to_number(rule[key])
|
83
|
-
if not (isinstance(rule[key], float | int) or
|
86
|
+
if not (isinstance(rule[key], float | int) or
|
87
|
+
rule[key].startswith('rand') or
|
88
|
+
rule[key] == 'none'):
|
84
89
|
raise SonusAIError(f'Invalid augmentation value for {key}: {rule[key]}')
|
85
90
|
|
86
91
|
expanded_rules.append(rule)
|
87
92
|
return expanded_rules
|
88
93
|
|
89
94
|
|
95
|
+
def _generate_none_rule(rule: dict) -> dict:
|
96
|
+
"""Generate a new rule from a rule that contains 'none' directives
|
97
|
+
|
98
|
+
:param rule: Rule
|
99
|
+
:return: New rule
|
100
|
+
"""
|
101
|
+
from copy import deepcopy
|
102
|
+
|
103
|
+
out_rule = deepcopy(rule)
|
104
|
+
for key in out_rule:
|
105
|
+
if out_rule[key] == 'none':
|
106
|
+
out_rule[key] = None
|
107
|
+
|
108
|
+
return out_rule
|
109
|
+
|
110
|
+
|
90
111
|
def _generate_random_rule(rule: dict, num_ir: int = 0) -> dict:
|
91
112
|
"""Generate a new rule from a rule that contains 'rand' directives
|
92
113
|
|
@@ -237,6 +258,15 @@ def _parse_ir(rule: dict, num_ir: int) -> dict:
|
|
237
258
|
from sonusai import SonusAIError
|
238
259
|
from .helpers import generic_ids_to_list
|
239
260
|
|
261
|
+
def _resolve_str(rule_in: str) -> str | list[int]:
|
262
|
+
if rule_in in ['rand', 'none']:
|
263
|
+
return rule_in
|
264
|
+
|
265
|
+
rule_out = generic_ids_to_list(num_ir, rule_in)
|
266
|
+
if not all(ro in range(num_ir) for ro in rule_out):
|
267
|
+
raise SonusAIError(f'Invalid ir entry of {rule_in}')
|
268
|
+
return rule_out
|
269
|
+
|
240
270
|
if 'ir' not in rule:
|
241
271
|
return rule
|
242
272
|
|
@@ -246,15 +276,18 @@ def _parse_ir(rule: dict, num_ir: int) -> dict:
|
|
246
276
|
return rule
|
247
277
|
|
248
278
|
if isinstance(ir, str):
|
249
|
-
|
250
|
-
return rule
|
251
|
-
|
252
|
-
rule['ir'] = generic_ids_to_list(num_ir, ir)
|
279
|
+
rule['ir'] = _resolve_str(ir)
|
253
280
|
return rule
|
254
281
|
|
255
282
|
if isinstance(ir, list):
|
256
|
-
|
257
|
-
|
283
|
+
rule['ir'] = []
|
284
|
+
for item in ir:
|
285
|
+
result = _resolve_str(item)
|
286
|
+
if isinstance(result, str):
|
287
|
+
rule['ir'].append(_resolve_str(item))
|
288
|
+
else:
|
289
|
+
rule['ir'] += _resolve_str(item)
|
290
|
+
|
258
291
|
return rule
|
259
292
|
|
260
293
|
if isinstance(ir, int):
|
@@ -296,6 +329,7 @@ def augmentation_from_rule(rule: AugmentationRule, num_ir: int) -> Augmentation:
|
|
296
329
|
|
297
330
|
processed_rule = rule.to_dict()
|
298
331
|
del processed_rule['mixup']
|
332
|
+
processed_rule = _generate_none_rule(processed_rule)
|
299
333
|
if _rule_has_rand(processed_rule):
|
300
334
|
processed_rule = _generate_random_rule(processed_rule, num_ir)
|
301
335
|
|
@@ -7,13 +7,16 @@ def eq_rule_is_valid(rule: Any) -> bool:
|
|
7
7
|
An EQ rule must be a tuple of length 3 or a list of length 3 tuples.
|
8
8
|
"""
|
9
9
|
|
10
|
-
# Must be a list
|
10
|
+
# Must be a list or string equal to 'none'
|
11
|
+
if isinstance(rule, str) and rule == 'none':
|
12
|
+
return True
|
13
|
+
|
11
14
|
if not isinstance(rule, list):
|
12
15
|
return False
|
13
16
|
|
14
17
|
if len(rule) != 3:
|
15
18
|
# If the length is not 3, then all elements must also be lists
|
16
|
-
if not all(
|
19
|
+
if not all(_check_for_none(el) for el in rule):
|
17
20
|
return False
|
18
21
|
rules = rule
|
19
22
|
else:
|
@@ -24,9 +27,22 @@ def eq_rule_is_valid(rule: Any) -> bool:
|
|
24
27
|
if not all(isinstance(el, float | int | str) for el in r):
|
25
28
|
return False
|
26
29
|
|
30
|
+
if isinstance(r, str) and r == 'none':
|
31
|
+
continue
|
32
|
+
|
27
33
|
for el in r:
|
28
34
|
# If a string, item must start with 'rand'
|
29
35
|
if isinstance(el, str) and not el.startswith('rand'):
|
30
36
|
return False
|
31
37
|
|
32
38
|
return True
|
39
|
+
|
40
|
+
|
41
|
+
def _check_for_none(rule: Any) -> bool:
|
42
|
+
"""Check if EQ rule is 'none'
|
43
|
+
"""
|
44
|
+
if isinstance(rule, str) and rule == 'none':
|
45
|
+
return True
|
46
|
+
if isinstance(rule, list) and len(rule) == 3:
|
47
|
+
return True
|
48
|
+
return False
|
@@ -37,12 +37,12 @@ sonusai/metrics/one_hot.py,sha256=QSeH_GdqBpOAKLrNnQ8gjcPC-vSdUqC0yPEQueTA6VI,13
|
|
37
37
|
sonusai/metrics/snr_summary.py,sha256=P4U5_Xr7v9F8kF-rZBnpsVNt3p42rIVS6zmch8yfVfg,5575
|
38
38
|
sonusai/mixture/__init__.py,sha256=WzPHGSWz6v64HCSFTGboG5o-xBy_0II4i4tkf1UL1Vw,5251
|
39
39
|
sonusai/mixture/audio.py,sha256=6W2ihjJGBy7Xggx1imF7bzkymDuipPOgC63j2J7Wf-E,3456
|
40
|
-
sonusai/mixture/augmentation.py,sha256=
|
40
|
+
sonusai/mixture/augmentation.py,sha256=Blb90tdTwBOj5w9tRcYyS5H67YJuFiXsGqwZWd7ON4g,10468
|
41
41
|
sonusai/mixture/class_count.py,sha256=_wFnVl2yEOnbor7pLg7cYOUeX6nioov-03Cv3SEbh2k,996
|
42
42
|
sonusai/mixture/config.py,sha256=CXIkVRJmaW2QW_sGl0aIqPf7I_TesyGhUYzxouw5UX4,22266
|
43
43
|
sonusai/mixture/constants.py,sha256=xjCskcQi6khqYZDf7j6z1OkeN1C6wE06kBBapcJiNI4,1428
|
44
44
|
sonusai/mixture/datatypes.py,sha256=xN-GdPCEHGE2Ak_TdFbjuSyMs4x7TLRp59trbMTiYLg,8164
|
45
|
-
sonusai/mixture/eq_rule_is_valid.py,sha256=
|
45
|
+
sonusai/mixture/eq_rule_is_valid.py,sha256=MpQwRA5M76wSiQWEI1lW2cLFdPaMttBLcQp3tWD8efM,1243
|
46
46
|
sonusai/mixture/feature.py,sha256=io6OiJAJ3GYvPChiUmPQuP3h0OB2onjYF8o9-AWkmqM,1996
|
47
47
|
sonusai/mixture/generation.py,sha256=EUzG7zrezcCm-DuhyY27SJKQ0g7RV7w_uu19Iu5v70c,38879
|
48
48
|
sonusai/mixture/helpers.py,sha256=XqpcB15MezEMVJwf3jxzATDJSpj_27b8Cru1TDIFD7w,21326
|
@@ -122,7 +122,7 @@ sonusai/utils/trim_docstring.py,sha256=dSrtiRsEN4wkkvKBp6WDr13RUypfqZzgH_jOBLs1o
|
|
122
122
|
sonusai/utils/wave.py,sha256=TKE-CNPGFXNXUW626CBPzCTNgWJut8I0ZEUsgG9q4Po,586
|
123
123
|
sonusai/utils/yes_or_no.py,sha256=eMLXBVH0cEahiXY4W2KNORmwNQ-ba10eRtldh0y4NYg,263
|
124
124
|
sonusai/vars.py,sha256=m2AefF0m5bXWGXpJj8Pi42zWL2ydeEj7bkak3GrtMyM,940
|
125
|
-
sonusai-0.15.
|
126
|
-
sonusai-0.15.
|
127
|
-
sonusai-0.15.
|
128
|
-
sonusai-0.15.
|
125
|
+
sonusai-0.15.4.dist-info/METADATA,sha256=ozwRzn2oun0k1CULOzzLQo46oGCqqr_4Za8ig5jqw1Y,3097
|
126
|
+
sonusai-0.15.4.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
127
|
+
sonusai-0.15.4.dist-info/entry_points.txt,sha256=zMNjEphEPO6B3cD1GNpit7z-yA9tUU5-j3W2v-UWstU,92
|
128
|
+
sonusai-0.15.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|