Project-MONAI / Project-MONAI/MONAI

SwinUnet deprecation error and when correct TypeError over img_size

Open
#8,300 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
8.7k
Forks
1.6k
Avg merge
5d 1h
Merged PRs (30d)
20

Description

Describe the bug
Img_size argument is required, but not allowed at the same time

To Reproduce
print_config()

MONAI version: 1.5.dev2450
Numpy version: 1.26.4
Pytorch version: 2.5.1
MONAI flags: HAS_EXT = False, USE_COMPILED = False,

device = torch.device("cuda:0")
model = SwinUNETR(
    img_size=(512,512,64),#this is not an argument anymore
    spatial_dims=3,
    in_channels=2,
    out_channels=3,
    feature_size=48,
    drop_rate=0.0,
    attn_drop_rate=0.0,
    dropout_path_rate=0.0,
    use_checkpoint=True
    
).to(device)

DeprecatedError: Argument img_size was removed in version 1.5. The img_size argument is not required anymore and checks on the input size are run during forward().

But

model = SwinUNETR(
    # img_size=(512,512,64),#this is not an argument anymore
    spatial_dims=3,
    in_channels=2,
    out_channels=3,
    feature_size=48,
    drop_rate=0.0,
    attn_drop_rate=0.0,
    dropout_path_rate=0.0,
    use_checkpoint=True
    
).to(device)

TypeError: missing a required argument: 'img_size'

Expected behavior
Img_size is no longer needed but we have type error when not present and DeprecationError when present.

Environment

anaconda linux ubuntu 24.04

python -c "import monai; monai.config.print_debug_info()"

================================
Printing MONAI config...

MONAI version: 1.5.dev2450
Numpy version: 1.26.4
Pytorch version: 2.5.1
MONAI flags: HAS_EXT = False, USE_COMPILED = False, USE_META_DICT = False
MONAI rev id: 0726cee7ba6c1b31f34d54fc26fe6b8db5f5c79c
MONAI file: /home//anaconda3/envs/monai/lib/python3.9/site-packages/monai/init.py

Optional dependencies:
Pytorch Ignite version: 0.4.11
ITK version: 5.4.0
Nibabel version: 5.3.2
scikit-image version: 0.22.0
scipy version: 1.13.1
Pillow version: 11.0.0
Tensorboard version: 2.18.0
gdown version: 5.2.0
TorchVision version: 0.20.1
tqdm version: 4.67.1
lmdb version: 1.5.1
psutil version: 6.1.0
pandas version: 2.2.3
einops version: 0.8.0
transformers version: 4.40.2
mlflow version: 2.19.0
pynrrd version: 1.1.1
clearml version: 1.17.0rc0

For details about installing the optional dependencies, please visit:
https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies

================================
Printing system config...

