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

Unable to train on small patches (64x48) #4

Open
bc-bytes opened this issue Jun 5, 2023 · 3 comments
Open

Unable to train on small patches (64x48) #4

bc-bytes opened this issue Jun 5, 2023 · 3 comments

Comments

@bc-bytes
Copy link

bc-bytes commented Jun 5, 2023

I am trying to train using the efficientnet_b0 backbone using an image size of 64x48, but get the following error:

  File "/home/seg/bbunet/train.py", line 85, in <module>
    trainer.fit(train_loader, val_loader)
  File "/home/seg/bbunet/backbones_unet/utils/trainer.py", line 82, in fit
    self._train_one_epoch(train_loader, epoch)
  File "/home/seg/bbunet/backbones_unet/utils/trainer.py", line 111, in _train_one_epoch
    preds = self.model(images)
  File "/home/miniconda3/envs/pt/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/seg/bbunet/backbones_unet/model/unet.py", line 174, in forward
    x = self.decoder(x)
  File "/home/miniconda3/envs/pt/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/seg/bbunet/backbones_unet/model/unet.py", line 334, in forward
    x = b(x, skip)
  File "/home/miniconda3/envs/pt/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/seg/bbunet/backbones_unet/model/unet.py", line 276, in forward
    x = torch.cat([x, skip], dim=1)
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 4 but got size 3 for tensor number 1 in the list.

I tried with and without pretrained model but got the same error each time.

@mberkay0
Copy link
Owner

mberkay0 commented Jun 11, 2023

Greetings @bc-bytes, you have passed the pretty low image size (64x48) for the encoder. Please consider experimenting with input dimensions of 224x224 or 256x256. Additionally, make sure that your data format follows the structure of [batch_size, channel, height, width].

@bc-bytes
Copy link
Author

I need to train the models using patches of full images, which are 64 x 48 pixels.

@mberkay0
Copy link
Owner

Sorry! To meet the desired dimensions, you will need to change the architecture of the network. A size of 64x48 is small. Developing a segmentation model with this size may require designing a simple convolutional neural network with fewer layers. You may need to base it on UNet but with significantly smaller layers. You will need to create your UNet model for this task.

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