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

Channel mismatch error when converting the code to do multi-class segmentation. #24

Closed
srivastavashobhit opened this issue Aug 6, 2022 · 4 comments

Comments

@srivastavashobhit
Copy link

srivastavashobhit commented Aug 6, 2022

I have made changes to your code to do multiclass segmentation. I have taken care that labels are read right. I have already done this job successfully for your last masterpiece, U2NET. In ISNET, I am getting this error when giving a four-channel multiclass label.

RuntimeError: Given groups=1, weight of size [16, 1, 3, 3], expected input[1, 4, 256, 256] to have 1 channels, but got 4 channels instead

I faced the same error in U2Net, but then this code fix at line 354 and line 459 in https://github.com/xuebinqin/U-2-Net/blob/master/model/u2net.py solved it -

   -  self.outconv = nn.Conv2d(6,out_ch,1)
   + self.outconv = nn.Conv2d(6*out_ch,out_ch,1)

Please check if ISNet needs a similar fix.

Thankful for your incredible work.

End notes
I have set out_channel to 4
I am taking care of gt_preprocess and ensuring it returns a four-channel label.

@srivastavashobhit
Copy link
Author

The issue is resolved. Error is due to not passing the correct number of out_ch in net = ISNetGTEncoder(in_ch=4, out_ch=4).

@kabbas570
Copy link

@srivastavashobhit can you please explain how you managed to make a 4-channel label? Thanks

@srivastavashobhit
Copy link
Author

@kabbas570
In my case, I was first incorrectly not passing out_ch=4 when creating an object of ISNetGTEncoder at line 38 of train_valid_inference_main.py

The default value of out_ch is 1. You can check this in the constructor of ISNetGTEncoder

Later, I also had to make changes to the data_loader_cache.py in im_preprocess and/or gt_preprocess to deal with 4 channels. I do not remember the changes now and do not have the files to refer.

@kabbas570
Copy link

@srivastavashobhit, thanks for the reply. Yes, I changed the gt_prrprocess file and the corresponding number of classes in ISNetGTEncoder,and fortunately, it working now,
Cheers
Abbas

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