I’ve trained a simple CNN until the training accuracy is >99% (so it overfits but for now I’m testing m,y ability to push test images through a pretrained network).
However when I reuse an image from the training data to look at the output it’s the same classification for every image I try with the same ‘probabilities’ when using softmax.
The code looks as below (I’ve tried to simplify it to it’s key points to see if I’m missing something really obvious).
tester = torch.load(IMG_PATH+'CategoricalNet.pt')

print(tester)


CategoricalNet(
(feature_extractor): Sequential(
(0): Conv2d(1, 64, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2))
(1): ReLU()
(2): Conv2d(64, 128, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2))
(3): ReLU()
(4): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(5): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
(6): Conv2d(128, 256, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2))
(7): ReLU()
(8): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(9): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
)
(classifier): Sequential(
(0): Dropout(p=0.25)
(1): Linear(in_features=65536, out_features=256, bias=True)
(2): ReLU()
(3): Dropout(p=0.25)
(4): Linear(in_features=256, out_features=10, bias=True)
)
)
test = fits.open("E:/Documents/Python_Scripts/CNN/TRAINING/EXAMPLE_DATA.fits")
transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize([0], [1])])
data = transform(d.reshape(*d.shape, 1)).unsqueeze(0).float().cuda()

output = torch.nn.functional.softmax(tester(data),dim=1).cpu().detach().numpy()

print('TRUE LABEL=',test2[0].header['LABEL'])
print(output)

TRUE LABEL= 5

[[0.10622309 0.1435124  0.05875074 0.0495275  0.06827779 0.03227602
  0.17474921 0.17845923 0.15276037 0.03546367]]

TEST LABEL=  7

And similarly for another test case:
TRUE LABEL= 0

[[0.10622309 0.1435124  0.05875074 0.0495275  0.06827779 0.03227602
  0.17474921 0.17845923 0.15276037 0.03546367]]

TEST LABEL= 7

I’ve checked that the image transformation matches that in the training:
transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize([0], [1])])

So I’m not sure why the predictions would be the same for every test case, any help on this matter would be greately appreciated!