Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwinUnet deprecation error and when correct TypeError over img_size #8300

Open
joaomamede opened this issue Jan 14, 2025 · 3 comments
Open

Comments

@joaomamede
Copy link

joaomamede commented Jan 14, 2025

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

@KumoLiu
Copy link
Contributor

KumoLiu commented Jan 17, 2025

Hi @joaomamede, may I ask how did you install the monai?

@joaomamede
Copy link
Author

Hi @joaomamede, may I ask how did you install the monai?

Good question I think I did pip install. It was a while back.

If I remove the deprecation type error in the code the swin runs.

@KumoLiu
Copy link
Contributor

KumoLiu commented Jan 17, 2025

Good question I think I did pip install. It was a while back.

If I remove the deprecation type error in the code the swin runs.

Hi @joaomamede, yes. I know it's a bit of a mismatch, because we want to tell the user something through the deprecate message, but because the img_size doesn't have a default value, if we add a default value for it and change the position of the parameter, it may cause some users get error who specifying the parameters in order. Theoretically, if your monai version doesn't start with 1.5, there won't be a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants