Datasets:
[release] v1.2.1: correct MAMA-MIA and PI-CAI to RAS+, withdraw their v1.2.0; new reproducibility and fast download scripts
dc096c2 | # Regenerating MedVision data | |
| These scripts rebuild the preprocessed images/masks and the benchmark-plan annotations for | |
| any dataset in the catalogue, from the original public sources. They are the record of how | |
| the published data was actually produced. | |
| They do **not** upload anything. Publishing to HuggingFace is a separate, deliberate step. | |
| ``` | |
| setup-env.sh install medvision_ds | |
| dataset_specs.py per-dataset recipe: download entrypoint, steps, reorientation policy | |
| build_dataset.py the driver | |
| ``` | |
| ## Quick start | |
| ```bash | |
| ./setup-env.sh /path/to/data-dir | |
| # see what would run, without running it | |
| python build_dataset.py --data_dir /path/to/data-dir --dataset KiTS23 --dry_run | |
| # build it | |
| python build_dataset.py --data_dir /path/to/data-dir --dataset KiTS23 | |
| ``` | |
| `--data_dir` is your `MedVision_DATA_DIR`; datasets are built under `<data_dir>/Datasets/`. | |
| Use `--all` for the whole catalogue, `--steps` to run a subset | |
| (`download,segmentation,detection,biometry`), and `--max_workers` for the downloads that | |
| support parallelism. | |
| - `download`: data retrieval and preprocessing | |
| - `segmentation`: generate `MaskSize` annotations | |
| - `detection`: generate bounding box annotations | |
| - `biometry`: generate tumor/lesion size or angle/distance annotations | |
| ## Two modes, and only two | |
| **Reproduce what is published** — the default, also spelled `--latest`. Each | |
| *(dataset, task)* pair (i.e., config) resolves to the newest version declared for it in | |
| `_ANNOTATION_INDEX` (in `MedVision.py`), and that value is passed down as | |
| `--annotation_version`. Config of one dataset can sit at different versions and are handled | |
| in a single run: KiTS23 emits `1.0.0` for segmentation and detection and `1.1.1` for | |
| biometry. | |
| **Publish a new annotation version** — `--new-annotation-version`, for maintainers. Bump | |
| `src/medvision_ds/__version__.py` first; the driver then passes no version and the planner | |
| stamps `__version__`. The run is refused unless that version is **strictly above** every | |
| affected pair's newest published version, so you cannot overwrite published data by | |
| forgetting to bump. | |
| There is no third mode. In particular **you cannot ask for an older version**, because the | |
| current codebase cannot produce one: the generation code changes between annotation | |
| versions — that is *why* the version is bumped. v1.1.0 changed the tumour/lesion | |
| cluster-size threshold (200px → 20px), v1.1.1 corrected the transposed in-plane spacing in | |
| the ellipse fit, v1.2.1 pinned float promotion against NEP 50. Naming an older version | |
| would emit a file with that name but with today's values. To rebuild an older version, | |
| check out the git commit with "[release]" in the commit title and install that `src/`. | |
| ## Credentials | |
| Read from the environment only. Never put a token in a file that a script reads. | |
| | Variable | Needed for | | | |
| | --- | --- | --- | | |
| | `SYNAPSE_TOKEN` | BCV15, BraTS24, FeTA24, MAMA-MIA | required; the download fails without it | | |
| | `HF_TOKEN` | SKM-TEA, ToothFairy2 | only if their HuggingFace mirror is private for you | | |
| | `MedVision_SKMTEA_HF_ID`, `MedVision_ToothFairy2_HF_ID`, `BiometricVQA_KiPA22_HF_ID` | those three | optional; override a working public default | | |
| The driver checks the required ones before running anything and names the missing variable. | |
| > **These tokens are for reproduction, not for loading.** Ordinary `load_dataset` use needs no | |
| > credentials across most of the catalogue: 21 of the 30 datasets fetch an already-preprocessed | |
| > copy, so nothing is retrieved from the gated source. BCV15, BraTS24 and MAMA-MIA are gated | |
| > upstream but ship such a copy, and therefore load without a token. | |
| > | |
| > Three datasets are the exception, because no redistributable copy exists and the loader must | |
| > build them from source at load time too: | |
| > | |
| > | Dataset | Also needed when loading | | |
| > | --- | --- | | |
| > | FeTA24 | `SYNAPSE_TOKEN` | | |
| > | SKM-TEA, ToothFairy2 | access to their HuggingFace mirror — `HF_TOKEN` only if it is private for you | | |
| ## Reorientation | |
| Ground truth is read in voxel space, so annotations must be computed against images that | |
| are already in RAS+. Two places can do that, and `dataset_specs.py` records which one each | |
| dataset uses: | |
| - **8 datasets reorient inside their own `download_raw.py`** (AFIDs, DEEP-PSMA, LIDC-IDRI, | |
| LNQ2023, MAMA-MIA, PDDCA, PI-CAI, VerSe) and are given no `--reorient2RAS`. It has to | |
| happen there because AFIDs, PDDCA and VerSe derive landmark *voxel indices* at download | |
| time, and the landmark-biometry planner cannot reorient at all. | |
| - **The rest are reoriented by the planner**, so `--reorient2RAS` is passed to every step | |
| that accepts it. Repeating it is free: the reorienter early-returns on an already-RAS | |
| file and writes nothing. | |
| Ceph-Biometrics-400 receives the flag nowhere, which is correct rather than special-cased — | |
| its only task is landmark biometry, whose planner has no such parameter, and its 2D X-rays | |
| sit on an identity affine already. | |
| `dataset_specs.py` carries the full rationale as comments. | |
| ## Tumour/lesion biometry: v1.1.0 and v1.1.1 are not reproduced here | |
| For **KiTS23, BraTS24, MSD, autoPET-III, HNTSMRG24 and KiPA22** the newest biometry | |
| annotation is `1.1.1`, and it was not produced by `preprocess_biometry.py`. Its lineage is: | |
| | version | produced by | | |
| | --- | --- | | |
| | `1.0.0` | `preprocess_biometry.py` — what this driver runs | | |
| | `1.1.0` | [`scripts/regenerate_tl_annotation_v1.1.0.py`](../regenerate_tl_annotation_v1.1.0.py) | | |
| | `1.1.1` | [`scripts/regenerate_tl_annotation_v1.1.1.py`](../regenerate_tl_annotation_v1.1.1.py) + [`scripts/align_tl_split_to_v1.0.0.py`](../align_tl_split_to_v1.0.0.py) | | |
| Those two regeneration scripts remain in `scripts/` and are described in | |
| [`doc/release-v1.1.1.md`](../../doc/release-v1.1.1.md). They are deliberately **not** wired | |
| into this driver: `align_tl_split_to_v1.0.0.py` rewrites already-published plans in place, | |
| which is the practice the annotation-identity policy exists to prevent, and it should stay | |
| a deliberate one-off rather than a routine step. | |
| ## Limitations worth knowing | |
| - **Split parameters are fixed catalogue-wide, not per-dataset choices.** Random seed `1024` | |
| and split ratio `0.7` are the default in all 72 `preprocess_*.py`, and the same two values | |
| are declared as `RAMDOM_SEED` and `SPLIT_TRAIN_RATIO` in `MedVision.py`. The 11 tumour/lesion | |
| biometry scripts likewise all default to `--shrunken_bbox_scale 0.9` and | |
| `--enlarged_bbox_scale 1.1`. The driver overrides none of them, so a rebuild inherits exactly | |
| the constants the published data was built with — this is not an assumption to be recovered. | |
| Verified end to end: regenerating PI-CAI segmentation and detection into a scratch directory | |
| reproduces the published plans byte for byte, split membership and order included. | |
| - **`--force_uint16_mask` is not passed.** Whether it was used per dataset is not | |
| recoverable; it is a mask-dtype hygiene step that does not change annotation values. | |
| - **Downloads are large.** Several datasets are tens of gigabytes. `--dry_run` first. | |
| - **Existing plan files are never overwritten** without `--force`. | |