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.
Files changed (106) hide show
  1. justdata/__init__.py +3 -0
  2. justdata/acoustic/__init__.py +381 -0
  3. justdata/acoustic/adapters.py +329 -0
  4. justdata/acoustic/augment/__init__.py +119 -0
  5. justdata/acoustic/augment/batch.py +813 -0
  6. justdata/acoustic/augment/configs.py +204 -0
  7. justdata/acoustic/augment/patchout.py +331 -0
  8. justdata/acoustic/augment/spectrogram.py +806 -0
  9. justdata/acoustic/augment/waveform.py +879 -0
  10. justdata/acoustic/batching.py +27 -0
  11. justdata/acoustic/channel.py +53 -0
  12. justdata/acoustic/compat/__init__.py +95 -0
  13. justdata/acoustic/compat/ast.py +626 -0
  14. justdata/acoustic/compat/ced.py +152 -0
  15. justdata/acoustic/compat/efficientat.py +243 -0
  16. justdata/acoustic/compat/panns.py +115 -0
  17. justdata/acoustic/compat/passt.py +191 -0
  18. justdata/acoustic/configs.py +519 -0
  19. justdata/acoustic/corruptions/__init__.py +33 -0
  20. justdata/acoustic/corruptions/codec.py +92 -0
  21. justdata/acoustic/corruptions/datasets.py +155 -0
  22. justdata/acoustic/corruptions/device.py +39 -0
  23. justdata/acoustic/corruptions/dynamics.py +55 -0
  24. justdata/acoustic/corruptions/filters.py +105 -0
  25. justdata/acoustic/corruptions/noise.py +173 -0
  26. justdata/acoustic/corruptions/registry.py +230 -0
  27. justdata/acoustic/corruptions/reverb.py +49 -0
  28. justdata/acoustic/corruptions/timefreq.py +127 -0
  29. justdata/acoustic/datasets.py +52 -0
  30. justdata/acoustic/dcase2025.py +814 -0
  31. justdata/acoustic/decoding.py +73 -0
  32. justdata/acoustic/eval_views.py +54 -0
  33. justdata/acoustic/evals.py +71 -0
  34. justdata/acoustic/filters.py +18 -0
  35. justdata/acoustic/frontends/__init__.py +37 -0
  36. justdata/acoustic/frontends/ast.py +116 -0
  37. justdata/acoustic/frontends/kaldi.py +34 -0
  38. justdata/acoustic/frontends/log.py +94 -0
  39. justdata/acoustic/frontends/mel.py +173 -0
  40. justdata/acoustic/frontends/mfcc.py +26 -0
  41. justdata/acoustic/frontends/pcen.py +26 -0
  42. justdata/acoustic/frontends/stft.py +174 -0
  43. justdata/acoustic/jax.py +23 -0
  44. justdata/acoustic/labels.py +169 -0
  45. justdata/acoustic/layouts.py +86 -0
  46. justdata/acoustic/metadata.py +152 -0
  47. justdata/acoustic/normalization.py +196 -0
  48. justdata/acoustic/pipelines.py +112 -0
  49. justdata/acoustic/postprocessing.py +328 -0
  50. justdata/acoustic/preprocessing.py +175 -0
  51. justdata/acoustic/presets.py +257 -0
  52. justdata/acoustic/registry.py +381 -0
  53. justdata/acoustic/resampling.py +218 -0
  54. justdata/acoustic/schema.py +51 -0
  55. justdata/acoustic/segment.py +369 -0
  56. justdata/acoustic/sources.py +503 -0
  57. justdata/acoustic/stages.py +59 -0
  58. justdata/acoustic/stats.py +50 -0
  59. justdata/acoustic/tasks.py +375 -0
  60. justdata/audio/__init__.py +20 -0
  61. justdata/core/__init__.py +74 -0
  62. justdata/core/adapters.py +46 -0
  63. justdata/core/augmentations.py +34 -0
  64. justdata/core/filters.py +94 -0
  65. justdata/core/finalization.py +173 -0
  66. justdata/core/label_mixing.py +129 -0
  67. justdata/core/loader.py +384 -0
  68. justdata/core/metadata.py +250 -0
  69. justdata/core/presets.py +155 -0
  70. justdata/core/registry.py +229 -0
  71. justdata/core/sources.py +87 -0
  72. justdata/core/stats.py +227 -0
  73. justdata/corruptions.py +52 -0
  74. justdata/py.typed +0 -0
  75. justdata/vision/__init__.py +17 -0
  76. justdata/vision/augmentations/__init__.py +31 -0
  77. justdata/vision/augmentations/auto.py +480 -0
  78. justdata/vision/augmentations/color.py +163 -0
  79. justdata/vision/augmentations/composed.py +156 -0
  80. justdata/vision/augmentations/geometric.py +302 -0
  81. justdata/vision/augmentations/mixing.py +232 -0
  82. justdata/vision/augmentations/registry.py +142 -0
  83. justdata/vision/corruptions/__init__.py +16 -0
  84. justdata/vision/corruptions/blur.py +65 -0
  85. justdata/vision/corruptions/digital.py +26 -0
  86. justdata/vision/corruptions/noise.py +20 -0
  87. justdata/vision/corruptions/registry.py +113 -0
  88. justdata/vision/corruptions/weather.py +100 -0
  89. justdata/vision/datasets.py +34 -0
  90. justdata/vision/encodings/__init__.py +1 -0
  91. justdata/vision/encodings/heatmaps.py +196 -0
  92. justdata/vision/minic.py +69 -0
  93. justdata/vision/pipelines.py +62 -0
  94. justdata/vision/presets.py +509 -0
  95. justdata/vision/sources.py +1080 -0
  96. justdata/vision/stages.py +271 -0
  97. justdata/vision/tasks/__init__.py +1 -0
  98. justdata/vision/tasks/classification.py +321 -0
  99. justdata/vision/tasks/depth.py +25 -0
  100. justdata/vision/tasks/segmentation.py +194 -0
  101. justdata/vision/transforms.py +113 -0
  102. justdata/vision/utils.py +741 -0
  103. justdata-1.0.0.dist-info/METADATA +860 -0
  104. justdata-1.0.0.dist-info/RECORD +106 -0
  105. justdata-1.0.0.dist-info/WHEEL +4 -0
  106. justdata-1.0.0.dist-info/licenses/LICENSE +23 -0
