partition_dataset with ratios leaves some items out of every partition
Los mantenedores suelen responder en 3 días
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Área
- data, machine-learning
Línea de trabajo
Empieza en monai/data/utils.py, en partition_dataset y su cálculo de tamaños basado en proporciones alrededor de las líneas enlazadas; revisa también la ruta relacionada partition_dataset_classes. Reproduce el caso reportado de elementos faltantes y luego ejecuta o añade pruebas específicas para las divisiones por proporciones y las divisiones por clases. El objetivo se cumple cuando cada elemento de entrada aparece exactamente en una partición, incluso si, de otro modo, los tamaños redondeados dejarían elementos fuera.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
The text below was written with AI assistance (Claude and GPT-6 Astra).
partition_dataset(data, ratios=...) rounds each partition size on its own (https://github.com/Project-MONAI/MONAI/blob/6920610c310200d683a3b00987a05893ccf1ca5f/monai/data/utils.py#L1217-L1224). When the rounded sizes add up to less than len(data), the remaining items are not in any partition, and nothing reports it. With three ratios this happens for about one length in five (0.8/0.1/0.1: 200 of the lengths 1 to 1000; 1/1/1: 334), and with five equal ratios up to two items are lost. partition_dataset_classes splits each class with the same function, so it can lose one item per class. Two-way splits are not affected.
I found this by reading and testing the code.
To Reproduce
from monai.data import partition_dataset
print(partition_dataset(list(range(10)), ratios=[1, 1, 1]))
data = list(range(63)) # e.g. the 63 training cases of MSD Task06_Lung
train, val, test = partition_dataset(data, ratios=[0.8, 0.1, 0.1], shuffle=True, seed=0)
print(len(train), len(val), len(test), "in no split:", sorted(set(data) - set(train + val + test)))
Output on dev (6920610):
[[0, 1, 2], [3, 4, 5], [6, 7, 8]]
50 6 6 in no split: [44]
The same happens for other Decathlon training-set sizes, e.g. 303 (Task08_HepaticVessel) and 484 (Task01_BrainTumour) with 0.8/0.1/0.1, 63 and 303 with 0.7/0.15/0.15, and 32 (Task05_Prostate) with five equal ratios, which loses two cases. In a Decathlon-style pipeline (load_decathlon_datalist -> partition_dataset -> CacheDataset -> DataLoader) with 63 cases, one case is never loaded by the train, validation or test split.
Expected behavior
Every item should be in exactly one partition, as in the docstring example ([0.6, 0.2, 0.2] on 5 items gives [[1, 2, 3], [4], [5]]). drop_last is documented as not applying to the ratio path.
Environment
MONAI 1.6.1rc0+50.g6920610c (dev), PyTorch 2.14.1+cpu, NumPy 2.5.4, Python 3.12.13, Linux.
Additional context
I have a small fix that gives the leftover items to the partitions whose sizes were rounded down the most and leaves every split that already covers all items unchanged, plus tests, and can open a PR.
I made this report and directed the investigation, with AI assistance from Claude and GPT-6 Astra.
- Lenguaje dominante
- Python
- Estrellas
- 8.8k
- Forks
- 1.7k
- Merge medio
- 5 d 3 h
- PR fusionados (30 d)
- 13
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Project-MONAI/MONAI
-
partition_datasetAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Project-MONAI/MONAI#9220 ·
Los mantenedores suelen responder en 3 días
-
FocalLoss mean reduction is multiplied by the number of channels when ignore_index is setPosiblemente ocupada @mottopanikeiku la tomó hace 3 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Project-MONAI/MONAI#9214 ·
Los mantenedores suelen responder en 3 días
-
DiNTS: missing graph-break regression test (follow-up to #9145)Posiblemente ocupada @nilapate la tomó hace 17 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Project-MONAI/MONAI#9159 ·
Los mantenedores suelen responder en 3 días
-
ProbMapProducer raises IndexError on numpy 2.x: SlidingPatchWSIDataset emits float locationsPosiblemente ocupada @nilapate la tomó hace 28 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Project-MONAI/MONAI#9135 · 1 comentario ·
Los mantenedores suelen responder en 3 días
-
RandGridPatch crashes for documented 0 or None patch_size entriesPosiblemente ocupada @Rajioba1 la tomó hace 84 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Project-MONAI/MONAI#9046 ·
Los mantenedores suelen responder en 3 días
Todos los issues de Project-MONAI/MONAI
Issues similares
-
link-rot
Dificultad 1/5 Menos de una hora Aptitud para principiantes 67/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
developmentseed/titiler-cmr#265 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Insecure Brotli version <1.2.1Posiblemente ocupada @jamescw19 la tomó hoy. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
stac-utils/stac-fastapi-pgstac#438 · 1 reacción ·
-
bug triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día