Convert_mode while creating ImageDataBunch

I just realized that fastai MNIST dataset (URLs.MNIST) is RGB, where I expected grayscaled images. So, each image is (3,28,28) instead of (28,28). Is there a way of easily transforming those images? maybe during ImageDataBunch.from… where I would use something like convert_mode?

Or is there a transform that let me change the image colorspace?

Not sure if you’d seen the convert_mode argument of ImageList. You can’t pass this to ImageDataBunch (extra arguments are used to specify databunch options) so you have to use the data block API. Something like (untested):

path = untar_data(URLs.MNIST_SAMPLE)
data = (ImageList.from_folder(path, convert_mode='L')
                 .split_by_folder()
                 .label_from_folder()
                 .databunch(bs=64))

Where you can pass any arguments you passed to ImageDataBunch.from_folder() to .databunch().

2 Likes

I had not seen it. Thanks for showing me.