Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

partition_dataset

オープン 初心者向け
#9,220 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python, pytorch
領域
data

調査の方向性

monai/data/utils.py の行 1217-1224 付近で partition_dataset が各パーティションのサイズを計算している丸めロジックを読み、issue 内のスニペットでバグを再現してください(例: partition_dataset(list(range(10)), ratios=[1,1,1]) が要素を落とす)。修正は、最も切り捨てられたパーティションに残余要素を分配するべきです。また、報告者は修正とテストを既に用意していると言っているため、PR が出現する可能性があるので、開始前に調整のために早急にコメントしてください。完了: 報告された ratios/lengths に対して各要素がちょうど1つのパーティションに収まり、tests for partition_dataset の既存のテストは引き続き通過し、新しいテストが残余要素のケースをカバーする。

索引モデルが issue の本文から書いたものです。

説明

When partition_dataset(data, ratios=...) splits a list, it computes every partition's size by rounding independently (see monai/data/utils.py, lines 1217–1224 at commit 6920610). If those rounded sizes add up to less than len(data), the extra items end up in no partition, and no warning or error is raised.

With three ratios this affects roughly one length in five: for 0.8/0.1/0.1 it happens for 200 of the lengths from 1 to 1000, and for 1/1/1 it happens for 334 of them. With five equal ratios, as many as two items can disappear. Because partition_dataset_classes applies the same function to each class, it can lose up to one item per class. Splits into two parts are not affected.

I found this by reading the code and then testing it.

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 thing occurs for other Decathlon training-set sizes. Examples: 303 cases (Task08_HepaticVessel) and 484 cases (Task01_BrainTumour) with 0.8/0.1/0.1; 63 and 303 cases with 0.7/0.15/0.15; and 32 cases (Task05_Prostate) with five equal ratios, where two cases are lost. 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

Each item should land in exactly one partition, as the docstring example shows ([0.6, 0.2, 0.2] on 5 items gives [[1, 2, 3], [4], [5]]). The documentation says drop_last does not apply when ratios are used.

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 ready. It hands the leftover items to the partitions that were rounded down the most, and splits that already cover every item stay unchanged. It comes with tests, and I can open a PR.

主要言語
Python
スター
8.8k
フォーク
1.7k
平均マージ
5日 3時間
マージ済み PR(30日)
13

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Project-MONAI/MONAI のほかの issue

Project-MONAI/MONAI の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。