I am getting a noisy classified image inspite of getting test accuracy of 99 percent

Dear friends, I am getting a noisy classified image inspite of getting test accuracy of 99 percent. I am using the following function for obtaining the classification map.

def classified_pixels(FPatches,gPatches,g):
  FPatches=np.reshape(FPatches,(FPatches.shape[0],FPatches.shape[3],FPatches.shape[1],FPatches.shape[2]))
  data_test=MyDataset(FPatches, gPatches)
  test_loader = torch.utils.data.DataLoader(data_test,batch_size=10,shuffle=False, num_workers=2)
  with torch.no_grad():
    correct = 0
    total = 0
    predicted_numpy=[]
    for images, labels in test_loader:
      images = images.to(device)
      labels = labels.to(device)
      outputs = model(images)
      _, predicted = torch.max(outputs.data, 1)
      predicted_numpy.append(predicted.cpu().numpy())
      total += labels.size(0)
      correct += (predicted == labels).sum().item()
  classification_map=np.array(predicted_numpy)
  cm=[]
  for arr in classification_map:
    cm.append(arr.tolist())
  cm=list(itertools.chain.from_iterable(cm))
  classification_map=np.array(cm)

  height=g.shape[0]
  width=g.shape[1]
  outputs = np.zeros((height,width))
  k=0
  for i in range(height):
    for j in range(width):
       target = g[i][j]
       if target == 0 :
         continue
       else :
        outputs[i][j]=classification_map[k]
       k=k+1
  return classification_map,outputs

If you add more context to your question then people who are not very familiar with the exact setting of your problem, may also be able to help you. This could increase the chances of you getting useful inputs from the forum.

Examples of more context include: What is the problem that you are trying to solve? What does the input look like? What is the output that you expect? What does your model look like? And so on.

@gphilip, I have performed pixel classification of Hyperspectral Image using the above mentioned model. I have extracted the patches mentioned as FPatches around the neighbourhood of the pixel and consider them as samples. The label of the center pixel of the FPatch is considered as the label for the entire FPatch. The model is trained using training samples and tested using test samples. Test accuracy is more than 99 percent. For obtaining the classification map I have taken the entire FPatches and predicted the labels using the same trained model. Finally I have converted the predicted classes into array to get the classification map. One important thing to mention is that the groundtruth contains background pixels denoted as 0 so when the classification map array is generated we will keep those classes as zero.

Thank you for the details.

I don’t have enough knowledge in your domain to answer your question; let us hope others can help you figure this out.