Open ImaGonEs opened 1 year ago
Hey. Thanks for letting us know. I think it's just an issue with the config file. When we moved to omegaconf, we decided to allow the user to have more control of the settings. You should set all backbone kwargs like below (it should also fix your issue):
backbone:
name: "swin_tiny"
kwargs:
window_size: 4
For reference, this is how we access the kwargs for the backbone: https://github.com/vturrisi/solo-learn/blob/1aeb6e97508b6e16fc75a903315904d0f4985cbe/solo/methods/base.py#L183 And this is the swin backbone constructor: https://github.com/vturrisi/solo-learn/blob/1aeb6e97508b6e16fc75a903315904d0f4985cbe/solo/backbones/swin/swin.py#L27-L37
Let me know if this fixes your issue and I'll also update the config files :)
Hi!
Thanks for your fast response. I've just tried what you mention but, even if that solves the previous error, it raises a new one:
RuntimeError: shape '[1, 3, 4, 3, 4, 1]' is invalid for input of size 196
Hmm, can you link the full error? I'll try to check it later.
Sure!
The configuration file is:
defaults:
- _self_
- augmentations: asymmetric.yaml
- wandb: private.yaml
- override hydra/hydra_logging: disabled
- override hydra/job_logging: disabled
# disable hydra outputs
hydra:
output_subdir: null
run:
dir: .
name: "nnclr-cifar100" # change here for cifar100
method: "nnclr"
backbone:
name: "swin_tiny"
kwargs:
window_size: 4
method_kwargs:
temperature: 0.2
proj_hidden_dim: 2048
pred_hidden_dim: 4096
proj_output_dim: 256
queue_size: 98304
data:
dataset: cifar100 # change here for cifar100
train_path: "./datasets"
val_path: "./datasets"
format: "image_folder"
num_workers: 4
optimizer:
name: "lars"
batch_size: 256
lr: 0.4
classifier_lr: 0.1
weight_decay: 1e-5
kwargs:
clip_lr: True
eta: 0.02
exclude_bias_n_norm: True
scheduler:
name: "warmup_cosine"
checkpoint:
enabled: True
dir: "trained_models"
frequency: 1
auto_resume:
enabled: False
# overwrite PL stuff
max_epochs: 1000
devices: [0]
sync_batchnorm: True
accelerator: "gpu"
strategy: "ddp"
precision: 16
And the error is:
File "/media/HDD_4TB/ima/work_dir/py/main_pretrain.py", line 75, in main
model = METHODS[cfg.method](cfg)
File "/media/HDD_4TB/ima/envs/neo_ssl/solo-learn/solo/methods/nnclr.py", line 43, in __init__
super().__init__(cfg)
File "/media/HDD_4TB/ima/envs/neo_ssl/solo-learn/solo/methods/base.py", line 192, in __init__
self.backbone: nn.Module = self.base_model(method, **kwargs)
File "/media/HDD_4TB/ima/envs/neo_ssl/solo-learn/solo/backbones/swin/__init__.py", line 27, in swin_tiny
return default_swin_tiny(*args, **kwargs)
File "/media/HDD_4TB/ima/envs/neo_ssl/solo-learn/solo/backbones/swin/swin.py", line 40, in swin_tiny
return _create_swin_transformer("swin_tiny_patch4_window7_224", **model_kwargs)
File "/media/HDD_4TB/ima/envs/neo_ssl/lib/python3.9/site-packages/timm/models/swin_transformer.py", line 574, in _create_swin_transformer
model = build_model_with_cfg(
File "/media/HDD_4TB/ima/envs/neo_ssl/lib/python3.9/site-packages/timm/models/helpers.py", line 537, in build_model_with_cfg
model = model_cls(**kwargs) if model_cfg is None else model_cls(cfg=model_cfg, **kwargs)
File "/media/HDD_4TB/ima/envs/neo_ssl/lib/python3.9/site-packages/timm/models/swin_transformer.py", line 486, in __init__
layers += [BasicLayer(
File "/media/HDD_4TB/ima/envs/neo_ssl/lib/python3.9/site-packages/timm/models/swin_transformer.py", line 402, in __init__
self.blocks = nn.Sequential(*[
File "/media/HDD_4TB/ima/envs/neo_ssl/lib/python3.9/site-packages/timm/models/swin_transformer.py", line 403, in <listcomp>
SwinTransformerBlock(
File "/media/HDD_4TB/ima/envs/neo_ssl/lib/python3.9/site-packages/timm/models/swin_transformer.py", line 281, in __init__
mask_windows = window_partition(img_mask, self.window_size) # num_win, window_size, window_size, 1
File "/media/HDD_4TB/ima/envs/neo_ssl/lib/python3.9/site-packages/timm/models/swin_transformer.py", line 111, in window_partition
x = x.view(B, H // window_size, window_size, W // window_size, window_size, C)
RuntimeError: shape '[1, 3, 4, 3, 4, 1]' is invalid for input of size 196
Thanks in advance for the help!
Hey. Sorry but I didn't have time to check it yet. I'll try to do it next week.
Problem When I try to run CIFAR datasets with Swin-Tiny Backbone, it return the error: "AssertionError: Input image height (32) doesn't match model (224)."
Reproducibility I'm using the following configuration file:
Version used I'm running the
92ec35f54a507fb5d4edc1dc5723abc022b39eb3
version of the library and this is my environment:Additional comments I think that on older versions of the library (before the omegaconf update) I could run the Swin Backbone without problems. Also, I believe that, at first, there was a line that changed the window size from 7 to 4 in the case of CIFAR dataset but I can't find it anymore.