Plugging in new data to a trained neural network - EMNIST Dataset

I am trying to create a program where an application analyzes your hand-drawn letters, but I’m having trouble putting the new data into the already trained model. It keeps coming back with large and strange outputs that don’t match what the training data’s outputs looked like. I am using the “byclass” Emnist set

Here is my Neural Network structure:

class NeuralNet(nn.Module):
     def __init__(self):
         super().__init__()
         self.flatten = nn.Flatten()
         self.linear_relu_stack = nn.Sequential(
             nn.Linear(28*28, 512),
             nn.ReLU(),
             nn.Linear(512,512),
             nn.ReLU(),
             nn.Linear(512, 62),
             )

     def forward(self, x):
         x = self.flatten(x)
         logits = self.linear_relu_stack(x)
         return logits

And here is where I am trying to call on it in the application:

    image = Image.open("Recent_Analysis.jpg").convert('L')
    imageArray = np.array(image)
    imageArray = imageArray.astype(np.float32)
    imageArray /= 255
    image_vals = torch.tensor(imageArray).unsqueeze(axis=0)
    print(image_vals.size())

    #Padding the batch in order to correct the batch size
    imageBatch = torch.zeros(128, 1, 28, 28)
    imageBatch[0] = image_vals

    with torch.no_grad():
        output = self.model(imageBatch)
        output = list(output[0].detach().numpy())
        print(output.index(max(output)))

I am confused on what I did wrong or if I fundamentally am unsure of how the output system works. I am very new to pytorch, so any help would be vastly appreciated. If you have more questions let me know.

Try to reuse a known image, which was already used during training, and compare the outputs between these runs. Based on your code it seems you are using a mostly empty batch containing only a single sample. If you haven’t moved the model to model.eval() the zeros would affect the batchnorm layers and the activation normalization of the input so you might want to use the single sample instead.