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,194 @@
|
|
|
1
|
+
import tensorflow as tf
|
|
2
|
+
|
|
3
|
+
from justdata.vision.augmentations.registry import (
|
|
4
|
+
get_augment_strategy,
|
|
5
|
+
get_crop_strategy,
|
|
6
|
+
)
|
|
7
|
+
from justdata.vision.stages import normalize_image_format, resize_and_normalize
|
|
8
|
+
from justdata.vision.transforms import (
|
|
9
|
+
normalize,
|
|
10
|
+
pad_to_patch_multiple,
|
|
11
|
+
resize_short_side,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def make_preprocessing(image_key="image", mask_key="mask"):
|
|
16
|
+
def preprocessing(sample):
|
|
17
|
+
return normalize_image_format(sample, image_key=image_key)
|
|
18
|
+
|
|
19
|
+
return preprocessing
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def make_augmentations(
|
|
23
|
+
image_size: int,
|
|
24
|
+
enable: bool = True,
|
|
25
|
+
crop_type: str = "random_resized",
|
|
26
|
+
augment_type: str = "rand_augment",
|
|
27
|
+
ra_kwargs: dict = None,
|
|
28
|
+
ta_kwargs: dict = None,
|
|
29
|
+
padding: int = 4,
|
|
30
|
+
pad_mode: str = "REFLECT",
|
|
31
|
+
mask_fill_value: int = 255,
|
|
32
|
+
):
|
|
33
|
+
if not enable:
|
|
34
|
+
|
|
35
|
+
def no_aug(sample, seed):
|
|
36
|
+
return sample
|
|
37
|
+
|
|
38
|
+
return no_aug
|
|
39
|
+
|
|
40
|
+
crop_fn = get_crop_strategy(crop_type)
|
|
41
|
+
aug_fn = get_augment_strategy(augment_type)
|
|
42
|
+
|
|
43
|
+
ra_kwargs = dict(ra_kwargs or {})
|
|
44
|
+
ta_kwargs = dict(ta_kwargs or {})
|
|
45
|
+
|
|
46
|
+
def augmentations(sample, seed):
|
|
47
|
+
seeds = tf.random.split(seed, 2)
|
|
48
|
+
|
|
49
|
+
# Ensure mask has a channel dim for crop ops (crop_to_bounding_box requires rank 3+)
|
|
50
|
+
mask = sample["mask"]
|
|
51
|
+
mask_was_2d = tf.equal(tf.rank(mask), 2)
|
|
52
|
+
mask = tf.cond(mask_was_2d, lambda: tf.expand_dims(mask, -1), lambda: mask)
|
|
53
|
+
|
|
54
|
+
# Apply same spatial crop to both image and mask, using nearest interpolation for the mask
|
|
55
|
+
image = crop_fn(
|
|
56
|
+
sample["image"],
|
|
57
|
+
size=image_size,
|
|
58
|
+
seed=seeds[0],
|
|
59
|
+
padding=padding,
|
|
60
|
+
pad_mode=pad_mode,
|
|
61
|
+
)
|
|
62
|
+
mask = crop_fn(
|
|
63
|
+
mask,
|
|
64
|
+
size=image_size,
|
|
65
|
+
seed=seeds[0],
|
|
66
|
+
padding=padding,
|
|
67
|
+
pad_mode=pad_mode,
|
|
68
|
+
interpolation="nearest",
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
# Restore original mask rank
|
|
72
|
+
mask = tf.cond(mask_was_2d, lambda: tf.squeeze(mask, -1), lambda: mask)
|
|
73
|
+
sample = sample | {"image": image, "mask": mask}
|
|
74
|
+
|
|
75
|
+
# Automatic policies apply geometric operations to image and mask together.
|
|
76
|
+
aug_kwargs_dict = ra_kwargs if augment_type == "rand_augment" else ta_kwargs
|
|
77
|
+
if augment_type in {
|
|
78
|
+
"rand_augment",
|
|
79
|
+
"trivial_augment",
|
|
80
|
+
"trivial_augment_wide",
|
|
81
|
+
}:
|
|
82
|
+
image, mask = aug_fn(
|
|
83
|
+
sample["image"],
|
|
84
|
+
seed=seeds[1],
|
|
85
|
+
segmentation_mask=sample["mask"],
|
|
86
|
+
segmentation_fill_value=mask_fill_value,
|
|
87
|
+
**aug_kwargs_dict,
|
|
88
|
+
)
|
|
89
|
+
return sample | {"image": image, "mask": mask}
|
|
90
|
+
|
|
91
|
+
image = aug_fn(sample["image"], seed=seeds[1], **aug_kwargs_dict)
|
|
92
|
+
|
|
93
|
+
return sample | {"image": image}
|
|
94
|
+
|
|
95
|
+
return augmentations
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def make_late_augmentations(**kwargs):
|
|
99
|
+
def late_augmentations(sample, num_classes=None, seed=None):
|
|
100
|
+
return sample
|
|
101
|
+
|
|
102
|
+
return late_augmentations
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def make_postprocessing(
|
|
106
|
+
image_size: int,
|
|
107
|
+
is_training: bool = False,
|
|
108
|
+
normalize_image: bool = True,
|
|
109
|
+
normalization_params: tuple | None = (
|
|
110
|
+
(0.485, 0.456, 0.406),
|
|
111
|
+
(0.229, 0.224, 0.225),
|
|
112
|
+
),
|
|
113
|
+
permute_image: bool = True,
|
|
114
|
+
patch_align: bool = False,
|
|
115
|
+
patch_size: int = 14,
|
|
116
|
+
val_resize_size: int | None = None,
|
|
117
|
+
):
|
|
118
|
+
"""Build postprocessing for segmentation.
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
patch_align: If ``True``, pad images/masks to the nearest multiple
|
|
122
|
+
of ``patch_size`` instead of resizing to a fixed square. This
|
|
123
|
+
is the recommended validation strategy for ViT-based dense
|
|
124
|
+
prediction (avoids dropping boundary pixels).
|
|
125
|
+
val_resize_size: When ``patch_align`` is ``True``, resize the
|
|
126
|
+
shorter side to this value before padding. Defaults to
|
|
127
|
+
``image_size`` if not set.
|
|
128
|
+
"""
|
|
129
|
+
|
|
130
|
+
def postprocessing(sample, **kwargs):
|
|
131
|
+
if patch_align and not is_training:
|
|
132
|
+
# Dense ViT evaluation: resize shorter side, pad to patch multiple
|
|
133
|
+
target = val_resize_size if val_resize_size is not None else image_size
|
|
134
|
+
image = tf.cast(sample["image"], tf.float32)
|
|
135
|
+
image = resize_short_side(image, target_size=target, method="bicubic")
|
|
136
|
+
if normalize_image:
|
|
137
|
+
if normalization_params is None:
|
|
138
|
+
raise ValueError(
|
|
139
|
+
"`normalization_params` needs to be provided if "
|
|
140
|
+
"`normalize_image` is True"
|
|
141
|
+
)
|
|
142
|
+
image = normalize(image, *normalization_params)
|
|
143
|
+
image = pad_to_patch_multiple(image, patch_size=patch_size)
|
|
144
|
+
if permute_image:
|
|
145
|
+
from justdata.vision.transforms import nhwc_to_nchw
|
|
146
|
+
|
|
147
|
+
image = nhwc_to_nchw(image)
|
|
148
|
+
sample = sample | {"image": image}
|
|
149
|
+
|
|
150
|
+
if "mask" in sample:
|
|
151
|
+
mask = sample["mask"]
|
|
152
|
+
mask = tf.cond(
|
|
153
|
+
tf.equal(tf.rank(mask), 2),
|
|
154
|
+
lambda: tf.expand_dims(mask, -1),
|
|
155
|
+
lambda: mask,
|
|
156
|
+
)
|
|
157
|
+
mask.set_shape([None, None, None])
|
|
158
|
+
mask = resize_short_side(
|
|
159
|
+
tf.cast(mask, tf.float32),
|
|
160
|
+
target_size=target,
|
|
161
|
+
method="nearest",
|
|
162
|
+
)
|
|
163
|
+
mask = pad_to_patch_multiple(mask, patch_size=patch_size)
|
|
164
|
+
mask = tf.squeeze(mask, -1)
|
|
165
|
+
sample = sample | {"mask": mask}
|
|
166
|
+
|
|
167
|
+
return sample
|
|
168
|
+
|
|
169
|
+
# Standard fixed-size postprocessing
|
|
170
|
+
sample = resize_and_normalize(
|
|
171
|
+
sample,
|
|
172
|
+
image_keys=["image"],
|
|
173
|
+
image_size=image_size,
|
|
174
|
+
resize_size=None,
|
|
175
|
+
normalize_image=normalize_image,
|
|
176
|
+
normalization_params=normalization_params,
|
|
177
|
+
permute=permute_image,
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
if "mask" in sample:
|
|
181
|
+
mask = sample["mask"]
|
|
182
|
+
mask = tf.cond(
|
|
183
|
+
tf.equal(tf.rank(mask), 2),
|
|
184
|
+
lambda: tf.expand_dims(mask, -1),
|
|
185
|
+
lambda: mask,
|
|
186
|
+
)
|
|
187
|
+
mask.set_shape([None, None, None])
|
|
188
|
+
mask = tf.image.resize(mask, [image_size, image_size], method="nearest")
|
|
189
|
+
mask = tf.squeeze(mask, -1)
|
|
190
|
+
sample = sample | {"mask": mask}
|
|
191
|
+
|
|
192
|
+
return sample
|
|
193
|
+
|
|
194
|
+
return postprocessing
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import tensorflow as tf
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
@tf.function
|
|
5
|
+
def nhwc_to_nchw(image: tf.Tensor) -> tf.Tensor:
|
|
6
|
+
if len(image.shape) == 4:
|
|
7
|
+
return tf.transpose(image, [0, 3, 1, 2])
|
|
8
|
+
elif len(image.shape) == 3:
|
|
9
|
+
return tf.transpose(image, [2, 0, 1])
|
|
10
|
+
else:
|
|
11
|
+
raise NotImplementedError
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@tf.function
|
|
15
|
+
def normalize(image, mean, std):
|
|
16
|
+
"""
|
|
17
|
+
Normalizes an image tensor of any rank, assuming channels are the last dimension.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
image: Input image tensor (any rank, channel-last).
|
|
21
|
+
Expected to have integer values in the range [0, 255].
|
|
22
|
+
mean: List, tuple, or 1D tensor of channel means.
|
|
23
|
+
std: List, tuple, or 1D tensor of channel standard deviations.
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
Normalized image tensor (tf.float32).
|
|
27
|
+
"""
|
|
28
|
+
image = tf.cast(image, tf.float32)
|
|
29
|
+
image /= 255.0
|
|
30
|
+
|
|
31
|
+
img_mean = tf.constant(mean, dtype=tf.float32)
|
|
32
|
+
img_std = tf.constant(std, dtype=tf.float32)
|
|
33
|
+
|
|
34
|
+
# TensorFlow automatically broadcasts 1D tensors to the last dimension
|
|
35
|
+
normalized_image = (image - img_mean) / (img_std + 1e-8)
|
|
36
|
+
return normalized_image
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@tf.function
|
|
40
|
+
def resize_short_side(
|
|
41
|
+
image: tf.Tensor, target_size: int, method: str = "bilinear"
|
|
42
|
+
) -> tf.Tensor:
|
|
43
|
+
"""Resizes image so the shorter side matches target_size, preserving aspect ratio."""
|
|
44
|
+
shape = tf.shape(image)
|
|
45
|
+
height, width = tf.cast(shape[0], tf.float32), tf.cast(shape[1], tf.float32)
|
|
46
|
+
|
|
47
|
+
scale = tf.cast(target_size, tf.float32) / tf.minimum(height, width)
|
|
48
|
+
|
|
49
|
+
new_height = tf.cast(tf.round(height * scale), tf.int32)
|
|
50
|
+
new_width = tf.cast(tf.round(width * scale), tf.int32)
|
|
51
|
+
|
|
52
|
+
return tf.image.resize(image, [new_height, new_width], method=method)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@tf.function
|
|
56
|
+
def center_crop(image: tf.Tensor, crop_size: int) -> tf.Tensor:
|
|
57
|
+
"""Crops the center of the image to the specific size."""
|
|
58
|
+
shape = tf.shape(image)
|
|
59
|
+
height, width = shape[0], shape[1]
|
|
60
|
+
|
|
61
|
+
offset_height = (height - crop_size) // 2
|
|
62
|
+
offset_width = (width - crop_size) // 2
|
|
63
|
+
|
|
64
|
+
return tf.image.crop_to_bounding_box(
|
|
65
|
+
image, offset_height, offset_width, crop_size, crop_size
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@tf.function
|
|
70
|
+
def resize_image(
|
|
71
|
+
image: tf.Tensor,
|
|
72
|
+
image_size: int,
|
|
73
|
+
resize_size: int | None = 256,
|
|
74
|
+
method: str = "bilinear",
|
|
75
|
+
):
|
|
76
|
+
image = tf.cast(image, tf.float32)
|
|
77
|
+
|
|
78
|
+
if resize_size is not None:
|
|
79
|
+
image = resize_short_side(image, target_size=resize_size, method=method)
|
|
80
|
+
image = center_crop(image, crop_size=image_size)
|
|
81
|
+
else:
|
|
82
|
+
image = tf.image.resize(image, [image_size, image_size], method=method)
|
|
83
|
+
|
|
84
|
+
return image
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@tf.function
|
|
88
|
+
def pad_to_patch_multiple(
|
|
89
|
+
image: tf.Tensor,
|
|
90
|
+
patch_size: int = 14,
|
|
91
|
+
pad_mode: str = "CONSTANT",
|
|
92
|
+
) -> tf.Tensor:
|
|
93
|
+
"""Pads an image so height and width are multiples of ``patch_size``.
|
|
94
|
+
|
|
95
|
+
Padding is applied to the bottom and right edges only, suitable for
|
|
96
|
+
dense ViT evaluation where boundary pixels must not be dropped.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
image: 3-D tensor ``[H, W, C]``.
|
|
100
|
+
patch_size: ViT patch size (e.g. 14 or 16).
|
|
101
|
+
pad_mode: One of ``CONSTANT``, ``REFLECT``, ``SYMMETRIC``.
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
Padded image tensor.
|
|
105
|
+
"""
|
|
106
|
+
shape = tf.shape(image)
|
|
107
|
+
h, w = shape[0], shape[1]
|
|
108
|
+
|
|
109
|
+
pad_h = (patch_size - h % patch_size) % patch_size
|
|
110
|
+
pad_w = (patch_size - w % patch_size) % patch_size
|
|
111
|
+
|
|
112
|
+
paddings = [[0, pad_h], [0, pad_w], [0, 0]]
|
|
113
|
+
return tf.pad(image, paddings, mode=pad_mode)
|