euler-inference 2.3.0__tar.gz → 2.5.0__tar.gz
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.
- {euler_inference-2.3.0 → euler_inference-2.5.0}/PKG-INFO +1 -1
- {euler_inference-2.3.0 → euler_inference-2.5.0}/README.md +20 -8
- {euler_inference-2.3.0 → euler_inference-2.5.0}/euler_inference/_outputs.py +117 -6
- {euler_inference-2.3.0 → euler_inference-2.5.0}/euler_inference/config.py +10 -5
- {euler_inference-2.3.0 → euler_inference-2.5.0}/euler_inference/inference.py +134 -14
- {euler_inference-2.3.0 → euler_inference-2.5.0}/euler_inference.egg-info/PKG-INFO +1 -1
- {euler_inference-2.3.0 → euler_inference-2.5.0}/pyproject.toml +1 -1
- {euler_inference-2.3.0 → euler_inference-2.5.0}/tests/test_model_card.py +138 -10
- {euler_inference-2.3.0 → euler_inference-2.5.0}/tests/test_writer_integration.py +154 -0
- {euler_inference-2.3.0 → euler_inference-2.5.0}/euler_inference/__init__.py +0 -0
- {euler_inference-2.3.0 → euler_inference-2.5.0}/euler_inference/__main__.py +0 -0
- {euler_inference-2.3.0 → euler_inference-2.5.0}/euler_inference/api.py +0 -0
- {euler_inference-2.3.0 → euler_inference-2.5.0}/euler_inference/model_card.py +0 -0
- {euler_inference-2.3.0 → euler_inference-2.5.0}/euler_inference/models/__init__.py +0 -0
- {euler_inference-2.3.0 → euler_inference-2.5.0}/euler_inference/models/external_model.py +0 -0
- {euler_inference-2.3.0 → euler_inference-2.5.0}/euler_inference.egg-info/SOURCES.txt +0 -0
- {euler_inference-2.3.0 → euler_inference-2.5.0}/euler_inference.egg-info/dependency_links.txt +0 -0
- {euler_inference-2.3.0 → euler_inference-2.5.0}/euler_inference.egg-info/entry_points.txt +0 -0
- {euler_inference-2.3.0 → euler_inference-2.5.0}/euler_inference.egg-info/requires.txt +0 -0
- {euler_inference-2.3.0 → euler_inference-2.5.0}/euler_inference.egg-info/top_level.txt +0 -0
- {euler_inference-2.3.0 → euler_inference-2.5.0}/setup.cfg +0 -0
- {euler_inference-2.3.0 → euler_inference-2.5.0}/tests/test_intrinsics_resolution.py +0 -0
- {euler_inference-2.3.0 → euler_inference-2.5.0}/tests/test_model_metadata.py +0 -0
- {euler_inference-2.3.0 → euler_inference-2.5.0}/tests/test_save_path.py +0 -0
|
@@ -104,6 +104,8 @@ Models can declare class-level attributes so pipelines don't need to know model
|
|
|
104
104
|
class Model:
|
|
105
105
|
OUTPUTS = [
|
|
106
106
|
{"key": "depth", "type": "npy"},
|
|
107
|
+
# Dense 3D point map in (3, H, W) layout:
|
|
108
|
+
# {"key": "points_3d", "type": "npy"},
|
|
107
109
|
{"key": "confidence", "type": "png"},
|
|
108
110
|
]
|
|
109
111
|
|
|
@@ -169,23 +171,30 @@ Model cards separate the model's self-description from runtime configuration. Th
|
|
|
169
171
|
}
|
|
170
172
|
```
|
|
171
173
|
|
|
172
|
-
#### Inline splits
|
|
174
|
+
#### Inline splits and scoped metadata
|
|
173
175
|
|
|
174
|
-
Modality values can be a structured object instead of a plain path string, allowing you to select an inline [ds-crawler](https://github.com/d-rothen/ds-crawler) split:
|
|
176
|
+
Modality values can be a structured object instead of a plain path string, allowing you to select an inline [ds-crawler](https://github.com/d-rothen/ds-crawler) split or disambiguate scoped metadata:
|
|
175
177
|
|
|
176
178
|
```json
|
|
177
179
|
{
|
|
178
180
|
"inputs": {
|
|
179
|
-
"rgb": {"path": "{{modality:rgb}}", "split": "test"}
|
|
181
|
+
"rgb": {"path": "{{modality:rgb}}", "split": "test"},
|
|
182
|
+
"image": {"path": "{{modality:muses_archive}}", "modality_key": "rgb"}
|
|
180
183
|
},
|
|
181
184
|
"hierarchical_inputs": {
|
|
182
|
-
"textgt": {"path": "{{hierarchical_modality:textgt}}"}
|
|
185
|
+
"textgt": {"path": "{{hierarchical_modality:textgt}}"},
|
|
186
|
+
"camera_extrinsics": {
|
|
187
|
+
"path": "{{hierarchical_modality:muses_archive}}",
|
|
188
|
+
"metadata_scope": "camera_extrinsics"
|
|
189
|
+
}
|
|
183
190
|
}
|
|
184
191
|
}
|
|
185
192
|
```
|
|
186
193
|
|
|
187
194
|
When `split` is specified, euler-loading reads the full ds-crawler metadata from the modality root and overlays the dataset payload from `.ds_crawler/split_<name>.json`. Sample IDs are matched by intersection across modalities, so it is fine to only specify a split on some modalities. Plain path strings (without `split`) continue to work as before.
|
|
188
195
|
|
|
196
|
+
When several configured modalities point at the same directory or zip, euler-inference tries to infer the matching euler-loading `metadata_scope` from the input key or `modality_key` and the scoped ds-crawler metadata. Use `metadata_scope` for an explicit scope, or `modality_key` / `modality_type` when the model input name differs from the dataset modality key.
|
|
197
|
+
|
|
189
198
|
### CLI usage
|
|
190
199
|
|
|
191
200
|
```bash
|
|
@@ -270,11 +279,11 @@ For simpler setups without placeholders, use a monolithic JSON config:
|
|
|
270
279
|
|-------|------|----------|-------------|
|
|
271
280
|
| `external_model.model_path` | string | Yes | **Absolute** path to model `.py` file |
|
|
272
281
|
| `external_model.model_config` | object/string | No | Model-specific config (dict or path to JSON). Passed as `config` to `Model.__init__`. Defaults to `{}`. |
|
|
273
|
-
| `dataset.modalities` | object | Yes | Map of modality names to root paths (string) or structured entries (`{"path": "...", "split": "..."}`) |
|
|
282
|
+
| `dataset.modalities` | object | Yes | Map of modality names to root paths (string) or structured entries (`{"path": "...", "split": "...", "metadata_scope": "...", "modality_key": "..."}`) |
|
|
274
283
|
| `dataset.hierarchical_modalities` | object | No | Map of hierarchical modality names to paths or structured entries |
|
|
275
284
|
| `outputs` | list | No | What to save from the model's output dict. Defaults to the model's `OUTPUTS`, else `[{"key": "depth", "type": "npy"}]` with the default `_depth` suffix. |
|
|
276
285
|
| `outputs[].key` | string | Yes | Key in the dict returned by `Model.predict()` |
|
|
277
|
-
| `outputs[].type` | string | Yes | Legacy file format: `npy`, `png`, `jpg`, `jpeg`, `exr`. Used when no source-backed writer is available. |
|
|
286
|
+
| `outputs[].type` | string | Yes | Legacy file format: `npy`, `npz`, `png`, `jpg`, `jpeg`, `exr`. Used when no source-backed writer is available. |
|
|
278
287
|
| `outputs[].suffix` | string | No | Legacy filename suffix before extension. Defaults to `_<key>`. Ignored for source-backed outputs. |
|
|
279
288
|
| `outputs[].source_modality` | string | No | Regular input modality whose `euler-loading` writer/path should be mirrored under `output_base_path/<key>/`. Defaults to `key` when it matches a regular input modality. |
|
|
280
289
|
| `outputs[].writer` | object | No | Override ds-crawler writer metadata for legacy outputs (see [Writer metadata](#writer-metadata)) |
|
|
@@ -438,6 +447,8 @@ output_base_path/
|
|
|
438
447
|
|
|
439
448
|
If `outputs[].source_modality` is set explicitly but the named modality is missing, or no `euler-loading` writer is available for it, inference fails instead of silently falling back.
|
|
440
449
|
|
|
450
|
+
`points_3d` is a built-in legacy output modality. Configure it as `{"key": "points_3d", "type": "npy"}` or `{"key": "points_3d", "type": "npz"}` and return a float-compatible array with shape `(3, H, W)`. The output dataset is indexed with `euler_loading.loader = "generic"` and `euler_loading.function = "points_3d"`, so recent `euler-loading` versions can read it without an explicit loader.
|
|
451
|
+
|
|
441
452
|
### Pipeline Manifest
|
|
442
453
|
|
|
443
454
|
When `pipeline.outputs_manifest_path` is set and at least one configured output has a matching pipeline target, finalization writes a manifest like this:
|
|
@@ -470,7 +481,7 @@ Legacy outputs are written via ds-crawler's `DatasetWriter`/`ZipDatasetWriter`,
|
|
|
470
481
|
| `name` | Input dataset's name (from its `output.json`), or the output key if unavailable | `outputs[].writer.name` |
|
|
471
482
|
| `type` | Output key (e.g. `"depth"`) | `outputs[].writer.type` |
|
|
472
483
|
| `euler_train` | `{"used_as": "target", "modality_type": "<key>"}` | `outputs[].writer.euler_train` |
|
|
473
|
-
| `euler_loading` | *(omitted)* | `outputs[].writer.euler_loading` |
|
|
484
|
+
| `euler_loading` | *(omitted; `points_3d` defaults to `{"loader": "generic", "function": "points_3d"}`)* | `outputs[].writer.euler_loading` |
|
|
474
485
|
| `separator` | `null` | — |
|
|
475
486
|
| `meta` | *(omitted)* | `outputs[].writer.meta` |
|
|
476
487
|
|
|
@@ -478,7 +489,7 @@ In `--no-strict` mode, `modality_type` defaults to `"other"` instead of the outp
|
|
|
478
489
|
|
|
479
490
|
#### `euler_loading`
|
|
480
491
|
|
|
481
|
-
When the output dataset should be loadable by [euler-loading](https://github.com/d-rothen/euler-loading) without an explicit loader, set `euler_loading` with the `loader` (module name) and `function` (callable name) that euler-loading should use to auto-resolve a loader from the output's `output.json`. Available loaders
|
|
492
|
+
When the output dataset should be loadable by [euler-loading](https://github.com/d-rothen/euler-loading) without an explicit loader, set `euler_loading` with the `loader` (module name) and `function` (callable name) that euler-loading should use to auto-resolve a loader from the output's `output.json`. Available loaders include `vkitti2`, `real_drive_sim`, `generic`, and `generic_dense_depth`.
|
|
482
493
|
|
|
483
494
|
You can also include `used_as`, `modality_type`, `slot`, and `task` — these are consulted by euler-loading's `describe_for_runlog()` for experiment metadata.
|
|
484
495
|
|
|
@@ -506,6 +517,7 @@ Example with explicit writer overrides:
|
|
|
506
517
|
| Format | Extension | Notes |
|
|
507
518
|
|--------|-----------|-------|
|
|
508
519
|
| NumPy | `npy` | Preserves full float precision |
|
|
520
|
+
| NumPy archive | `npz` | Compressed NumPy archive with array key `data` |
|
|
509
521
|
| PNG | `png` | Float arrays clipped to [0,1] and scaled to uint8. Supports grayscale, RGB, RGBA. |
|
|
510
522
|
| JPEG | `jpg`/`jpeg` | Same as PNG but lossy. |
|
|
511
523
|
| OpenEXR | `exr` | Full float precision. Requires `pip install OpenEXR`. Not supported in zip mode. |
|
|
@@ -18,6 +18,14 @@ from euler_inference.config import (
|
|
|
18
18
|
|
|
19
19
|
PIPELINE_OUTPUTS_MANIFEST_VERSION = 1
|
|
20
20
|
|
|
21
|
+
_NUMPY_OUTPUT_TYPES = {"npy", "npz"}
|
|
22
|
+
_LOADABLE_LEGACY_OUTPUTS = {
|
|
23
|
+
"points_3d": {
|
|
24
|
+
"euler_loading": {"loader": "generic", "function": "points_3d"},
|
|
25
|
+
"output_types": _NUMPY_OUTPUT_TYPES,
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
|
|
21
29
|
|
|
22
30
|
def get_save_path(output_base: Path, full_id: str, suffix: str, extension: str) -> Path:
|
|
23
31
|
"""
|
|
@@ -100,7 +108,7 @@ def save_output(data: np.ndarray, target: Path | IO[bytes], output_type: str) ->
|
|
|
100
108
|
Args:
|
|
101
109
|
data: numpy array to save
|
|
102
110
|
target: Path to save to, or a writable file-like object (for zip streaming)
|
|
103
|
-
output_type: File format ("npy", "png", "jpg", "jpeg", "exr")
|
|
111
|
+
output_type: File format ("npy", "npz", "png", "jpg", "jpeg", "exr")
|
|
104
112
|
|
|
105
113
|
Raises:
|
|
106
114
|
ValueError: If output_type is not supported
|
|
@@ -112,6 +120,10 @@ def save_output(data: np.ndarray, target: Path | IO[bytes], output_type: str) ->
|
|
|
112
120
|
np.save(target, data)
|
|
113
121
|
return
|
|
114
122
|
|
|
123
|
+
if output_type == "npz":
|
|
124
|
+
np.savez_compressed(target, data=data)
|
|
125
|
+
return
|
|
126
|
+
|
|
115
127
|
if output_type in ("png", "jpg", "jpeg"):
|
|
116
128
|
_save_image_output(data, target, output_type)
|
|
117
129
|
return
|
|
@@ -125,6 +137,88 @@ def save_output(data: np.ndarray, target: Path | IO[bytes], output_type: str) ->
|
|
|
125
137
|
raise ValueError(f"Unsupported output type: {output_type}")
|
|
126
138
|
|
|
127
139
|
|
|
140
|
+
def _get_writer_modality_type(
|
|
141
|
+
output_config: OutputConfig,
|
|
142
|
+
writer_meta: dict[str, Any],
|
|
143
|
+
*,
|
|
144
|
+
strict: bool,
|
|
145
|
+
) -> str:
|
|
146
|
+
euler_train = writer_meta.get("euler_train")
|
|
147
|
+
if isinstance(euler_train, dict):
|
|
148
|
+
modality_type = euler_train.get("modality_type")
|
|
149
|
+
if modality_type:
|
|
150
|
+
return modality_type
|
|
151
|
+
|
|
152
|
+
if output_config.key in _LOADABLE_LEGACY_OUTPUTS:
|
|
153
|
+
return output_config.key
|
|
154
|
+
|
|
155
|
+
if strict:
|
|
156
|
+
return output_config.key
|
|
157
|
+
return "other"
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _get_loadable_legacy_output(modality_type: str) -> dict[str, Any] | None:
|
|
161
|
+
return _LOADABLE_LEGACY_OUTPUTS.get(modality_type)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _get_writer_type_default(
|
|
165
|
+
output_config: OutputConfig,
|
|
166
|
+
writer_meta: dict[str, Any],
|
|
167
|
+
) -> str:
|
|
168
|
+
euler_train = writer_meta.get("euler_train")
|
|
169
|
+
if isinstance(euler_train, dict):
|
|
170
|
+
modality_type = euler_train.get("modality_type")
|
|
171
|
+
if modality_type:
|
|
172
|
+
return modality_type
|
|
173
|
+
return output_config.key
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _validate_loadable_legacy_output(
|
|
177
|
+
output_config: OutputConfig,
|
|
178
|
+
modality_type: str,
|
|
179
|
+
) -> None:
|
|
180
|
+
loadable = _get_loadable_legacy_output(modality_type)
|
|
181
|
+
if loadable is None:
|
|
182
|
+
return
|
|
183
|
+
|
|
184
|
+
output_types = loadable.get("output_types")
|
|
185
|
+
if output_types and output_config.type not in output_types:
|
|
186
|
+
supported = ", ".join(sorted(output_types))
|
|
187
|
+
raise ValueError(
|
|
188
|
+
f"{modality_type} outputs must use one of: {supported}. "
|
|
189
|
+
f"Got: {output_config.type}"
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _to_numpy(data: Any) -> np.ndarray:
|
|
194
|
+
if hasattr(data, "detach"):
|
|
195
|
+
data = data.detach()
|
|
196
|
+
if hasattr(data, "cpu"):
|
|
197
|
+
data = data.cpu()
|
|
198
|
+
if hasattr(data, "numpy"):
|
|
199
|
+
data = data.numpy()
|
|
200
|
+
return np.asarray(data)
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def _prepare_legacy_output_data(data: Any, output_config: OutputConfig) -> Any:
|
|
204
|
+
writer_meta = output_config.writer or {}
|
|
205
|
+
modality_type = _get_writer_modality_type(
|
|
206
|
+
output_config,
|
|
207
|
+
writer_meta,
|
|
208
|
+
strict=True,
|
|
209
|
+
)
|
|
210
|
+
if modality_type != "points_3d":
|
|
211
|
+
return data
|
|
212
|
+
|
|
213
|
+
arr = _to_numpy(data)
|
|
214
|
+
if arr.ndim != 3 or arr.shape[0] != 3:
|
|
215
|
+
raise ValueError(
|
|
216
|
+
"points_3d output must have shape (3, H, W), "
|
|
217
|
+
f"got {arr.shape}"
|
|
218
|
+
)
|
|
219
|
+
return arr.astype(np.float32, copy=False)
|
|
220
|
+
|
|
221
|
+
|
|
128
222
|
def _get_writer_kwargs(
|
|
129
223
|
output_config: OutputConfig,
|
|
130
224
|
*,
|
|
@@ -134,14 +228,20 @@ def _get_writer_kwargs(
|
|
|
134
228
|
"""Derive DatasetWriter/ZipDatasetWriter kwargs from an OutputConfig."""
|
|
135
229
|
writer_meta = output_config.writer or {}
|
|
136
230
|
name = writer_meta.get("name", dataset_name or output_config.key)
|
|
231
|
+
modality_type = _get_writer_modality_type(
|
|
232
|
+
output_config,
|
|
233
|
+
writer_meta,
|
|
234
|
+
strict=strict,
|
|
235
|
+
)
|
|
236
|
+
_validate_loadable_legacy_output(output_config, modality_type)
|
|
237
|
+
|
|
137
238
|
type_ = writer_meta.get(
|
|
138
239
|
"type",
|
|
139
|
-
|
|
240
|
+
_get_writer_type_default(output_config, writer_meta),
|
|
140
241
|
)
|
|
141
|
-
default_modality_type = output_config.key if strict else "other"
|
|
142
242
|
euler_train = writer_meta.get("euler_train", {
|
|
143
243
|
"used_as": "target",
|
|
144
|
-
"modality_type":
|
|
244
|
+
"modality_type": modality_type,
|
|
145
245
|
})
|
|
146
246
|
kwargs = dict(name=name, type=type_, euler_train=euler_train, separator=None)
|
|
147
247
|
|
|
@@ -149,7 +249,15 @@ def _get_writer_kwargs(
|
|
|
149
249
|
if meta is not None:
|
|
150
250
|
kwargs["meta"] = meta
|
|
151
251
|
|
|
152
|
-
euler_loading
|
|
252
|
+
if "euler_loading" in writer_meta:
|
|
253
|
+
euler_loading = writer_meta.get("euler_loading")
|
|
254
|
+
else:
|
|
255
|
+
loadable = _get_loadable_legacy_output(modality_type)
|
|
256
|
+
euler_loading = (
|
|
257
|
+
loadable.get("euler_loading")
|
|
258
|
+
if loadable is not None
|
|
259
|
+
else None
|
|
260
|
+
)
|
|
153
261
|
if euler_loading is not None:
|
|
154
262
|
merged = {
|
|
155
263
|
key: value for key, value in euler_train.items()
|
|
@@ -472,7 +580,10 @@ class PreparedOutputs:
|
|
|
472
580
|
|
|
473
581
|
file_id = _full_id_leaf(full_id)
|
|
474
582
|
for output_config in self.legacy_outputs:
|
|
475
|
-
output_data =
|
|
583
|
+
output_data = _prepare_legacy_output_data(
|
|
584
|
+
outputs[output_config.key],
|
|
585
|
+
output_config,
|
|
586
|
+
)
|
|
476
587
|
basename = (
|
|
477
588
|
f"{file_id}{output_config.effective_suffix}.{output_config.type}"
|
|
478
589
|
)
|
|
@@ -13,7 +13,7 @@ class OutputConfig:
|
|
|
13
13
|
|
|
14
14
|
Attributes:
|
|
15
15
|
key: Key in the model's output dictionary (e.g., "depth", "dehazed")
|
|
16
|
-
type: File format to save as ("npy", "png", "jpg", "exr")
|
|
16
|
+
type: File format to save as ("npy", "npz", "png", "jpg", "exr")
|
|
17
17
|
suffix: Filename suffix before extension. Defaults to "_{key}".
|
|
18
18
|
Use empty string "" for no suffix (filename will be {id}.{type}).
|
|
19
19
|
source_modality: Optional regular input modality whose euler-loading
|
|
@@ -35,7 +35,7 @@ class OutputConfig:
|
|
|
35
35
|
if not self.type:
|
|
36
36
|
raise ValueError("output.type is required")
|
|
37
37
|
|
|
38
|
-
supported_types = {"npy", "png", "jpg", "jpeg", "exr"}
|
|
38
|
+
supported_types = {"npy", "npz", "png", "jpg", "jpeg", "exr"}
|
|
39
39
|
if self.type not in supported_types:
|
|
40
40
|
raise ValueError(
|
|
41
41
|
f"Unsupported output type '{self.type}'. Supported: {supported_types}"
|
|
@@ -246,16 +246,21 @@ class DatasetConfig:
|
|
|
246
246
|
``output.json``.
|
|
247
247
|
|
|
248
248
|
Modality values may be either a plain path string or a structured
|
|
249
|
-
dict with ``path`` (required)
|
|
249
|
+
dict with ``path`` (required), ``split`` (optional), ``metadata_scope``
|
|
250
|
+
(optional), and ``modality_type`` / ``modality_key`` (optional) keys::
|
|
250
251
|
|
|
251
252
|
"modalities": {
|
|
252
253
|
"rgb": "/data/rgb",
|
|
253
|
-
"depth": {"path": "/data/depth", "split": "test"}
|
|
254
|
+
"depth": {"path": "/data/depth", "split": "test"},
|
|
255
|
+
"image": {"path": "/data/muses.zip", "modality_key": "rgb"}
|
|
254
256
|
}
|
|
255
257
|
|
|
256
258
|
When ``split`` is specified, euler-loading reads the full ds-crawler
|
|
257
259
|
metadata from the modality root and overlays the dataset payload from
|
|
258
|
-
the named inline split.
|
|
260
|
+
the named inline split. When multiple configured modalities point to the
|
|
261
|
+
same physical path, euler-inference attempts to infer a fitting
|
|
262
|
+
euler-loading metadata scope from the modality key and scoped ds-crawler
|
|
263
|
+
metadata.
|
|
259
264
|
|
|
260
265
|
Attributes:
|
|
261
266
|
modalities: Mapping of modality names to their root paths or
|
|
@@ -16,6 +16,7 @@ Usage:
|
|
|
16
16
|
import argparse
|
|
17
17
|
import logging
|
|
18
18
|
from pathlib import Path
|
|
19
|
+
from typing import NamedTuple
|
|
19
20
|
|
|
20
21
|
from euler_loading import Modality, MultiModalDataset
|
|
21
22
|
from tqdm import tqdm
|
|
@@ -53,26 +54,147 @@ def setup_logging(verbose: bool = False) -> logging.Logger:
|
|
|
53
54
|
return logging.getLogger(__name__)
|
|
54
55
|
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
class _ParsedModalityEntry(NamedTuple):
|
|
58
|
+
path: str
|
|
59
|
+
split: str | None
|
|
60
|
+
metadata_scope: str | None
|
|
61
|
+
modality_type: str | None
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _optional_string(value: object, field_name: str) -> str | None:
|
|
65
|
+
if value is None:
|
|
66
|
+
return None
|
|
67
|
+
if not isinstance(value, str):
|
|
68
|
+
raise TypeError(f"Modality entry field '{field_name}' must be a string")
|
|
69
|
+
stripped = value.strip()
|
|
70
|
+
return stripped or None
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _parse_modality_entry(entry: str | dict) -> _ParsedModalityEntry:
|
|
74
|
+
"""Parse a modality config entry.
|
|
58
75
|
|
|
59
76
|
Accepts either a plain path string or a structured dict with
|
|
60
|
-
``path`` (required)
|
|
77
|
+
``path`` (required), ``split`` (optional), ``metadata_scope`` (optional),
|
|
78
|
+
and ``modality_type`` / ``modality_key`` (optional) keys.
|
|
61
79
|
"""
|
|
62
80
|
if isinstance(entry, str):
|
|
63
|
-
return entry, None
|
|
81
|
+
return _ParsedModalityEntry(entry, None, None, None)
|
|
64
82
|
if isinstance(entry, dict):
|
|
65
83
|
path = entry.get("path")
|
|
66
84
|
if not path:
|
|
67
85
|
raise ValueError(
|
|
68
86
|
f"Structured modality entry must have a 'path' key, got: {entry}"
|
|
69
87
|
)
|
|
70
|
-
|
|
88
|
+
metadata_scope = _optional_string(
|
|
89
|
+
entry.get("metadata_scope"),
|
|
90
|
+
"metadata_scope",
|
|
91
|
+
)
|
|
92
|
+
modality_type = _optional_string(
|
|
93
|
+
entry.get("modality_type"),
|
|
94
|
+
"modality_type",
|
|
95
|
+
) or _optional_string(entry.get("modality_key"), "modality_key")
|
|
96
|
+
return _ParsedModalityEntry(
|
|
97
|
+
path,
|
|
98
|
+
_optional_string(entry.get("split"), "split"),
|
|
99
|
+
metadata_scope,
|
|
100
|
+
modality_type,
|
|
101
|
+
)
|
|
71
102
|
raise TypeError(
|
|
72
103
|
f"Modality entry must be a string or dict, got {type(entry).__name__}"
|
|
73
104
|
)
|
|
74
105
|
|
|
75
106
|
|
|
107
|
+
def _normalize_modality_entry(entry: _ParsedModalityEntry) -> _ParsedModalityEntry:
|
|
108
|
+
"""Let euler-loading normalize inline :split and #scope selectors."""
|
|
109
|
+
modality = Modality(
|
|
110
|
+
entry.path,
|
|
111
|
+
split=entry.split,
|
|
112
|
+
metadata_scope=entry.metadata_scope,
|
|
113
|
+
modality_type=entry.modality_type,
|
|
114
|
+
)
|
|
115
|
+
return _ParsedModalityEntry(
|
|
116
|
+
modality.path,
|
|
117
|
+
modality.split,
|
|
118
|
+
modality.metadata_scope,
|
|
119
|
+
modality.modality_type,
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _read_scoped_modality_key(path: str, scope: str) -> str | None:
|
|
124
|
+
from ds_crawler.zip_utils import DATASET_HEAD_FILENAME, read_metadata_json
|
|
125
|
+
|
|
126
|
+
head = read_metadata_json(
|
|
127
|
+
Path(path),
|
|
128
|
+
DATASET_HEAD_FILENAME,
|
|
129
|
+
metadata_scope=scope,
|
|
130
|
+
)
|
|
131
|
+
if not isinstance(head, dict):
|
|
132
|
+
return None
|
|
133
|
+
modality = head.get("modality")
|
|
134
|
+
if not isinstance(modality, dict):
|
|
135
|
+
return None
|
|
136
|
+
key = modality.get("key")
|
|
137
|
+
return key.strip() if isinstance(key, str) and key.strip() else None
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _has_unscoped_metadata(path: str) -> bool:
|
|
141
|
+
from ds_crawler.config import CONFIG_FILENAME
|
|
142
|
+
from ds_crawler.zip_utils import (
|
|
143
|
+
DATASET_HEAD_FILENAME,
|
|
144
|
+
OUTPUT_FILENAME,
|
|
145
|
+
read_metadata_json,
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
dataset_path = Path(path)
|
|
149
|
+
return any(
|
|
150
|
+
read_metadata_json(dataset_path, filename) is not None
|
|
151
|
+
for filename in (OUTPUT_FILENAME, CONFIG_FILENAME, DATASET_HEAD_FILENAME)
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _infer_metadata_scope(path: str, modality_key: str) -> str | None:
|
|
156
|
+
"""Infer a scoped metadata selector from ds-crawler scope metadata."""
|
|
157
|
+
from ds_crawler import list_metadata_scopes
|
|
158
|
+
|
|
159
|
+
try:
|
|
160
|
+
if _has_unscoped_metadata(path):
|
|
161
|
+
return None
|
|
162
|
+
scopes = list_metadata_scopes(Path(path))
|
|
163
|
+
except (FileNotFoundError, NotADirectoryError):
|
|
164
|
+
return None
|
|
165
|
+
|
|
166
|
+
if modality_key in scopes:
|
|
167
|
+
return modality_key
|
|
168
|
+
|
|
169
|
+
matches = [
|
|
170
|
+
scope
|
|
171
|
+
for scope in scopes
|
|
172
|
+
if _read_scoped_modality_key(path, scope) == modality_key
|
|
173
|
+
]
|
|
174
|
+
if len(matches) == 1:
|
|
175
|
+
return matches[0]
|
|
176
|
+
return None
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _build_modality_specs(entries: dict) -> dict[str, Modality]:
|
|
180
|
+
specs = {}
|
|
181
|
+
for name, entry in entries.items():
|
|
182
|
+
parsed = _normalize_modality_entry(_parse_modality_entry(entry))
|
|
183
|
+
metadata_scope = parsed.metadata_scope
|
|
184
|
+
if metadata_scope is None:
|
|
185
|
+
metadata_scope = _infer_metadata_scope(
|
|
186
|
+
parsed.path,
|
|
187
|
+
parsed.modality_type or name,
|
|
188
|
+
)
|
|
189
|
+
specs[name] = Modality(
|
|
190
|
+
parsed.path,
|
|
191
|
+
split=parsed.split,
|
|
192
|
+
metadata_scope=metadata_scope,
|
|
193
|
+
modality_type=parsed.modality_type,
|
|
194
|
+
)
|
|
195
|
+
return specs
|
|
196
|
+
|
|
197
|
+
|
|
76
198
|
def create_dataset(config: InferenceConfig) -> MultiModalDataset:
|
|
77
199
|
"""
|
|
78
200
|
Create euler-loading dataset from configuration.
|
|
@@ -82,7 +204,9 @@ def create_dataset(config: InferenceConfig) -> MultiModalDataset:
|
|
|
82
204
|
|
|
83
205
|
Each modality entry in the config can be either a plain path string
|
|
84
206
|
or a structured dict ``{"path": "...", "split": "..."}`` where
|
|
85
|
-
``split`` selects an inline ds-crawler split.
|
|
207
|
+
``split`` selects an inline ds-crawler split. Structured entries may
|
|
208
|
+
also set ``metadata_scope`` or ``modality_type`` / ``modality_key`` to
|
|
209
|
+
disambiguate archives that carry multiple scoped modalities.
|
|
86
210
|
|
|
87
211
|
Args:
|
|
88
212
|
config: Inference configuration
|
|
@@ -90,17 +214,13 @@ def create_dataset(config: InferenceConfig) -> MultiModalDataset:
|
|
|
90
214
|
Returns:
|
|
91
215
|
MultiModalDataset with all configured modalities
|
|
92
216
|
"""
|
|
93
|
-
modalities =
|
|
94
|
-
for name, entry in config.dataset.modalities.items():
|
|
95
|
-
path, split = _parse_modality_entry(entry)
|
|
96
|
-
modalities[name] = Modality(path, split=split)
|
|
217
|
+
modalities = _build_modality_specs(config.dataset.modalities)
|
|
97
218
|
|
|
98
219
|
hierarchical_modalities = None
|
|
99
220
|
if config.dataset.hierarchical_modalities:
|
|
100
|
-
hierarchical_modalities =
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
hierarchical_modalities[name] = Modality(path, split=split)
|
|
221
|
+
hierarchical_modalities = _build_modality_specs(
|
|
222
|
+
config.dataset.hierarchical_modalities
|
|
223
|
+
)
|
|
104
224
|
|
|
105
225
|
return MultiModalDataset(
|
|
106
226
|
modalities=modalities,
|
|
@@ -3,12 +3,18 @@
|
|
|
3
3
|
import json
|
|
4
4
|
import textwrap
|
|
5
5
|
from pathlib import Path
|
|
6
|
+
from types import SimpleNamespace
|
|
6
7
|
from unittest.mock import patch
|
|
7
8
|
|
|
8
9
|
import numpy as np
|
|
9
10
|
import pytest
|
|
10
11
|
|
|
11
|
-
from euler_inference.config import
|
|
12
|
+
from euler_inference.config import (
|
|
13
|
+
DEFAULT_OUTPUTS,
|
|
14
|
+
DatasetConfig,
|
|
15
|
+
InferenceConfig,
|
|
16
|
+
OutputConfig,
|
|
17
|
+
)
|
|
12
18
|
from euler_inference.model_card import (
|
|
13
19
|
PLACEHOLDER_RE,
|
|
14
20
|
find_unresolved_placeholders,
|
|
@@ -766,23 +772,40 @@ class TestParseModalityEntry:
|
|
|
766
772
|
def test_plain_string_returns_path_and_no_split(self):
|
|
767
773
|
from euler_inference.inference import _parse_modality_entry
|
|
768
774
|
|
|
769
|
-
|
|
770
|
-
assert path == "/data/rgb"
|
|
771
|
-
assert split is None
|
|
775
|
+
entry = _parse_modality_entry("/data/rgb")
|
|
776
|
+
assert entry.path == "/data/rgb"
|
|
777
|
+
assert entry.split is None
|
|
778
|
+
assert entry.metadata_scope is None
|
|
779
|
+
assert entry.modality_type is None
|
|
772
780
|
|
|
773
781
|
def test_structured_dict_with_split(self):
|
|
774
782
|
from euler_inference.inference import _parse_modality_entry
|
|
775
783
|
|
|
776
|
-
|
|
777
|
-
assert path == "/data/rgb"
|
|
778
|
-
assert split == "test"
|
|
784
|
+
entry = _parse_modality_entry({"path": "/data/rgb", "split": "test"})
|
|
785
|
+
assert entry.path == "/data/rgb"
|
|
786
|
+
assert entry.split == "test"
|
|
787
|
+
assert entry.metadata_scope is None
|
|
779
788
|
|
|
780
789
|
def test_structured_dict_without_split(self):
|
|
781
790
|
from euler_inference.inference import _parse_modality_entry
|
|
782
791
|
|
|
783
|
-
|
|
784
|
-
assert path == "/data/rgb"
|
|
785
|
-
assert split is None
|
|
792
|
+
entry = _parse_modality_entry({"path": "/data/rgb"})
|
|
793
|
+
assert entry.path == "/data/rgb"
|
|
794
|
+
assert entry.split is None
|
|
795
|
+
|
|
796
|
+
def test_structured_dict_with_metadata_scope(self):
|
|
797
|
+
from euler_inference.inference import _parse_modality_entry
|
|
798
|
+
|
|
799
|
+
entry = _parse_modality_entry(
|
|
800
|
+
{
|
|
801
|
+
"path": "/data/muses.zip",
|
|
802
|
+
"metadata_scope": "scope-a",
|
|
803
|
+
"modality_key": "rgb",
|
|
804
|
+
}
|
|
805
|
+
)
|
|
806
|
+
assert entry.path == "/data/muses.zip"
|
|
807
|
+
assert entry.metadata_scope == "scope-a"
|
|
808
|
+
assert entry.modality_type == "rgb"
|
|
786
809
|
|
|
787
810
|
def test_missing_path_key_raises(self):
|
|
788
811
|
from euler_inference.inference import _parse_modality_entry
|
|
@@ -795,3 +818,108 @@ class TestParseModalityEntry:
|
|
|
795
818
|
|
|
796
819
|
with pytest.raises(TypeError, match="must be a string or dict"):
|
|
797
820
|
_parse_modality_entry(42)
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
# ---------------------------------------------------------------------------
|
|
824
|
+
# Test: create_dataset scoped modality inference
|
|
825
|
+
# ---------------------------------------------------------------------------
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
class TestCreateDatasetScopedModalities:
|
|
829
|
+
"""Tests for passing euler-loading scope hints from inference configs."""
|
|
830
|
+
|
|
831
|
+
@staticmethod
|
|
832
|
+
def _write_scope(root: Path, scope: str, modality_key: str | None = None) -> None:
|
|
833
|
+
scope_dir = root / ".ds_crawler" / scope
|
|
834
|
+
scope_dir.mkdir(parents=True, exist_ok=True)
|
|
835
|
+
(scope_dir / "index.json").write_text("{}")
|
|
836
|
+
if modality_key is not None:
|
|
837
|
+
(scope_dir / "dataset-head.json").write_text(
|
|
838
|
+
json.dumps({"modality": {"key": modality_key}})
|
|
839
|
+
)
|
|
840
|
+
|
|
841
|
+
def test_infers_metadata_scope_for_shared_path(self, tmp_path, monkeypatch):
|
|
842
|
+
from euler_inference import inference
|
|
843
|
+
|
|
844
|
+
root = tmp_path / "muses"
|
|
845
|
+
root.mkdir()
|
|
846
|
+
self._write_scope(root, "rgb")
|
|
847
|
+
self._write_scope(root, "depth")
|
|
848
|
+
|
|
849
|
+
captured = {}
|
|
850
|
+
|
|
851
|
+
def fake_dataset(**kwargs):
|
|
852
|
+
captured.update(kwargs)
|
|
853
|
+
return object()
|
|
854
|
+
|
|
855
|
+
monkeypatch.setattr(inference, "MultiModalDataset", fake_dataset)
|
|
856
|
+
|
|
857
|
+
config = SimpleNamespace(
|
|
858
|
+
dataset=DatasetConfig(
|
|
859
|
+
modalities={
|
|
860
|
+
"rgb": str(root),
|
|
861
|
+
"depth": str(root),
|
|
862
|
+
},
|
|
863
|
+
)
|
|
864
|
+
)
|
|
865
|
+
inference.create_dataset(config)
|
|
866
|
+
|
|
867
|
+
assert captured["modalities"]["rgb"].metadata_scope == "rgb"
|
|
868
|
+
assert captured["modalities"]["depth"].metadata_scope == "depth"
|
|
869
|
+
|
|
870
|
+
def test_infers_metadata_scope_for_single_scoped_path(self, tmp_path, monkeypatch):
|
|
871
|
+
from euler_inference import inference
|
|
872
|
+
|
|
873
|
+
root = tmp_path / "muses"
|
|
874
|
+
root.mkdir()
|
|
875
|
+
self._write_scope(root, "rgb")
|
|
876
|
+
|
|
877
|
+
captured = {}
|
|
878
|
+
|
|
879
|
+
def fake_dataset(**kwargs):
|
|
880
|
+
captured.update(kwargs)
|
|
881
|
+
return object()
|
|
882
|
+
|
|
883
|
+
monkeypatch.setattr(inference, "MultiModalDataset", fake_dataset)
|
|
884
|
+
|
|
885
|
+
config = SimpleNamespace(
|
|
886
|
+
dataset=DatasetConfig(
|
|
887
|
+
modalities={
|
|
888
|
+
"rgb": str(root),
|
|
889
|
+
},
|
|
890
|
+
)
|
|
891
|
+
)
|
|
892
|
+
inference.create_dataset(config)
|
|
893
|
+
|
|
894
|
+
assert captured["modalities"]["rgb"].metadata_scope == "rgb"
|
|
895
|
+
|
|
896
|
+
def test_infers_scope_from_explicit_modality_key(self, tmp_path, monkeypatch):
|
|
897
|
+
from euler_inference import inference
|
|
898
|
+
|
|
899
|
+
root = tmp_path / "muses"
|
|
900
|
+
root.mkdir()
|
|
901
|
+
self._write_scope(root, "scope-a", modality_key="rgb")
|
|
902
|
+
self._write_scope(root, "scope-b", modality_key="depth")
|
|
903
|
+
|
|
904
|
+
captured = {}
|
|
905
|
+
|
|
906
|
+
def fake_dataset(**kwargs):
|
|
907
|
+
captured.update(kwargs)
|
|
908
|
+
return object()
|
|
909
|
+
|
|
910
|
+
monkeypatch.setattr(inference, "MultiModalDataset", fake_dataset)
|
|
911
|
+
|
|
912
|
+
config = SimpleNamespace(
|
|
913
|
+
dataset=DatasetConfig(
|
|
914
|
+
modalities={
|
|
915
|
+
"image": {"path": str(root), "modality_key": "rgb"},
|
|
916
|
+
"target": {"path": str(root), "modality_key": "depth"},
|
|
917
|
+
},
|
|
918
|
+
)
|
|
919
|
+
)
|
|
920
|
+
inference.create_dataset(config)
|
|
921
|
+
|
|
922
|
+
assert captured["modalities"]["image"].metadata_scope == "scope-a"
|
|
923
|
+
assert captured["modalities"]["image"].modality_type == "rgb"
|
|
924
|
+
assert captured["modalities"]["target"].metadata_scope == "scope-b"
|
|
925
|
+
assert captured["modalities"]["target"].modality_type == "depth"
|
|
@@ -92,6 +92,31 @@ def _make_indexed_rgb_dataset(tmp_path: Path) -> tuple[Path, dict[Path, np.ndarr
|
|
|
92
92
|
return root, written
|
|
93
93
|
|
|
94
94
|
|
|
95
|
+
def _read_output_metadata(root: Path) -> dict:
|
|
96
|
+
"""Read legacy output.json or newer dataset-head metadata."""
|
|
97
|
+
output_json = root / ".ds_crawler" / "output.json"
|
|
98
|
+
if output_json.exists():
|
|
99
|
+
with open(output_json) as f:
|
|
100
|
+
return json.load(f)
|
|
101
|
+
|
|
102
|
+
dataset_head = root / ".ds_crawler" / "dataset-head.json"
|
|
103
|
+
with open(dataset_head) as f:
|
|
104
|
+
head = json.load(f)
|
|
105
|
+
|
|
106
|
+
modality_key = head["modality"]["key"]
|
|
107
|
+
addons = head.get("addons", {})
|
|
108
|
+
euler_train = dict(addons.get("euler_train", {}))
|
|
109
|
+
euler_train.setdefault("modality_type", modality_key)
|
|
110
|
+
euler_loading = dict(addons.get("euler_loading", {}))
|
|
111
|
+
euler_loading.setdefault("modality_type", modality_key)
|
|
112
|
+
return {
|
|
113
|
+
"name": head["dataset"]["name"],
|
|
114
|
+
"type": modality_key,
|
|
115
|
+
"euler_train": euler_train,
|
|
116
|
+
"euler_loading": euler_loading,
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
|
|
95
120
|
# ---------------------------------------------------------------------------
|
|
96
121
|
# _get_writer_kwargs
|
|
97
122
|
# ---------------------------------------------------------------------------
|
|
@@ -232,6 +257,32 @@ class TestGetWriterKwargs:
|
|
|
232
257
|
kw = _get_writer_kwargs(oc, dataset_name=None)
|
|
233
258
|
assert kw["name"] == "depth"
|
|
234
259
|
|
|
260
|
+
def test_points_3d_defaults_to_generic_loader_metadata(self):
|
|
261
|
+
oc = OutputConfig(key="points_3d", type="npy")
|
|
262
|
+
kw = _get_writer_kwargs(oc, strict=True)
|
|
263
|
+
assert kw["type"] == "points_3d"
|
|
264
|
+
assert kw["euler_train"] == {
|
|
265
|
+
"used_as": "target",
|
|
266
|
+
"modality_type": "points_3d",
|
|
267
|
+
}
|
|
268
|
+
assert kw["euler_loading"] == {
|
|
269
|
+
"used_as": "target",
|
|
270
|
+
"modality_type": "points_3d",
|
|
271
|
+
"loader": "generic",
|
|
272
|
+
"function": "points_3d",
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
def test_points_3d_keeps_modality_metadata_in_non_strict_mode(self):
|
|
276
|
+
oc = OutputConfig(key="points_3d", type="npy")
|
|
277
|
+
kw = _get_writer_kwargs(oc, strict=False)
|
|
278
|
+
assert kw["euler_train"]["modality_type"] == "points_3d"
|
|
279
|
+
assert kw["euler_loading"]["function"] == "points_3d"
|
|
280
|
+
|
|
281
|
+
def test_points_3d_rejects_non_numpy_output_format(self):
|
|
282
|
+
oc = OutputConfig(key="points_3d", type="png")
|
|
283
|
+
with pytest.raises(ValueError, match="points_3d outputs must use"):
|
|
284
|
+
_get_writer_kwargs(oc, strict=True)
|
|
285
|
+
|
|
235
286
|
|
|
236
287
|
# ---------------------------------------------------------------------------
|
|
237
288
|
# create_writers
|
|
@@ -415,6 +466,14 @@ class TestSaveOutputFileLike:
|
|
|
415
466
|
loaded = np.load(buf)
|
|
416
467
|
np.testing.assert_array_equal(loaded, data)
|
|
417
468
|
|
|
469
|
+
def test_npz_to_bytesio(self):
|
|
470
|
+
data = np.random.randn(10, 10).astype(np.float32)
|
|
471
|
+
buf = io.BytesIO()
|
|
472
|
+
save_output(data, buf, "npz")
|
|
473
|
+
buf.seek(0)
|
|
474
|
+
loaded = np.load(buf)["data"]
|
|
475
|
+
np.testing.assert_array_equal(loaded, data)
|
|
476
|
+
|
|
418
477
|
def test_png_to_bytesio(self):
|
|
419
478
|
from PIL import Image
|
|
420
479
|
|
|
@@ -459,6 +518,13 @@ class TestSaveOutputFileLike:
|
|
|
459
518
|
loaded = np.load(path)
|
|
460
519
|
np.testing.assert_array_equal(loaded, data)
|
|
461
520
|
|
|
521
|
+
def test_npz_path_still_works(self, tmp_path: Path):
|
|
522
|
+
data = np.random.randn(10, 10).astype(np.float32)
|
|
523
|
+
path = tmp_path / "test.npz"
|
|
524
|
+
save_output(data, path, "npz")
|
|
525
|
+
loaded = np.load(path)["data"]
|
|
526
|
+
np.testing.assert_array_equal(loaded, data)
|
|
527
|
+
|
|
462
528
|
|
|
463
529
|
# ---------------------------------------------------------------------------
|
|
464
530
|
# Filesystem writer end-to-end
|
|
@@ -529,6 +595,26 @@ class TestFilesystemWriterEndToEnd:
|
|
|
529
595
|
index_path = Path(config.output_base_path) / key / ".ds_crawler" / "output.json"
|
|
530
596
|
assert index_path.exists(), f"Missing index for {key}"
|
|
531
597
|
|
|
598
|
+
def test_points_3d_metadata_is_loadable_by_euler_loading(self, tmp_path: Path):
|
|
599
|
+
config = _make_config(
|
|
600
|
+
tmp_path,
|
|
601
|
+
outputs=[OutputConfig(key="points_3d", type="npy")],
|
|
602
|
+
strict=True,
|
|
603
|
+
)
|
|
604
|
+
writers = create_writers(config)
|
|
605
|
+
writer = writers["points_3d"]
|
|
606
|
+
|
|
607
|
+
full_id = "Scene01/Camera_0/00001"
|
|
608
|
+
path = writer.get_path(full_id, "00001_points_3d.npy")
|
|
609
|
+
save_output(np.zeros((3, 4, 5), dtype=np.float32), path, "npy")
|
|
610
|
+
writer.save_index()
|
|
611
|
+
|
|
612
|
+
index = _read_output_metadata(Path(config.output_base_path) / "points_3d")
|
|
613
|
+
assert index["type"] == "points_3d"
|
|
614
|
+
assert index["euler_train"]["modality_type"] == "points_3d"
|
|
615
|
+
assert index["euler_loading"]["loader"] == "generic"
|
|
616
|
+
assert index["euler_loading"]["function"] == "points_3d"
|
|
617
|
+
|
|
532
618
|
|
|
533
619
|
# ---------------------------------------------------------------------------
|
|
534
620
|
# Zip writer end-to-end
|
|
@@ -1083,3 +1169,71 @@ class TestRunInferenceWriterBackedOutputs:
|
|
|
1083
1169
|
np.full((6, 8), 2.5, dtype=np.float32),
|
|
1084
1170
|
)
|
|
1085
1171
|
assert (output_root / ".ds_crawler" / "output.json").exists()
|
|
1172
|
+
|
|
1173
|
+
def test_unmapped_points_3d_output_uses_generic_loader_metadata(
|
|
1174
|
+
self,
|
|
1175
|
+
tmp_path: Path,
|
|
1176
|
+
):
|
|
1177
|
+
dataset_root, _expected_images = _make_indexed_rgb_dataset(tmp_path)
|
|
1178
|
+
model_py = tmp_path / "points_model.py"
|
|
1179
|
+
model_py.write_text(
|
|
1180
|
+
"import numpy as np\n\n"
|
|
1181
|
+
"class Model:\n"
|
|
1182
|
+
" def __init__(self, config, device=None):\n"
|
|
1183
|
+
" pass\n\n"
|
|
1184
|
+
" def predict(self, inputs):\n"
|
|
1185
|
+
" height, width = inputs['rgb'].shape[-2:]\n"
|
|
1186
|
+
" points = np.stack([\n"
|
|
1187
|
+
" np.full((height, width), 1.0),\n"
|
|
1188
|
+
" np.full((height, width), 2.0),\n"
|
|
1189
|
+
" np.full((height, width), 3.0),\n"
|
|
1190
|
+
" ])\n"
|
|
1191
|
+
" return {'points_3d': points}\n"
|
|
1192
|
+
)
|
|
1193
|
+
|
|
1194
|
+
config = InferenceConfig(
|
|
1195
|
+
external_model=ExternalModelConfig(model_path=str(model_py)),
|
|
1196
|
+
dataset=DatasetConfig(modalities={"rgb": str(dataset_root)}),
|
|
1197
|
+
output_base_path=str(tmp_path / "predictions"),
|
|
1198
|
+
outputs=[OutputConfig(key="points_3d", type="npy")],
|
|
1199
|
+
strict=True,
|
|
1200
|
+
)
|
|
1201
|
+
|
|
1202
|
+
run_inference(config)
|
|
1203
|
+
|
|
1204
|
+
output_root = Path(config.output_base_path) / "points_3d"
|
|
1205
|
+
legacy_path = output_root / "Scene01" / "Camera_0" / "00001_points_3d.npy"
|
|
1206
|
+
assert legacy_path.exists()
|
|
1207
|
+
loaded = np.load(legacy_path)
|
|
1208
|
+
assert loaded.dtype == np.float32
|
|
1209
|
+
assert loaded.shape == (3, 6, 8)
|
|
1210
|
+
np.testing.assert_array_equal(loaded[:, 0, 0], np.array([1.0, 2.0, 3.0]))
|
|
1211
|
+
|
|
1212
|
+
output_index = _read_output_metadata(output_root)
|
|
1213
|
+
assert output_index["euler_train"]["modality_type"] == "points_3d"
|
|
1214
|
+
assert output_index["euler_loading"]["loader"] == "generic"
|
|
1215
|
+
assert output_index["euler_loading"]["function"] == "points_3d"
|
|
1216
|
+
|
|
1217
|
+
def test_points_3d_output_rejects_hwc_layout(self, tmp_path: Path):
|
|
1218
|
+
dataset_root, _expected_images = _make_indexed_rgb_dataset(tmp_path)
|
|
1219
|
+
model_py = tmp_path / "bad_points_model.py"
|
|
1220
|
+
model_py.write_text(
|
|
1221
|
+
"import numpy as np\n\n"
|
|
1222
|
+
"class Model:\n"
|
|
1223
|
+
" def __init__(self, config, device=None):\n"
|
|
1224
|
+
" pass\n\n"
|
|
1225
|
+
" def predict(self, inputs):\n"
|
|
1226
|
+
" height, width = inputs['rgb'].shape[-2:]\n"
|
|
1227
|
+
" return {'points_3d': np.zeros((height, width, 3), dtype=np.float32)}\n"
|
|
1228
|
+
)
|
|
1229
|
+
|
|
1230
|
+
config = InferenceConfig(
|
|
1231
|
+
external_model=ExternalModelConfig(model_path=str(model_py)),
|
|
1232
|
+
dataset=DatasetConfig(modalities={"rgb": str(dataset_root)}),
|
|
1233
|
+
output_base_path=str(tmp_path / "predictions"),
|
|
1234
|
+
outputs=[OutputConfig(key="points_3d", type="npy")],
|
|
1235
|
+
strict=True,
|
|
1236
|
+
)
|
|
1237
|
+
|
|
1238
|
+
with pytest.raises(ValueError, match="points_3d output must have shape"):
|
|
1239
|
+
run_inference(config)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{euler_inference-2.3.0 → euler_inference-2.5.0}/euler_inference.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|