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

Error when training a supervised linear classifier on EuroSAT from a pre-trained SeCo model #17

Open
chandlerbing65nm opened this issue Dec 21, 2022 · 1 comment

Comments

@chandlerbing65nm
Copy link

I encountered error when running this script:
python main_eurosat.py --data_dir data/eurosat --backbone_type pretrain --ckpt_path checkpoints/seco_resnet50_100k.ckpt

Traceback (most recent call last):
  File "main_eurosat.py", line 89, in <module>
    trainer.fit(model, datamodule=datamodule)
  File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 510, in fit
    results = self.accelerator_backend.train()
  File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/pytorch_lightning/accelerators/accelerator.py", line 57, in train
    return self.train_or_test()
  File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/pytorch_lightning/accelerators/accelerator.py", line 74, in train_or_test
    results = self.trainer.train()
  File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 532, in train
    self.run_sanity_check(self.get_model())
  File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 731, in run_sanity_check
    _, eval_results = self.run_evaluation(max_batches=self.num_sanity_val_batches)
  File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 643, in run_evaluation
    output = self.evaluation_loop.evaluation_step(batch, batch_idx, dataloader_idx)
  File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/pytorch_lightning/trainer/evaluation_loop.py", line 171, in evaluation_step
    output = self.trainer.accelerator_backend.validation_step(args)
  File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/pytorch_lightning/accelerators/gpu_accelerator.py", line 73, in validation_step
    return self._step(self.trainer.model.validation_step, args)
  File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/pytorch_lightning/accelerators/gpu_accelerator.py", line 65, in _step
    output = model_step(*args)
  File "main_eurosat.py", line 39, in validation_step
    loss, acc = self.shared_step(batch)
  File "main_eurosat.py", line 46, in shared_step
    logits = self(x)
  File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "main_eurosat.py", line 29, in forward
    logits = self.classifier(feats)
  File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/torch/nn/modules/linear.py", line 93, in forward
    return F.linear(input, self.weight, self.bias)
  File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/torch/nn/functional.py", line 1690, in linear
    ret = torch.addmm(bias, input, weight.t())
RuntimeError: mat1 dim 1 must match mat2 dim 0
@xavibou
Copy link

xavibou commented Feb 7, 2023

Hi,
I encountered the same issue, which comes from the model initialisation in main_eurosat.py. It is hard-coded for in_features=512, corresponding to the dimension of the feature vector provided by a pre-trained resnet18 encoder. In the case of resnet50, this output vector is of dimension 2048. Hence, you can modify the line 83 from:

model = Classifier(backbone, in_features=512, num_classes=datamodule.num_classes)

to

model = Classifier(backbone, in_features=2048, num_classes=datamodule.num_classes)

Hope it helps.
Xavi

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