System: Linux
Linux version: Ubuntu 24.04.1 LTS
Platform: Linux-6.8.0-51-generic-x86_64-with-glibc2.39
Processor: x86_64
Machine: x86_64
Python version: 3.9.21
Process name: python
Command: ['/home/jmamede/anaconda3/envs/monai/bin/python', '-m', 'ipykernel_launcher', '--f=/home/jmamede/.local/share/jupyter/runtime/kernel-v3a91b9ef6ea6c88b8a84ed6c43240878d988e2a4a.json']
Open files: [popenfile(path='/home/jmamede/.config/Code/logs/20250112T171623/window1/exthost/exthost.log', fd=43, position=5315, mode='a', flags=33793), popenfile(path='/home/jmamede/.config/Code/logs/20250112T171623/window1/exthost/extensionTelemetry.log', fd=44, position=490, mode='a', flags=33793), popenfile(path='/home/jmamede/.config/Code/logs/20250112T171623/window1/exthost/vscode.github/GitHub.log', fd=45, position=219, mode='a', flags=33793), popenfile(path='/home/jmamede/.config/Code/logs/20250112T171623/window1/exthost/vscode.github-authentication/GitHub Authentication.log', fd=46, position=723, mode='a', flags=33793), popenfile(path='/home/jmamede/.config/Code/logs/20250112T171623/window1/exthost/vscode.git/Git.log', fd=49, position=876031, mode='a', flags=33793), popenfile(path='/home/jmamede/.config/Code/logs/20250112T171623/window1/exthost/output_logging_20250112T171631/1-Jupyter.log', fd=50, position=503828, mode='a', flags=33793), popenfile(path='/home/jmamede/.config/Code/logs/20250112T171623/window1/exthost/ms-python.debugpy/Python Debugger.log', fd=52, position=0, mode='a', flags=33793), popenfile(path='/home/jmamede/.ipython/profile_default/history.sqlite', fd=53, position=0, mode='r+', flags=688130), popenfile(path='/home/jmamede/.ipython/profile_default/history.sqlite', fd=54, position=0, mode='r+', flags=688130), popenfile(path='/home/jmamede/.config/Code/logs/20250112T171623/window1/exthost/output_logging_20250112T171631/2-Jupyter Server Console.log', fd=62, position=0, mode='a', flags=33793), popenfile(path='/home/jmamede/.config/Code/logs/20250112T171623/window1/exthost/output_logging_20250112T171631/3-Python Test Log.log', fd=64, position=0, mode='a', flags=33793), popenfile(path='/home/jmamede/.config/Code/logs/20250112T171623/window1/exthost/ms-python.python/Python Language Server.log', fd=70, position=14458, mode='a', flags=33793), popenfile(path='/home/jmamede/.config/Code/logs/20250112T171623/window1/exthost/ms-python.python/Python.log', fd=81, position=28422, mode='a', flags=33793), popenfile(path='/home/jmamede/.config/Code/logs/20250112T171623/window1/exthost/output_logging_20250112T171631/4-Tensorboard.log', fd=93, position=5868, mode='a', flags=33793), popenfile(path='/home/jmamede/.config/Code/logs/20250112T171623/window1/exthost/ms-python.python/Python Locator.log', fd=95, position=38210, mode='a', flags=33793), popenfile(path='/usr/share/code/v8_context_snapshot.bin', fd=103, position=0, mode='r', flags=32768), popenfile(path='/home/jmamede/.config/Code/logs/20250112T171623/window1/exthost/vscode.json-language-features/JSON Language Server.log', fd=114, position=0, mode='a', flags=33793)]
Num physical CPUs: 24
Num logical CPUs: 48
Num usable CPUs: 48
CPU usage (%): [2.8, 3.0, 3.0, 5.0, 3.5, 4.3, 3.6, 3.5, 3.1, 3.3, 3.5, 3.1, 3.2, 2.7, 4.5, 4.3, 3.5, 3.7, 4.9, 3.5, 3.1, 3.5, 3.1, 2.9, 3.6, 2.9, 2.9, 6.4, 3.0, 5.5, 3.1, 4.3, 3.1, 3.5, 3.2, 3.3, 3.1, 2.6, 3.6, 3.4, 3.8, 6.9, 3.7, 3.5, 3.3, 2.8, 3.0, 3.8]
CPU freq. (MHz): 2279
Load avg. in last 1, 5, 15 mins (%): [4.7, 5.3, 7.3]
Disk usage (%): 78.8
Avg. sensor temp. (Celsius): UNKNOWN for given OS
Total physical memory (GB): 125.6
Available memory (GB): 7.5
Used memory (GB): 115.7

================================
Printing GPU config...

Num GPUs: 1
Has CUDA: True
CUDA version: 12.4
cuDNN enabled: True
NVIDIA_TF32_OVERRIDE: None
TORCH_ALLOW_TF32_CUBLAS_OVERRIDE: None
cuDNN version: 90100
Current device: 0
Library compiled for CUDA architectures: ['sm_50', 'sm_60', 'sm_61', 'sm_70', 'sm_75', 'sm_80', 'sm_86', 'sm_90']
GPU 0 Name: NVIDIA RTX A4000
GPU 0 Is integrated: False
GPU 0 Is multi GPU board: False
GPU 0 Multi processor count: 48
GPU 0 Total memory (GB): 15.7
GPU 0 CUDA capability (maj.min): 8.6

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the SwinUNETR constructor and reproduce both calls from the issue: one with img_size and one without it. Check the constructor's required arguments and deprecation handling, then add coverage showing that the supported call no longer raises either error; done means the reported initialization path works consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.