usuyama / pytorch-unet

Simple PyTorch implementations of U-Net/FullyConvNet (FCN) for image segmentation
https://colab.research.google.com/github/usuyama/pytorch-unet/blob/master/pytorch_unet_resnet18_colab.ipynb
MIT License
827 stars 233 forks source link

Grayscale Images #15

Closed ayaanzhaque closed 4 years ago

ayaanzhaque commented 4 years ago

Hi, How do I change the model to input grayscale images instead of 3 channel images? Thanks

usuyama commented 4 years ago

@ayaanzhaque

One way is to convert your grayscale images to 3 channels (just repeat 3 times). e.g. https://stackoverflow.com/questions/50243709/how-to-convert-a-1-channel-image-into-a-3-channel-with-pil

Another way is to change the input shape of the model or add one layer to take 1 channel input.

ayaanzhaque commented 4 years ago

Ok thanks, I figured it out! I just changed conv1 of the Resnet to single channeled.