1

As shown in the following code, after I put the input image into the model to obtain the output, I want to use argmax to reduce the dimensionality, but the results after argmax all become 0. What is the reason for this, should I use other methods for dimensionality reduction? Or change my model?

newModel = CNNSEG()
newModel.load_state_dict(torch.load(PATH))
newModel.eval()

for iteration, sample in enumerate(test_data_loader):
    img = sample

    # output the results
    inputs = img.unsqueeze(1)
    outputs = newModel(inputs) # shape: [2, 4, 96, 96]
    print('outputs',outputs)
    # argmax
    #print(outputs.shape)
    out = torch.argmax(outputs, dim=1) # shape: [2,96,96]
    print('out',out)

The result of out is shown below, but all have values in outputs.

tensor([[[0, 0, 0,  ..., 0, 0, 0],
         [0, 0, 0,  ..., 0, 0, 0],
         [0, 0, 0,  ..., 0, 0, 0],
         ...,
         [0, 0, 0,  ..., 0, 0, 0],
         [0, 0, 0,  ..., 0, 0, 0],
         [0, 0, 0,  ..., 0, 0, 0]],

        [[0, 0, 0,  ..., 0, 0, 0],
         [0, 0, 0,  ..., 0, 0, 0],
         [0, 0, 0,  ..., 0, 0, 0],
         ...,
         [0, 0, 0,  ..., 0, 0, 0],
         [0, 0, 0,  ..., 0, 0, 0],
         [0, 0, 0,  ..., 0, 0, 0]]])
Zheyue Zhang
  • 23
  • 1
  • 5
  • It means that in the first dimension, the values at the zeroth index always have the highest value, across the entire tensor. Why this happens depends on your data, problem, etc. – GoodDeeds Nov 20 '21 at 23:29
  • This may be a problem of my model selection. After I switch to another model, it can work normally. Anyway, thank you so much. – Zheyue Zhang Nov 20 '21 at 23:42

0 Answers0