ShiftIntensity(safe=True) still wraps uint8 values when `offset` is an int
メンテナーはふだん 3 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 84/100
調査の方向性
monai/transforms/intensity/array.py の ShiftIntensity.__call__ と tests/transforms/test_shift_intensity*.py のテストを読んでください。報告された uint8 のケースを、整数と浮動小数点数のオフセットで再現してください。そのうえで、既存のテストを使って簡単にできる場合は、safe=True と関連する Random または Dictionary 変換のテストも追加してください。整数オフセットで期待される範囲内の値が得られ、テストが通れば完了です。
索引モデルが issue の本文から書いたものです。
説明
[Describe the bug
safe=True in ShiftIntensity (added for #5621) clamps overflow for float offsets but not for int offsets. With a uint8 image and an int offset, img + offset stays uint8, so values wrap during the addition, before convert_data_type(..., safe=True) runs (monai/transforms/intensity/array.py, ShiftIntensity.__call__). The safe check then has nothing to clamp. This also affects RandShiftIntensity and the dictionary versions, which use ShiftIntensity.
To Reproduce
import torch
from monai.transforms import ShiftIntensity
img = torch.tensor([0, 100, 255], dtype=torch.uint8)
print(ShiftIntensity(offset=1.0, safe=True)(img)) # [1, 101, 255] clamped, as documented
print(ShiftIntensity(offset=1, safe=True)(img)) # [1, 101, 0] wraps despite safe=True
print(ShiftIntensity(offset=-1, safe=True)(img)) # [255, 99, 254] wraps despite safe=True
Expected behavior
With safe=True, an int offset should give the same result as the equivalent float offset: [1, 101, 255] and [0, 99, 254]
Screenshots
If applicable, add screenshots to help explain your problem.
Environment
MONAI 1.6.1rc0+65.gc5bddb21 (dev @ c5bddb21), PyTorch 2.15.0, NumPy 2.4.6, Python 3.11.5, macOS arm64.
Additional context
One possible fix is to compute the shift in a wider dtype (e.g. cast offset to float, or promote img) before the safe conversion. As far as I can tell there's no test covering safe in tests/transforms/test_shift_intensity*.py. I'm happy to open a PR with a fix and a test if this is considered a bug.
Investigation and draft assisted by Claude (AI); I reproduced and verified the behavior myself.
- 主要言語
- Python
- スター
- 8.8k
- フォーク
- 1.7k
- 平均マージ
- 6日 1時間
- マージ済み PR(30日)
- 15
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Project-MONAI/MONAI のほかの issue
-
Small-integer inputs produce incorrect regression metric values or runtime errors対応中かも @leecoring が 4 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
Project-MONAI/MONAI#9246 ·
メンテナーはふだん 3 日以内に返信
-
partition_dataset対応中かも @rtmalikian が 9 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Project-MONAI/MONAI#9220 ·
メンテナーはふだん 3 日以内に返信
-
partition_dataset with ratios leaves some items out of every partition対応中かも @mottopanikeiku が 14 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Project-MONAI/MONAI#9216 ·
メンテナーはふだん 3 日以内に返信
-
FocalLoss mean reduction is multiplied by the number of channels when ignore_index is set対応中かも @mottopanikeiku が 14 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
Project-MONAI/MONAI#9214 ·
メンテナーはふだん 3 日以内に返信
-
DiNTS: missing graph-break regression test (follow-up to #9145)対応中かも @nilapate が 28 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
Project-MONAI/MONAI#9159 ·
メンテナーはふだん 3 日以内に返信
Project-MONAI/MONAI の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
didi/helixharness#18 ·
-
request-theme
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
LizardByte/ThemerrDB#9883 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
NousResearch/hermes-agent#149885 ·
メンテナーはふだん 1 日以内に返信
-
Set cache_ok = True on GUID TypeDecorator to enable SQLAlchemy query caching対応中かも @patelshivani2283-lab が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 91/100
fedora-infra/anitya#2157 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
mllam/neural-lam#860 ·
メンテナーはふだん 2 日以内に返信