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

UNet inchannels != 3 not working #243

Open
nickkeepfer opened this issue Jun 6, 2023 · 3 comments
Open

UNet inchannels != 3 not working #243

nickkeepfer opened this issue Jun 6, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@nickkeepfer
Copy link

It seems the UNet implementation only works with inputs with channel-size 3

Status `/private/var/folders/98/8xz00xq10hq7kdrdvdjd1jy00000gn/T/jl_EZ324U/Project.toml`
  [dbeba491] Metalhead v0.8.0
  [44cfe95a] Pkg v1.8.0
using Metalhead
UNet((128,128),1,3,Metalhead.backbone(DenseNet(121)))

ERROR: DimensionMismatch: layer Conv((7, 7), 3 => 64, pad=3, stride=2, bias=false) expects size(input, 3) == 3, but got 128×128×1×1 Array{Flux.NilNumber.Nil, 4}

@theabhirath
Copy link
Member

theabhirath commented Jun 7, 2023

Hi @nickkeepfer, as I understand it, the way U-Net is being constructed right now requires you to specify inchannels at two places - one for the function itself and another for the backbone. So

UNet((128,128),1,3,Metalhead.backbone(DenseNet(121; inchannels = 1)))

should hopefully yield the model that you want. Do let me know if this works the way you expect it to. If it does, there can be a discussion around reducing this redundancy.

@nickkeepfer
Copy link
Author

Yep, that's exactly what I needed, thanks! From a new user's perspective, it would be better if the inchannels from UNet was automatically propagated to the backbone, rather than having to specify it twice. Or at least making this clear in the docs with an example that you do need to specify it twice

@theabhirath theabhirath added the bug Something isn't working label Jun 8, 2023
@theabhirath
Copy link
Member

Yeah, it's definitely weird to keep it this way, I will try and land a PR soon to address this.

vinayakjeet added a commit to vinayakjeet/Metalhead.jl that referenced this issue Mar 22, 2024
Fix UNet implementation to support input  with channel sizes other than 3
vinayakjeet added a commit to vinayakjeet/Metalhead.jl that referenced this issue Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants