I try use different channel image to train a unet model with models.resnet34(fastai v1). But normalize(imagenet_stats)) function will convert gray image to 3channel image, and the RGBA image will error with normalize(imagenet_stats)), So what should i do to train a unet with different channels image?
You can call .normalize() without imagenet_stats, and it will grab a batch and compute the stats. This is because your 4-channel imaging will have stats of nested shape ((4,), (4,)) while imagenet_stats has shape ((3,), (3,))
Alternatively you might want to grab a batch and save the stats explicitly, which can be done like
Yep as @Pomo mentioned, you can use unet_learner(n_in=4) to set it. If you’re not using a pretrained resnet34, it might be nice to use the Fastai xresnet34 (which also has a way to specify number of input channels via the c_in parameter)
@jwuphysics@Pomo Thank you very much! I think the matter is that my fastai version is too old(1.0.59), and it does not have n_in or c_in parameter. I will try new version, Thanks again!