Using pixel values instead of images for image classifier training

Hi everyone,
So I have just completed watch lecture 3 of part 1 of fast ai course and i tried to apply my knowledge to mnist data set but the problem that i am facing is that in imageClassifierData.from_csv i have to pass images but i have the pixel values of the images that too are stored in a variable in jupyter notebook is there any way to train my model using pixel values of an image and the lables of an image that are stored in a variable .
I have images in the form of matrix not .jpg or any other format

P.S. I am posting for the first time so please help me improve the way i ask question if you find it wrong.

1 Like

Welcome to the forums :slight_smile:

You can use ImageClassifierData.from_arrays, I think this even reshapes the images for you too. If not, perform a
x = x.reshape((len(x), 28,28)
x = np.stack(3*[x], 3)

1 Like

@sjdlloyd can you please explain what is np.stack doing

This adds the RGB axes to it, so it goes from
X.shape = (n,28,28)
To
X.shap = (n,28,28,3)
Where the 28x28 is duplicated across the 3 values
Hope that makes sense. Strictly speaking you don’t need to do these, but it’s required for pretrained architectures, like resnet