isaaccorley / torchseg

Segmentation models with pretrained backbones. PyTorch.
MIT License
104 stars 8 forks source link

unexpected keyword argument 'output_stride' with TinyVit #41

Closed ogencoglu closed 4 months ago

ogencoglu commented 5 months ago

Trying to use Unet++ with tiny_vit_21m_512.dist_in22k_ft_in1k ( https://huggingface.co/timm/tiny_vit_21m_512.dist_in22k_ft_in1k )

returns:

TypeError: TinyVit.__init__() got an unexpected keyword argument 'output_stride'

Any tips here?

isaaccorley commented 5 months ago

Can you try passing encoder_output_stride=None when you instantiate the model? Not all timm backbones support the output stride argument.

ogencoglu commented 5 months ago

Will try and let you know. Is there a documentation showing what has been changed from https://github.com/qubvel/segmentation_models.pytorch ?

Unet++ does not have encoder_output_stride parameter if it has not been changed: https://smp.readthedocs.io/en/latest/models.html#unetplusplus

notprime commented 5 months ago

@ogencoglu we're still working on a well-written documentation, but we don't have one atm.

You just have to pass the argument encoder_output_stride when creating the Unet++ model. Now, all of our encoders are directly created using timm, so you can use timm's parameters, and output_stride is one of them (we call it encoder_output_stride to indicate we are referring to the encoder). When you create an instance of Unet++, the function get_encoder, is called to create the specified timm encoder. As you can see also there, at line 60 you find encoder_output_stride: int = 32 which is later used at line 81 output_stride=encoder_output_stride. Again output_stride is passed to get_encoder :D