justdata 1.0.0__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.
- justdata/__init__.py +3 -0
- justdata/acoustic/__init__.py +381 -0
- justdata/acoustic/adapters.py +329 -0
- justdata/acoustic/augment/__init__.py +119 -0
- justdata/acoustic/augment/batch.py +813 -0
- justdata/acoustic/augment/configs.py +204 -0
- justdata/acoustic/augment/patchout.py +331 -0
- justdata/acoustic/augment/spectrogram.py +806 -0
- justdata/acoustic/augment/waveform.py +879 -0
- justdata/acoustic/batching.py +27 -0
- justdata/acoustic/channel.py +53 -0
- justdata/acoustic/compat/__init__.py +95 -0
- justdata/acoustic/compat/ast.py +626 -0
- justdata/acoustic/compat/ced.py +152 -0
- justdata/acoustic/compat/efficientat.py +243 -0
- justdata/acoustic/compat/panns.py +115 -0
- justdata/acoustic/compat/passt.py +191 -0
- justdata/acoustic/configs.py +519 -0
- justdata/acoustic/corruptions/__init__.py +33 -0
- justdata/acoustic/corruptions/codec.py +92 -0
- justdata/acoustic/corruptions/datasets.py +155 -0
- justdata/acoustic/corruptions/device.py +39 -0
- justdata/acoustic/corruptions/dynamics.py +55 -0
- justdata/acoustic/corruptions/filters.py +105 -0
- justdata/acoustic/corruptions/noise.py +173 -0
- justdata/acoustic/corruptions/registry.py +230 -0
- justdata/acoustic/corruptions/reverb.py +49 -0
- justdata/acoustic/corruptions/timefreq.py +127 -0
- justdata/acoustic/datasets.py +52 -0
- justdata/acoustic/dcase2025.py +814 -0
- justdata/acoustic/decoding.py +73 -0
- justdata/acoustic/eval_views.py +54 -0
- justdata/acoustic/evals.py +71 -0
- justdata/acoustic/filters.py +18 -0
- justdata/acoustic/frontends/__init__.py +37 -0
- justdata/acoustic/frontends/ast.py +116 -0
- justdata/acoustic/frontends/kaldi.py +34 -0
- justdata/acoustic/frontends/log.py +94 -0
- justdata/acoustic/frontends/mel.py +173 -0
- justdata/acoustic/frontends/mfcc.py +26 -0
- justdata/acoustic/frontends/pcen.py +26 -0
- justdata/acoustic/frontends/stft.py +174 -0
- justdata/acoustic/jax.py +23 -0
- justdata/acoustic/labels.py +169 -0
- justdata/acoustic/layouts.py +86 -0
- justdata/acoustic/metadata.py +152 -0
- justdata/acoustic/normalization.py +196 -0
- justdata/acoustic/pipelines.py +112 -0
- justdata/acoustic/postprocessing.py +328 -0
- justdata/acoustic/preprocessing.py +175 -0
- justdata/acoustic/presets.py +257 -0
- justdata/acoustic/registry.py +381 -0
- justdata/acoustic/resampling.py +218 -0
- justdata/acoustic/schema.py +51 -0
- justdata/acoustic/segment.py +369 -0
- justdata/acoustic/sources.py +503 -0
- justdata/acoustic/stages.py +59 -0
- justdata/acoustic/stats.py +50 -0
- justdata/acoustic/tasks.py +375 -0
- justdata/audio/__init__.py +20 -0
- justdata/core/__init__.py +74 -0
- justdata/core/adapters.py +46 -0
- justdata/core/augmentations.py +34 -0
- justdata/core/filters.py +94 -0
- justdata/core/finalization.py +173 -0
- justdata/core/label_mixing.py +129 -0
- justdata/core/loader.py +384 -0
- justdata/core/metadata.py +250 -0
- justdata/core/presets.py +155 -0
- justdata/core/registry.py +229 -0
- justdata/core/sources.py +87 -0
- justdata/core/stats.py +227 -0
- justdata/corruptions.py +52 -0
- justdata/py.typed +0 -0
- justdata/vision/__init__.py +17 -0
- justdata/vision/augmentations/__init__.py +31 -0
- justdata/vision/augmentations/auto.py +480 -0
- justdata/vision/augmentations/color.py +163 -0
- justdata/vision/augmentations/composed.py +156 -0
- justdata/vision/augmentations/geometric.py +302 -0
- justdata/vision/augmentations/mixing.py +232 -0
- justdata/vision/augmentations/registry.py +142 -0
- justdata/vision/corruptions/__init__.py +16 -0
- justdata/vision/corruptions/blur.py +65 -0
- justdata/vision/corruptions/digital.py +26 -0
- justdata/vision/corruptions/noise.py +20 -0
- justdata/vision/corruptions/registry.py +113 -0
- justdata/vision/corruptions/weather.py +100 -0
- justdata/vision/datasets.py +34 -0
- justdata/vision/encodings/__init__.py +1 -0
- justdata/vision/encodings/heatmaps.py +196 -0
- justdata/vision/minic.py +69 -0
- justdata/vision/pipelines.py +62 -0
- justdata/vision/presets.py +509 -0
- justdata/vision/sources.py +1080 -0
- justdata/vision/stages.py +271 -0
- justdata/vision/tasks/__init__.py +1 -0
- justdata/vision/tasks/classification.py +321 -0
- justdata/vision/tasks/depth.py +25 -0
- justdata/vision/tasks/segmentation.py +194 -0
- justdata/vision/transforms.py +113 -0
- justdata/vision/utils.py +741 -0
- justdata-1.0.0.dist-info/METADATA +860 -0
- justdata-1.0.0.dist-info/RECORD +106 -0
- justdata-1.0.0.dist-info/WHEEL +4 -0
- justdata-1.0.0.dist-info/licenses/LICENSE +23 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
import tensorflow as tf
|
|
7
|
+
|
|
8
|
+
from justdata.acoustic.registry import (
|
|
9
|
+
get_audio_corruption,
|
|
10
|
+
has_audio_corruption,
|
|
11
|
+
list_audio_corruptions,
|
|
12
|
+
register_audio_corruption,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
SeverityTable = Mapping[int, float | int | tuple[float, ...]]
|
|
17
|
+
|
|
18
|
+
_EPS = tf.constant(1e-8, dtype=tf.float32)
|
|
19
|
+
_MAX_SEED = tf.constant(2**31 - 1, dtype=tf.int64)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def apply_audio_corruption(
|
|
23
|
+
audio_or_features: tf.Tensor,
|
|
24
|
+
corruption: str,
|
|
25
|
+
severity: int,
|
|
26
|
+
seed: tf.Tensor,
|
|
27
|
+
config: dict | None = None,
|
|
28
|
+
) -> tf.Tensor:
|
|
29
|
+
"""Apply a registered audio corruption with a validated severity level."""
|
|
30
|
+
_validate_severity(severity)
|
|
31
|
+
fn = get_audio_corruption(corruption)
|
|
32
|
+
return fn(
|
|
33
|
+
audio_or_features,
|
|
34
|
+
severity=severity,
|
|
35
|
+
seed=_seed_tensor(seed),
|
|
36
|
+
config=config,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _validate_severity(severity: int | tf.Tensor) -> tf.Tensor:
|
|
41
|
+
if not tf.is_tensor(severity):
|
|
42
|
+
value = int(severity)
|
|
43
|
+
if value < 1 or value > 5:
|
|
44
|
+
raise ValueError("Audio corruption severity must be in the range 1..5.")
|
|
45
|
+
|
|
46
|
+
severity_tensor = tf.cast(tf.convert_to_tensor(severity), tf.int32)
|
|
47
|
+
if tf.executing_eagerly():
|
|
48
|
+
try:
|
|
49
|
+
value = int(severity_tensor.numpy())
|
|
50
|
+
except (TypeError, ValueError):
|
|
51
|
+
value = None
|
|
52
|
+
if value is not None and (value < 1 or value > 5):
|
|
53
|
+
raise ValueError("Audio corruption severity must be in the range 1..5.")
|
|
54
|
+
|
|
55
|
+
with tf.control_dependencies(
|
|
56
|
+
[
|
|
57
|
+
tf.debugging.assert_greater_equal(
|
|
58
|
+
severity_tensor,
|
|
59
|
+
tf.constant(1, dtype=tf.int32),
|
|
60
|
+
message="Audio corruption severity must be in the range 1..5.",
|
|
61
|
+
),
|
|
62
|
+
tf.debugging.assert_less_equal(
|
|
63
|
+
severity_tensor,
|
|
64
|
+
tf.constant(5, dtype=tf.int32),
|
|
65
|
+
message="Audio corruption severity must be in the range 1..5.",
|
|
66
|
+
),
|
|
67
|
+
]
|
|
68
|
+
):
|
|
69
|
+
return tf.identity(severity_tensor)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _severity_index(severity: int | tf.Tensor) -> tf.Tensor:
|
|
73
|
+
return _validate_severity(severity) - 1
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _severity_value(
|
|
77
|
+
table: SeverityTable,
|
|
78
|
+
severity: int | tf.Tensor,
|
|
79
|
+
*,
|
|
80
|
+
dtype: tf.dtypes.DType = tf.float32,
|
|
81
|
+
) -> tf.Tensor:
|
|
82
|
+
values = [table[level] for level in range(1, 6)]
|
|
83
|
+
return tf.gather(tf.constant(values, dtype=dtype), _severity_index(severity))
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _seed_tensor(seed: tf.Tensor | int | None) -> tf.Tensor:
|
|
87
|
+
if seed is None:
|
|
88
|
+
return tf.constant([0, 0], dtype=tf.int32)
|
|
89
|
+
seed = tf.cast(tf.convert_to_tensor(seed), tf.int32)
|
|
90
|
+
if seed.shape.rank == 0:
|
|
91
|
+
return tf.stack([seed, tf.constant(0, dtype=tf.int32)])
|
|
92
|
+
if seed.shape.rank == 1 and seed.shape[0] == 1:
|
|
93
|
+
return tf.stack([seed[0], tf.constant(0, dtype=tf.int32)])
|
|
94
|
+
return seed[:2]
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _split_seed(seed: tf.Tensor | int | None, count: int) -> tf.Tensor:
|
|
98
|
+
return tf.random.split(_seed_tensor(seed), count)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _seed_from_index(
|
|
102
|
+
seed: int | tf.Tensor, index: tf.Tensor, salt: int = 0
|
|
103
|
+
) -> tf.Tensor:
|
|
104
|
+
base = tf.cast(_seed_tensor(seed), tf.int64)
|
|
105
|
+
idx = tf.cast(index, tf.int64)
|
|
106
|
+
salted = tf.math.floormod(base[1] + idx + tf.cast(salt, tf.int64), _MAX_SEED)
|
|
107
|
+
return tf.cast(tf.stack([base[0], salted]), tf.int32)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _as_tc(x: tf.Tensor) -> tuple[tf.Tensor, int | None]:
|
|
111
|
+
x = tf.convert_to_tensor(x)
|
|
112
|
+
rank = x.shape.rank
|
|
113
|
+
x = tf.cast(x, tf.float32)
|
|
114
|
+
if rank == 1:
|
|
115
|
+
return x[:, tf.newaxis], rank
|
|
116
|
+
if rank == 2:
|
|
117
|
+
return x, rank
|
|
118
|
+
raise ValueError("Audio corruption input must have shape [T] or [T, C].")
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _restore_rank(x: tf.Tensor, rank: int | None) -> tf.Tensor:
|
|
122
|
+
if rank == 1:
|
|
123
|
+
return tf.squeeze(x, axis=-1)
|
|
124
|
+
return x
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _fit_length(x: tf.Tensor, target_length: tf.Tensor) -> tf.Tensor:
|
|
128
|
+
target_length = tf.cast(tf.maximum(target_length, 1), tf.int32)
|
|
129
|
+
x = x[:target_length]
|
|
130
|
+
pad = tf.maximum(target_length - tf.shape(x)[0], 0)
|
|
131
|
+
return tf.pad(x, [[0, pad], [0, 0]])
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _resize_time(x: tf.Tensor, target_length: tf.Tensor) -> tf.Tensor:
|
|
135
|
+
target_length = tf.cast(tf.maximum(target_length, 1), tf.int32)
|
|
136
|
+
resized = tf.image.resize(
|
|
137
|
+
x[tf.newaxis, :, tf.newaxis, :],
|
|
138
|
+
[target_length, 1],
|
|
139
|
+
method="bilinear",
|
|
140
|
+
antialias=True,
|
|
141
|
+
)
|
|
142
|
+
return resized[0, :, 0, :]
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _sample_rate(config: dict | None, default: int = 32000) -> tf.Tensor:
|
|
146
|
+
"""Read the rate supplied by dataset helpers, defaulting for direct callers."""
|
|
147
|
+
value = default if config is None else config.get("sample_rate", default)
|
|
148
|
+
return tf.cast(value, tf.float32)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _rfft_filter(x: tf.Tensor, response: tf.Tensor) -> tf.Tensor:
|
|
152
|
+
audio, rank = _as_tc(x)
|
|
153
|
+
time = tf.shape(audio)[0]
|
|
154
|
+
channels_first = tf.transpose(audio, [1, 0])
|
|
155
|
+
spectrum = tf.signal.rfft(channels_first, fft_length=[time])
|
|
156
|
+
filtered = spectrum * tf.cast(response[tf.newaxis, :], spectrum.dtype)
|
|
157
|
+
result = tf.signal.irfft(filtered, fft_length=[time])
|
|
158
|
+
return _restore_rank(tf.transpose(result, [1, 0]), rank)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def _frequency_bins(x: tf.Tensor, sample_rate: tf.Tensor) -> tf.Tensor:
|
|
162
|
+
audio, _rank = _as_tc(x)
|
|
163
|
+
time = tf.shape(audio)[0]
|
|
164
|
+
num_bins = time // 2 + 1
|
|
165
|
+
return tf.linspace(
|
|
166
|
+
tf.constant(0.0, dtype=tf.float32),
|
|
167
|
+
tf.cast(sample_rate, tf.float32) * 0.5,
|
|
168
|
+
num_bins,
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _convolve_waveform(
|
|
173
|
+
x: tf.Tensor,
|
|
174
|
+
ir: tf.Tensor,
|
|
175
|
+
*,
|
|
176
|
+
compensate_delay: bool = False,
|
|
177
|
+
) -> tf.Tensor:
|
|
178
|
+
audio, rank = _as_tc(x)
|
|
179
|
+
time = tf.shape(audio)[0]
|
|
180
|
+
ir = tf.reshape(tf.cast(ir, tf.float32), [-1])
|
|
181
|
+
ir = tf.cond(tf.shape(ir)[0] > 0, lambda: ir, lambda: tf.ones([1], tf.float32))
|
|
182
|
+
kernel = tf.reverse(ir, axis=[0])[:, tf.newaxis, tf.newaxis]
|
|
183
|
+
kernel_length = tf.shape(kernel)[0]
|
|
184
|
+
start = (
|
|
185
|
+
tf.argmax(tf.abs(ir), output_type=tf.int32)
|
|
186
|
+
if compensate_delay
|
|
187
|
+
else (kernel_length - 1) // 2
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
def convolve_channel(channel: tf.Tensor) -> tf.Tensor:
|
|
191
|
+
signal = channel[tf.newaxis, :, tf.newaxis]
|
|
192
|
+
padded = tf.pad(
|
|
193
|
+
signal, [[0, 0], [kernel_length - 1, kernel_length - 1], [0, 0]]
|
|
194
|
+
)
|
|
195
|
+
full = tf.nn.conv1d(padded, kernel, stride=1, padding="VALID")[0, :, 0]
|
|
196
|
+
return _fit_length(full[start:, tf.newaxis], time)[:, 0]
|
|
197
|
+
|
|
198
|
+
channels_first = tf.transpose(audio, [1, 0])
|
|
199
|
+
convolved = tf.map_fn(
|
|
200
|
+
convolve_channel,
|
|
201
|
+
channels_first,
|
|
202
|
+
fn_output_signature=tf.float32,
|
|
203
|
+
)
|
|
204
|
+
return _restore_rank(tf.transpose(convolved, [1, 0]), rank)
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def _metadata_with_corruption(
|
|
208
|
+
sample: dict[str, Any],
|
|
209
|
+
*,
|
|
210
|
+
name: str,
|
|
211
|
+
severity: int,
|
|
212
|
+
domain: str,
|
|
213
|
+
) -> dict[str, Any]:
|
|
214
|
+
result = dict(sample)
|
|
215
|
+
current = result.get("metadata")
|
|
216
|
+
metadata = dict(current) if isinstance(current, dict) else {}
|
|
217
|
+
metadata["corruption"] = tf.constant(name)
|
|
218
|
+
metadata["severity"] = tf.cast(severity, tf.int32)
|
|
219
|
+
metadata["corruption_domain"] = tf.constant(domain)
|
|
220
|
+
result["metadata"] = metadata
|
|
221
|
+
return result
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
__all__ = [
|
|
225
|
+
"apply_audio_corruption",
|
|
226
|
+
"get_audio_corruption",
|
|
227
|
+
"has_audio_corruption",
|
|
228
|
+
"list_audio_corruptions",
|
|
229
|
+
"register_audio_corruption",
|
|
230
|
+
]
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import tensorflow as tf
|
|
4
|
+
|
|
5
|
+
from justdata.acoustic.corruptions.registry import (
|
|
6
|
+
_EPS,
|
|
7
|
+
_convolve_waveform,
|
|
8
|
+
_sample_rate,
|
|
9
|
+
_severity_value,
|
|
10
|
+
_split_seed,
|
|
11
|
+
register_audio_corruption,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
REVERB_RT60_SECONDS = {1: 0.15, 2: 0.3, 3: 0.5, 4: 0.8, 5: 1.2}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@register_audio_corruption("reverb_rir")
|
|
19
|
+
def reverb_rir(
|
|
20
|
+
audio_or_features: tf.Tensor,
|
|
21
|
+
severity: int,
|
|
22
|
+
seed: tf.Tensor,
|
|
23
|
+
config: dict | None = None,
|
|
24
|
+
) -> tf.Tensor:
|
|
25
|
+
rir = None if config is None else config.get("rir")
|
|
26
|
+
if rir is not None:
|
|
27
|
+
ir = tf.reshape(tf.cast(rir, tf.float32), [-1])
|
|
28
|
+
else:
|
|
29
|
+
sample_rate = _sample_rate(config)
|
|
30
|
+
rt60 = _severity_value(REVERB_RT60_SECONDS, severity)
|
|
31
|
+
max_ir_samples = (
|
|
32
|
+
4096 if config is None else int(config.get("max_ir_samples", 4096))
|
|
33
|
+
)
|
|
34
|
+
target_length = tf.cast(tf.round(rt60 * sample_rate), tf.int32)
|
|
35
|
+
length = tf.minimum(tf.maximum(target_length, 2), max_ir_samples)
|
|
36
|
+
noise_seed = tf.unstack(_split_seed(seed, 1))[0]
|
|
37
|
+
times = tf.cast(tf.range(length), tf.float32) / sample_rate
|
|
38
|
+
decay = tf.pow(tf.constant(10.0, dtype=tf.float32), -3.0 * times / rt60)
|
|
39
|
+
tail = tf.random.stateless_normal([length - 1], seed=noise_seed, stddev=0.05)
|
|
40
|
+
ir = tf.concat([tf.ones([1], dtype=tf.float32), tail * decay[1:]], axis=0)
|
|
41
|
+
|
|
42
|
+
ir = ir / tf.maximum(tf.sqrt(tf.reduce_sum(tf.square(ir))), _EPS)
|
|
43
|
+
return _convolve_waveform(audio_or_features, ir, compensate_delay=True)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
__all__ = [
|
|
47
|
+
"REVERB_RT60_SECONDS",
|
|
48
|
+
"reverb_rir",
|
|
49
|
+
]
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import tensorflow as tf
|
|
4
|
+
|
|
5
|
+
from justdata.acoustic.corruptions.registry import (
|
|
6
|
+
_as_tc,
|
|
7
|
+
_fit_length,
|
|
8
|
+
_resize_time,
|
|
9
|
+
_restore_rank,
|
|
10
|
+
_sample_rate,
|
|
11
|
+
_severity_value,
|
|
12
|
+
_split_seed,
|
|
13
|
+
register_audio_corruption,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
TIME_STRETCH_FACTOR = {1: 1.02, 2: 1.05, 3: 1.10, 4: 1.20, 5: 1.35}
|
|
18
|
+
PITCH_SHIFT_SEMITONES = {1: 0.5, 2: 1.0, 3: 2.0, 4: 3.0, 5: 4.0}
|
|
19
|
+
PACKET_DROPOUT_PROBABILITY = {1: 0.01, 2: 0.025, 3: 0.05, 4: 0.10, 5: 0.20}
|
|
20
|
+
PACKET_DROPOUT_GAP_MS = {1: 5, 2: 10, 3: 20, 4: 30, 5: 50}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@register_audio_corruption("time_stretch")
|
|
24
|
+
def time_stretch(
|
|
25
|
+
audio_or_features: tf.Tensor,
|
|
26
|
+
severity: int,
|
|
27
|
+
seed: tf.Tensor,
|
|
28
|
+
config: dict | None = None,
|
|
29
|
+
) -> tf.Tensor:
|
|
30
|
+
del seed
|
|
31
|
+
factor = _severity_value(TIME_STRETCH_FACTOR, severity)
|
|
32
|
+
if config is not None and "factor" in config:
|
|
33
|
+
factor = tf.cast(config["factor"], tf.float32)
|
|
34
|
+
audio, rank = _as_tc(audio_or_features)
|
|
35
|
+
length = tf.shape(audio)[0]
|
|
36
|
+
stretched_length = tf.cast(
|
|
37
|
+
tf.maximum(tf.round(tf.cast(length, tf.float32) * factor), 1.0),
|
|
38
|
+
tf.int32,
|
|
39
|
+
)
|
|
40
|
+
stretched = _resize_time(audio, stretched_length)
|
|
41
|
+
return _restore_rank(_fit_length(stretched, length), rank)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@register_audio_corruption("pitch_shift")
|
|
45
|
+
def pitch_shift(
|
|
46
|
+
audio_or_features: tf.Tensor,
|
|
47
|
+
severity: int,
|
|
48
|
+
seed: tf.Tensor,
|
|
49
|
+
config: dict | None = None,
|
|
50
|
+
) -> tf.Tensor:
|
|
51
|
+
del seed
|
|
52
|
+
semitones = _severity_value(PITCH_SHIFT_SEMITONES, severity)
|
|
53
|
+
if config is not None and "semitones" in config:
|
|
54
|
+
semitones = tf.cast(config["semitones"], tf.float32)
|
|
55
|
+
audio, rank = _as_tc(audio_or_features)
|
|
56
|
+
length = tf.shape(audio)[0]
|
|
57
|
+
factor = tf.pow(tf.constant(2.0, dtype=tf.float32), semitones / 12.0)
|
|
58
|
+
shifted_length = tf.cast(
|
|
59
|
+
tf.maximum(tf.round(tf.cast(length, tf.float32) / factor), 1.0),
|
|
60
|
+
tf.int32,
|
|
61
|
+
)
|
|
62
|
+
shifted = _resize_time(audio, shifted_length)
|
|
63
|
+
return _restore_rank(_fit_length(shifted, length), rank)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@register_audio_corruption("packet_dropout_gaps")
|
|
67
|
+
def packet_dropout_gaps(
|
|
68
|
+
audio_or_features: tf.Tensor,
|
|
69
|
+
severity: int,
|
|
70
|
+
seed: tf.Tensor,
|
|
71
|
+
config: dict | None = None,
|
|
72
|
+
) -> tf.Tensor:
|
|
73
|
+
sample_rate = _sample_rate(config)
|
|
74
|
+
probability = _severity_value(PACKET_DROPOUT_PROBABILITY, severity)
|
|
75
|
+
gap_ms = _severity_value(PACKET_DROPOUT_GAP_MS, severity)
|
|
76
|
+
if config is not None:
|
|
77
|
+
if "probability" in config:
|
|
78
|
+
probability = tf.cast(config["probability"], tf.float32)
|
|
79
|
+
if "gap_ms" in config:
|
|
80
|
+
gap_ms = tf.cast(config["gap_ms"], tf.float32)
|
|
81
|
+
|
|
82
|
+
dropout_seed, fallback_seed = tf.unstack(_split_seed(seed, 2))
|
|
83
|
+
audio, rank = _as_tc(audio_or_features)
|
|
84
|
+
length = tf.shape(audio)[0]
|
|
85
|
+
gap_length = tf.cast(
|
|
86
|
+
tf.maximum(tf.round(sample_rate * gap_ms / 1000.0), 1.0),
|
|
87
|
+
tf.int32,
|
|
88
|
+
)
|
|
89
|
+
num_segments = tf.cast(
|
|
90
|
+
tf.maximum(
|
|
91
|
+
tf.math.ceil(tf.cast(length, tf.float32) / tf.cast(gap_length, tf.float32)),
|
|
92
|
+
1.0,
|
|
93
|
+
),
|
|
94
|
+
tf.int32,
|
|
95
|
+
)
|
|
96
|
+
random_values = tf.random.stateless_uniform([num_segments], seed=dropout_seed)
|
|
97
|
+
dropped = random_values < probability
|
|
98
|
+
|
|
99
|
+
def add_fallback_drop() -> tf.Tensor:
|
|
100
|
+
index = tf.random.stateless_uniform(
|
|
101
|
+
[],
|
|
102
|
+
seed=fallback_seed,
|
|
103
|
+
minval=0,
|
|
104
|
+
maxval=num_segments,
|
|
105
|
+
dtype=tf.int32,
|
|
106
|
+
)
|
|
107
|
+
return tf.tensor_scatter_nd_update(
|
|
108
|
+
dropped,
|
|
109
|
+
indices=tf.reshape(index, [1, 1]),
|
|
110
|
+
updates=tf.constant([True]),
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
dropped = tf.cond(tf.reduce_any(dropped), lambda: dropped, add_fallback_drop)
|
|
114
|
+
mask = tf.repeat(dropped, gap_length)[:length]
|
|
115
|
+
corrupted = tf.where(mask[:, tf.newaxis], tf.zeros_like(audio), audio)
|
|
116
|
+
return _restore_rank(corrupted, rank)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
__all__ = [
|
|
120
|
+
"PACKET_DROPOUT_GAP_MS",
|
|
121
|
+
"PACKET_DROPOUT_PROBABILITY",
|
|
122
|
+
"PITCH_SHIFT_SEMITONES",
|
|
123
|
+
"TIME_STRETCH_FACTOR",
|
|
124
|
+
"packet_dropout_gaps",
|
|
125
|
+
"pitch_shift",
|
|
126
|
+
"time_stretch",
|
|
127
|
+
]
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from justdata.core.registry import register_dataset
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
AUDIO_CLASSIFICATION_SINGLE_LABEL = "audio_classification_single_label"
|
|
5
|
+
AUDIO_CLASSIFICATION_MULTI_LABEL = "audio_classification_multi_label"
|
|
6
|
+
AUDIO_EVENT_DETECTION = "audio_event_detection"
|
|
7
|
+
AUDIO_RETRIEVAL = "audio_retrieval"
|
|
8
|
+
AUDIO_TEXT_PAIR = "audio_text_pair"
|
|
9
|
+
AUDIO_SELF_SUPERVISED = "audio_self_supervised"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
register_dataset(
|
|
13
|
+
"esc50",
|
|
14
|
+
task_type=AUDIO_CLASSIFICATION_SINGLE_LABEL,
|
|
15
|
+
modality="acoustic",
|
|
16
|
+
pipeline_name="acoustic/classification",
|
|
17
|
+
preset="audio_default_32k_logmel128",
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
register_dataset(
|
|
21
|
+
"speech_commands",
|
|
22
|
+
task_type=AUDIO_CLASSIFICATION_SINGLE_LABEL,
|
|
23
|
+
modality="acoustic",
|
|
24
|
+
pipeline_name="acoustic/classification",
|
|
25
|
+
preset="audio_default_16k_waveform",
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
register_dataset(
|
|
29
|
+
"audioset",
|
|
30
|
+
task_type=AUDIO_CLASSIFICATION_MULTI_LABEL,
|
|
31
|
+
modality="acoustic",
|
|
32
|
+
pipeline_name="acoustic/classification",
|
|
33
|
+
preset="audioset_32k_10s_logmel128",
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
register_dataset(
|
|
37
|
+
"dcase2025_task1",
|
|
38
|
+
task_type=AUDIO_CLASSIFICATION_SINGLE_LABEL,
|
|
39
|
+
modality="acoustic",
|
|
40
|
+
pipeline_name="acoustic/classification",
|
|
41
|
+
preset="dcase2025_task1_native_44k_1s",
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
__all__ = [
|
|
46
|
+
"AUDIO_CLASSIFICATION_MULTI_LABEL",
|
|
47
|
+
"AUDIO_CLASSIFICATION_SINGLE_LABEL",
|
|
48
|
+
"AUDIO_EVENT_DETECTION",
|
|
49
|
+
"AUDIO_RETRIEVAL",
|
|
50
|
+
"AUDIO_SELF_SUPERVISED",
|
|
51
|
+
"AUDIO_TEXT_PAIR",
|
|
52
|
+
]
|