@@ -0,0 +1,142 @@
1
+ import threading
2
+ from typing import Dict, Protocol
3
+
4
+ import tensorflow as tf
5
+
6
+ from justdata.core.augmentations import (
7
+ AugmentationMetadata,
8
+ attach_augmentation_metadata,
9
+ )
10
+
11
+
12
+ class CropStrategyFn(Protocol):
13
+ def __call__(self, image: tf.Tensor, *, seed: tf.Tensor, **kwargs) -> tf.Tensor: ...
14
+
15
+
16
+ class AugmentStrategyFn(Protocol):
17
+ def __call__(self, image: tf.Tensor, *, seed: tf.Tensor, **kwargs) -> tf.Tensor: ...
18
+
19
+
20
+ _CROP_STRATEGIES: Dict[str, CropStrategyFn] = {}
21
+ _AUGMENT_STRATEGIES: Dict[str, AugmentStrategyFn] = {}
22
+ _CROP_STRATEGY_METADATA: Dict[str, AugmentationMetadata] = {}
23
+ _AUGMENT_STRATEGY_METADATA: Dict[str, AugmentationMetadata] = {}
24
+ _REGISTRY_LOCK = threading.Lock()
25
+
26
+
27
+ def register_crop_strategy(
28
+ name: str,
29
+ *,
30
+ is_training_only: bool = True,
31
+ requires_labels: bool = False,
32
+ ):
33
+ metadata = AugmentationMetadata(
34
+ name=name,
35
+ domain="image",
36
+ is_training_only=is_training_only,
37
+ requires_labels=requires_labels,
38
+ )
39
+
40
+ def decorator(fn: CropStrategyFn) -> CropStrategyFn:
41
+ with _REGISTRY_LOCK:
42
+ if name in _CROP_STRATEGIES:
43
+ raise ValueError(
44
+ f"Crop strategy '{name}' already registered by "
45
+ f"{_CROP_STRATEGIES[name].__module__}.{_CROP_STRATEGIES[name].__qualname__}"
46
+ )
47
+ _CROP_STRATEGIES[name] = fn
48
+ _CROP_STRATEGY_METADATA[name] = metadata
49
+ attach_augmentation_metadata(fn, metadata)
50
+ return fn
51
+
52
+ return decorator
53
+
54
+
55
+ def register_augment_strategy(
56
+ name: str,
57
+ *,
58
+ is_training_only: bool = True,
59
+ requires_labels: bool = False,
60
+ ):
61
+ metadata = AugmentationMetadata(
62
+ name=name,
63
+ domain="image",
64
+ is_training_only=is_training_only,
65
+ requires_labels=requires_labels,
66
+ )
67
+
68
+ def decorator(fn: AugmentStrategyFn) -> AugmentStrategyFn:
69
+ with _REGISTRY_LOCK:
70
+ if name in _AUGMENT_STRATEGIES:
71
+ raise ValueError(
72
+ f"Augment strategy '{name}' already registered by "
73
+ f"{_AUGMENT_STRATEGIES[name].__module__}.{_AUGMENT_STRATEGIES[name].__qualname__}"
74
+ )
75
+ _AUGMENT_STRATEGIES[name] = fn
76
+ _AUGMENT_STRATEGY_METADATA[name] = metadata
77
+ attach_augmentation_metadata(fn, metadata)
78
+ return fn
79
+
80
+ return decorator
81
+
82
+
83
+ def get_crop_strategy(name: str) -> CropStrategyFn:
84
+ if name not in _CROP_STRATEGIES:
85
+ raise ValueError(
86
+ f"Crop strategy '{name}' not found. "
87
+ f"Available: {list(_CROP_STRATEGIES.keys())}"
88
+ )
89
+ return attach_augmentation_metadata(
90
+ _CROP_STRATEGIES[name],
91
+ _CROP_STRATEGY_METADATA[name],
92
+ )
93
+
94
+
95
+ def get_augment_strategy(name: str) -> AugmentStrategyFn:
96
+ if name not in _AUGMENT_STRATEGIES:
97
+ raise ValueError(
98
+ f"Augment strategy '{name}' not found. "
99
+ f"Available: {list(_AUGMENT_STRATEGIES.keys())}"
100
+ )
101
+ return attach_augmentation_metadata(
102
+ _AUGMENT_STRATEGIES[name],
103
+ _AUGMENT_STRATEGY_METADATA[name],
104
+ )
105
+
106
+
107
+ def list_crop_strategies() -> tuple[str, ...]:
108
+ return tuple(sorted(_CROP_STRATEGIES))
109
+
110
+
111
+ def list_augment_strategies() -> tuple[str, ...]:
112
+ return tuple(sorted(_AUGMENT_STRATEGIES))
113
+
114
+
115
+ def get_crop_strategy_metadata(name: str) -> AugmentationMetadata:
116
+ if name not in _CROP_STRATEGY_METADATA:
117
+ raise ValueError(
118
+ f"Crop strategy metadata '{name}' not found. "
119
+ f"Available: {list(_CROP_STRATEGY_METADATA.keys())}"
120
+ )
121
+ return _CROP_STRATEGY_METADATA[name]
122
+
123
+
124
+ def get_augment_strategy_metadata(name: str) -> AugmentationMetadata:
125
+ if name not in _AUGMENT_STRATEGY_METADATA:
126
+ raise ValueError(
127
+ f"Augment strategy metadata '{name}' not found. "
128
+ f"Available: {list(_AUGMENT_STRATEGY_METADATA.keys())}"
129
+ )
130
+ return _AUGMENT_STRATEGY_METADATA[name]
131
+
132
+
133
+ def list_crop_strategy_metadata() -> tuple[AugmentationMetadata, ...]:
134
+ return tuple(
135
+ _CROP_STRATEGY_METADATA[name] for name in sorted(_CROP_STRATEGY_METADATA)
136
+ )
137
+
138
+
139
+ def list_augment_strategy_metadata() -> tuple[AugmentationMetadata, ...]:
140
+ return tuple(
141
+ _AUGMENT_STRATEGY_METADATA[name] for name in sorted(_AUGMENT_STRATEGY_METADATA)
142
+ )
@@ -0,0 +1,16 @@
1
+ from justdata.vision.corruptions import blur, digital, noise, weather
2
+ from justdata.vision.corruptions.registry import (
3
+ apply_minic_corruption,
4
+ list_corruptions,
5
+ register_corruption,
6
+ )
7
+
8
+ __all__ = [
9
+ "apply_minic_corruption",
10
+ "blur",
11
+ "digital",
12
+ "list_corruptions",
13
+ "noise",
14
+ "register_corruption",
15
+ "weather",
16
+ ]
@@ -0,0 +1,65 @@
1
+ import tensorflow as tf
2
+
3
+ from justdata.vision.corruptions.registry import (
4
+ _get_severity_index,
5
+ register_corruption,
6
+ )
7
+ from justdata.vision.utils import _pad, from_4d, gaussian_filter2d, to_4d
8
+
9
+ DEFOCUS_RADIUS = (3.0, 4.0, 6.0, 8.0, 10.0)
10
+
11
+ DEFOCUS_ALIAS = (0.1, 0.5, 0.5, 0.5, 0.5)
12
+
13
+
14
+ @register_corruption("blur")
15
+ @tf.function
16
+ def defocus_blur(image: tf.Tensor, severity: int, seed: tf.Tensor) -> tf.Tensor:
17
+ """
18
+ Applies Defocus Blur using a disk kernel convolution.
19
+
20
+ Note: Standard Gaussian blur mimics atmospheric scattering.
21
+ Defocus blur (bokeh) is physically caused by a circular aperture,
22
+ resulting in a disk-shaped Point Spread Function (PSF).
23
+ """
24
+ idx = _get_severity_index(severity)
25
+ radius = tf.gather(tf.constant(DEFOCUS_RADIUS, dtype=tf.float32), idx)
26
+ alias_blur = tf.gather(tf.constant(DEFOCUS_ALIAS, dtype=tf.float32), idx)
27
+
28
+ # Kernel size must be large enough to hold the disk (approx 2*r + 1)
29
+ k_size = tf.cast(tf.math.ceil(radius * 2.0) + 1, tf.int32)
30
+ # Ensure odd
31
+ k_size = tf.where(k_size % 2 == 0, k_size + 1, k_size)
32
+
33
+ # Coordinate grid
34
+ x = tf.range(tf.cast(k_size, tf.float32), dtype=tf.float32)
35
+ x = x - (tf.cast(k_size, tf.float32) - 1.0) / 2.0
36
+ xx, yy = tf.meshgrid(x, x)
37
+
38
+ # Disk equation: x^2 + y^2 <= r^2
39
+ dist_sq = xx**2 + yy**2
40
+ mask = tf.cast(dist_sq <= radius**2, tf.float32)
41
+
42
+ # Normalize kernel so energy is preserved
43
+ kernel = mask / (tf.reduce_sum(mask) + 1e-8)
44
+
45
+ kernel = kernel[:, :, tf.newaxis, tf.newaxis]
46
+ channels = tf.shape(image)[-1]
47
+ kernel = tf.tile(kernel, [1, 1, channels, 1])
48
+
49
+ image_f = tf.cast(image, tf.float32)
50
+ original_ndims = tf.rank(image_f)
51
+ image_4d = to_4d(image_f)
52
+
53
+ # Pad to preserve size
54
+ image_padded = _pad(image_4d, [k_size, k_size], pad_mode="REFLECT")
55
+
56
+ blurred = tf.nn.depthwise_conv2d(
57
+ image_padded, kernel, strides=[1, 1, 1, 1], padding="VALID"
58
+ )
59
+
60
+ blurred = from_4d(blurred, original_ndims)
61
+
62
+ # Slight Gaussian "aliasing" blur (simulates soft edges of aperture)
63
+ return gaussian_filter2d(
64
+ blurred, filter_shape=5, sigma=alias_blur, padding="REFLECT"
65
+ )
@@ -0,0 +1,26 @@
1
+ import tensorflow as tf
2
+
3
+ from justdata.vision.corruptions.registry import (
4
+ _get_severity_index,
5
+ register_corruption,
6
+ )
7
+
8
+ PIXELATE_RATIOS = (0.6, 0.5, 0.4, 0.3, 0.25)
9
+
10
+
11
+ @register_corruption("digital")
12
+ @tf.function
13
+ def pixelate(image: tf.Tensor, severity: int, seed: tf.Tensor) -> tf.Tensor:
14
+ """Pixelates image by downsampling and nearest-neighbor upsampling."""
15
+ idx = _get_severity_index(severity)
16
+ ratio = tf.gather(tf.constant(PIXELATE_RATIOS, dtype=tf.float32), idx)
17
+
18
+ shape = tf.shape(image)
19
+ h, w = tf.cast(shape[0], tf.float32), tf.cast(shape[1], tf.float32)
20
+
21
+ h_small = tf.cast(h * ratio, tf.int32)
22
+ w_small = tf.cast(w * ratio, tf.int32)
23
+
24
+ img_small = tf.image.resize(image, [h_small, w_small], method="nearest")
25
+
26
+ return tf.image.resize(img_small, [shape[0], shape[1]], method="nearest")
@@ -0,0 +1,20 @@
1
+ import tensorflow as tf
2
+
3
+ from justdata.vision.corruptions.registry import (
4
+ _get_severity_index,
5
+ register_corruption,
6
+ )
7
+
8
+ NOISE_STD = (8.0, 12.0, 18.0, 26.0, 38.0)
9
+
10
+
11
+ @register_corruption("noise")
12
+ @tf.function
13
+ def gaussian_noise(image: tf.Tensor, severity: int, seed: tf.Tensor) -> tf.Tensor:
14
+ """Applies Additive Gaussian Noise."""
15
+ idx = _get_severity_index(severity)
16
+ std = tf.gather(tf.constant(NOISE_STD, dtype=tf.float32), idx)
17
+
18
+ image = tf.cast(image, tf.float32)
19
+ noise = tf.random.stateless_normal(tf.shape(image), seed=seed, mean=0.0, stddev=std)
20
+ return tf.clip_by_value(image + noise, 0.0, 255.0)
@@ -0,0 +1,113 @@
1
+ import threading
2
+ from typing import Any, Callable, Dict
3
+
4
+ import tensorflow as tf
5
+
6
+ _CORRUPTION_REGISTRY: Dict[str, Callable] = {}
7
+ _CORRUPTION_LOCK = threading.Lock()
8
+
9
+
10
+ def register_corruption(name: str):
11
+ def decorator(fn):
12
+ with _CORRUPTION_LOCK:
13
+ if name in _CORRUPTION_REGISTRY:
14
+ raise ValueError(
15
+ f"Corruption '{name}' already registered by "
16
+ f"{_CORRUPTION_REGISTRY[name].__module__}.{_CORRUPTION_REGISTRY[name].__qualname__}"
17
+ )
18
+ _CORRUPTION_REGISTRY[name] = fn
19
+ return fn
20
+
21
+ return decorator
22
+
23
+
24
+ def apply_minic_corruption(
25
+ image: tf.Tensor, corruption: str, severity: int, seed: tf.Tensor
26
+ ) -> tf.Tensor:
27
+ """
28
+ Apply a specific Mini-C corruption to an image.
29
+
30
+ Args:
31
+ image: Input image tensor (uint8 or float).
32
+ corruption: One of ["noise", "blur", "weather", "digital"].
33
+ severity: Severity level [1-5].
34
+ seed: Random seed.
35
+
36
+ Returns:
37
+ Corrupted image as uint8 tensor.
38
+ """
39
+ _validate_severity(severity)
40
+ if corruption not in _CORRUPTION_REGISTRY:
41
+ raise ValueError(
42
+ f"Unknown corruption '{corruption}'. "
43
+ f"Available: {list(_CORRUPTION_REGISTRY.keys())}"
44
+ )
45
+
46
+ # Ensure input is float for processing
47
+ if image.dtype != tf.float32:
48
+ image = tf.cast(image, tf.float32)
49
+
50
+ fn = _CORRUPTION_REGISTRY[corruption]
51
+ corrupted = fn(image, severity, seed)
52
+
53
+ # Ensure output is uint8 [0, 255] for consistency with standard pipeline
54
+ corrupted = tf.clip_by_value(corrupted, 0.0, 255.0)
55
+ return tf.cast(corrupted, tf.uint8)
56
+
57
+
58
+ def list_corruptions() -> tuple[str, ...]:
59
+ return tuple(sorted(_CORRUPTION_REGISTRY))
60
+
61
+
62
+ def _get_severity_index(severity: int) -> int:
63
+ """Validate severity 1-5 and return a 0-based Tensor index."""
64
+ return _validate_severity(severity) - 1
65
+
66
+
67
+ def _validate_severity(severity: int | tf.Tensor) -> tf.Tensor:
68
+ if not tf.is_tensor(severity):
69
+ value = int(severity)
70
+ if value < 1 or value > 5:
71
+ raise ValueError("Mini-C corruption severity must be in the range 1..5.")
72
+
73
+ severity_tensor = tf.cast(tf.convert_to_tensor(severity), tf.int32)
74
+ if tf.executing_eagerly():
75
+ try:
76
+ value = int(severity_tensor.numpy())
77
+ except (TypeError, ValueError):
78
+ value = None
79
+ if value is not None and (value < 1 or value > 5):
80
+ raise ValueError("Mini-C corruption severity must be in the range 1..5.")
81
+
82
+ with tf.control_dependencies(
83
+ [
84
+ tf.debugging.assert_greater_equal(
85
+ severity_tensor,
86
+ tf.constant(1, dtype=tf.int32),
87
+ message="Mini-C corruption severity must be in the range 1..5.",
88
+ ),
89
+ tf.debugging.assert_less_equal(
90
+ severity_tensor,
91
+ tf.constant(5, dtype=tf.int32),
92
+ message="Mini-C corruption severity must be in the range 1..5.",
93
+ ),
94
+ ]
95
+ ):
96
+ return tf.identity(severity_tensor)
97
+
98
+
99
+ def _metadata_with_corruption(
100
+ sample: dict[str, Any],
101
+ *,
102
+ name: str,
103
+ severity: int,
104
+ domain: str = "image",
105
+ ) -> dict[str, Any]:
106
+ result = dict(sample)
107
+ current = result.get("metadata")
108
+ metadata = dict(current) if isinstance(current, dict) else {}
109
+ metadata["corruption"] = tf.constant(name)
110
+ metadata["severity"] = tf.cast(severity, tf.int32)
111
+ metadata["corruption_domain"] = tf.constant(domain)
112
+ result["metadata"] = metadata
113
+ return result
@@ -0,0 +1,100 @@
1
+ import tensorflow as tf
2
+
3
+ from justdata.vision.corruptions.registry import (
4
+ _get_severity_index,
5
+ register_corruption,
6
+ )
7
+ from justdata.vision.utils import _pad, _rotate, from_4d, to_4d
8
+
9
+ SNOW_PARAMS = (
10
+ (0.1, 0.3),
11
+ (0.2, 0.3),
12
+ (0.55, 0.3),
13
+ (0.55, 0.45),
14
+ (0.85, 0.55),
15
+ )
16
+
17
+
18
+ @register_corruption("weather")
19
+ @tf.function
20
+ def snow(image: tf.Tensor, severity: int, seed: tf.Tensor) -> tf.Tensor:
21
+ """
22
+ Simulates Snow by:
23
+ 1. Whitening/Fogging the image stats.
24
+ 2. Generating "snowflakes" via thresholded noise and motion blur.
25
+ """
26
+ idx = _get_severity_index(severity)
27
+ params = tf.constant(SNOW_PARAMS, dtype=tf.float32)
28
+ snow_intensity = tf.gather(params[:, 0], idx)
29
+ brightness_factor = tf.gather(params[:, 1], idx)
30
+
31
+ seeds = tf.random.split(seed, 2)
32
+ image_f = tf.cast(image, tf.float32)
33
+
34
+ h, w = tf.shape(image)[0], tf.shape(image)[1]
35
+
36
+ # 1. Generate Snowflakes at lower resolution
37
+ scale = 0.25
38
+ h_snow, w_snow = (
39
+ tf.cast(tf.cast(h, tf.float32) * scale, tf.int32),
40
+ tf.cast(tf.cast(w, tf.float32) * scale, tf.int32),
41
+ )
42
+
43
+ snow_layer = tf.random.stateless_normal([h_snow, w_snow, 1], seed=seeds[0])
44
+ snow_threshold = 2.5 - (snow_intensity * 0.5)
45
+ snow_layer = tf.cast(snow_layer > snow_threshold, tf.float32)
46
+ snow_layer = tf.image.resize(snow_layer, [h, w], method="nearest")
47
+
48
+ # 2. Apply Asymmetric Gaussian Blur (Motion Blur)
49
+ # Strong vertical blur (sigma=4.0) to create streaks
50
+ # Weak horizontal blur (sigma=0.5) to give slight width
51
+ sigma_motion = 4.0
52
+ sigma_width = 0.5
53
+
54
+ # Kernel sizes approx 4*sigma + 1
55
+ k_motion = 17
56
+ k_width = 3
57
+
58
+ ky = _get_gaussian_kernel(sigma_motion, k_motion)
59
+ kx = _get_gaussian_kernel(sigma_width, k_width)
60
+
61
+ # Create 2D Separable Kernel [k_motion, k_width]
62
+ # Shape: [k_motion, k_width]
63
+ kernel_2d = tf.matmul(ky[:, tf.newaxis], kx[tf.newaxis, :])
64
+ # Shape for depthwise conv: [H, W, In, Multiplier] -> [k_motion, k_width, 1, 1]
65
+ kernel_4d = kernel_2d[:, :, tf.newaxis, tf.newaxis]
66
+
67
+ # Pad snow layer to avoid border artifacts during blur
68
+ snow_4d = to_4d(snow_layer)
69
+ snow_padded = _pad(snow_4d, [k_motion, k_width], pad_mode="CONSTANT")
70
+
71
+ snow_blur = tf.nn.depthwise_conv2d(
72
+ snow_padded, kernel_4d, strides=[1, 1, 1, 1], padding="VALID"
73
+ )
74
+
75
+ # 3. Rotate to simulate falling angle (-15 degrees)
76
+ # We rotate the streaks to make them fall diagonally
77
+ # Note: _rotate automatically handles the 4D conversion internally if needed
78
+ snow_blur_3d = from_4d(snow_blur, tf.rank(snow_layer))
79
+ snow_final = _rotate(snow_blur_3d, degrees=-15.0, replace=0)
80
+
81
+ # Scale intensity
82
+ snow_final = snow_final * 255.0 * snow_intensity
83
+
84
+ # 4. Whiten the original image
85
+ image_whitened = image_f * (1.0 - brightness_factor) + (255.0 * brightness_factor)
86
+
87
+ output = tf.clip_by_value(image_whitened + snow_final, 0.0, 255.0)
88
+
89
+ return output
90
+
91
+
92
+ def _get_gaussian_kernel(sigma: float, filter_size: int) -> tf.Tensor:
93
+ """Computes 1D Gaussian kernel."""
94
+ x = tf.range(
95
+ tf.cast(-filter_size // 2 + 1, tf.float32),
96
+ tf.cast(filter_size // 2 + 1, tf.float32),
97
+ )
98
+ x = x**2
99
+ x = tf.nn.softmax(-x / (2.0 * (sigma**2)))
100
+ return x
@@ -0,0 +1,34 @@
1
+ from justdata.core.registry import register_dataset
2
+
3
+ register_dataset("cifar10", "classification", modality="vision")
4
+ register_dataset("cifar100", "classification", modality="vision")
5
+ register_dataset("imagenet", "classification", modality="vision")
6
+ register_dataset("imagenette", "classification", modality="vision")
7
+ register_dataset("stanford_dogs", "classification", modality="vision")
8
+ register_dataset("kitti_road", "segmentation", modality="vision")
9
+ register_dataset("zenodo:", "classification", modality="vision")
10
+
11
+ register_dataset(
12
+ "wilds:camelyon17",
13
+ "classification",
14
+ modality="vision",
15
+ preset="wilds:camelyon17",
16
+ )
17
+ register_dataset(
18
+ "wilds:fmow",
19
+ "classification",
20
+ modality="vision",
21
+ preset="wilds:fmow",
22
+ )
23
+ register_dataset(
24
+ "wilds:iwildcam",
25
+ "classification",
26
+ modality="vision",
27
+ preset="wilds:iwildcam",
28
+ )
29
+ register_dataset(
30
+ "wilds:rxrx1",
31
+ "classification",
32
+ modality="vision",
33
+ preset="wilds:rxrx1",
34
+ )
@@ -0,0 +1 @@
1
+