Duplicating greyscale channel with ImageClassifierData.from_csv()

Hi, I have some greyscale SAR satellite images to classify. I think that to train on a 3 channel network I should duplicate the single channel across all three. I’m wondering if it’s possible to use the following convenient import method from notebook examples for this task or if I’ll need to modify something myself:

def get_data(sz,bs=32):    
    tfms = tfms_from_model(resnet32, sz, aug_tfms=transforms_top_down, max_zoom=1.05)
    return ImageClassifierData.from_csv(PATH, 'train', label_csv, tfms=tfms,
                    suffix='.png', val_idxs=val_idxs, bs=bs, num_workers=20)
data = get_data(120)

I tried using this and by default the three channels have different values at the same locations.

It’s hard to tell from your post if you created new images with the grayscale channel duplicated and are now wondering why when you use the above code you are getting different values for the 3 channels when loaded, but if that is you’re question then I believe the answer is because the tfms_from_model calls tfms_from_stats which for resnet uses the below imagenet stats when normalizing the image data and since the stats are different for each channel, you will get different values for each channel even though the input channels are the same.

imagenet_stats = A([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
...
tfm_norm = Normalize(*stats, tfm_y=tfm_y if norm_y else TfmType.NO) if stats is not None else None
1 Like

Sorry for being vague, I actually tried both using the single channel directly as well as duplicating the channel. Thanks for the explanation as to why this is occurring! Do you happen to know if there’s any drawback to this normalization implementation when attempting to train on greyscale images?

Sorry, I do not know.