How to test my own image on a MNIST trained network?
This is my first time trying to train a network and use PyTorch, so please forgive me if this is considered simple.
I have a pretrained AlexNet network that was modified to classify 3 classes, which I've already trained on MNIST that I mapped to 3 different labels.
class Net( nn.Module ) :
    def __init__( self ) :
        super( Net, self ).__init__()
        
        self.model = models.alexnet( pretrained = True )
        # changed in_channels from 3 to 1 bc images are black and white 
        self.model.features[ 0 ] = nn.Conv2d( 1, 64, kernel_size = 11, stride = 4, padding = 2 )
        
        # binary classifier -&gt; 3 out_features
        self.model.classifier[ 4 ] = nn.Linear( 4096, 1024 )
        self.model.classifier[ 6 ] = nn.Linear( 1024, 3 )
        
    def forward( self, x ):
        return self.model( x )
    
model = Net().to( device )

I want to test this on a single .png image that I drew, which is already 255x255, and in black and white. I would like the predicted label. This is the code I have so far for preprocessing the image:
from PIL import Image
import matplotlib.pyplot as plt
import cv2
image_8 = Image.open( &quot;eight.png&quot; ).convert('L')

image_8 = list( image_8.getdata())
normalized_8 = [(255 - x) * 1.0 / 255.0 for x in image_8 ]
tensor_8 = torch.FloatTensor( normalized_8 )

pred = model( tensor_8 )

from which I got the following error: Expected 4-dimensional input for 4-dimensional weight [64, 1, 11, 11], but got 1-dimensional input of size [50176] instead. So this is clearly the wrong way to do things, but I'm not sure how to proceed.

Change your inference code to the following. Images are not intended to be flattened into 1d.
import matplotlib.pyplot as plt
import cv2
image_8 = cv2.imread(&quot;eight.png&quot;)

# following line may or may not be necessary
image_8 = cv2.cvtColor(image_8, cv2.COLOR_BGR2GRAY)

# you can divide numpy arrays by a constant natively
image_8 /= 255.

# This makes a 4d tensor (batched image) with shape [1, channels, width, height]
image_8 = torch.Tensor(tensor_8).unsqueeze(axis=0)

pred = model(image_8)

If the image is still 3d (shape of [1, width, height]), add a second .unsqueeze(axis=0).
