eecn/Hyperspectral-Classification

Why ignored label appeared in prediction map?

Surflyan opened this issue · 9 comments

there are some pixels predict to undefined as first column shows, but undefined label has ignored. how to solve ?

eecn commented

Maybe you can reference to model.py/get_model function.
image

The number of categories we use in the model definition is the actual number of categories plus one (including undefined data). Actually, the training data does not contain undefined data during the supervised training process, but the undefined category is included in the prediction process with the defined model.

eecn commented

So the confusion matrix contains a row of all zero vectors (actually the target does not contain undefined categories), and the prediction contains the actual number of categories +1.

eecn commented

In my opinion,at main.py line 170
N_CLASSES = len(LABEL_VALUES) which include the undefined label .
at model.py line 33
n_classes = kwargs['n_classes'] so our model try to learn actual classes+ 1categories.
Take PU data as an example,the target is in [1,9],but the prediction is in [0,9].That why the confusion matrix looks like that.
But ,in the get_model function we set weights[torch.LongTensor(kwargs['ignored_labels'])] = 0. which pass to 'criterion' and it will not have influence on loss.

eecn commented

This project is designed to construct a common framework, so it is designed to be compatible with the requirements of full supervision and semi-supervised learning, so it is not as intuitive as a normal network. If you want to carry out ordinary supervised training, you can modify the following points to achieve.

  1. in the main.py line 170
    modify N_CLASSES = len(LABEL_VALUES)to N_CLASSES = len(LABEL_VALUES) - len(IGNORED_LABELS)
  2. in the model.py
    line 36 comment out this line
    # weights[torch.LongTensor(kwargs['ignored_labels'])] = 0.
    line 998 1003 1138
    add target = target - 1
  3. in the utils.py
    metrics function line 304
    modify target = target[ignored_mask] to target = target[ignored_mask] -1
    show_results function line 365
    add label_values = label_values[1:]
    This is just to provide a method to solve the issue you raised.And i will try to make the project more valid in the feature.Thanks for your attention.

@Surflyan

Thanks for your reply, I will try as you suggest. Your job is helpful for me.

This project is designed to construct a common framework, so it is designed to be compatible with the requirements of full supervision and semi-supervised learning, so it is not as intuitive as a normal network. If you want to carry out ordinary supervised training, you can modify the following points to achieve.

  1. in the main.py line 170
    modify N_CLASSES = len(LABEL_VALUES)to N_CLASSES = len(LABEL_VALUES) - len(IGNORED_LABELS)
  2. in the model.py
    line 36 comment out this line
    # weights[torch.LongTensor(kwargs['ignored_labels'])] = 0.
    line 998 1003 1138
    add target = target - 1
  3. in the utils.py
    metrics function line 304
    modify target = target[ignored_mask] to target = target[ignored_mask] -1
    show_results function line 365
    add label_values = label_values[1:]
    This is just to provide a method to solve the issue you raised.And i will try to make the project more valid in the feature.Thanks for your attention.

When i follow the steps and run it ,i found that the Confusion matrix data become wrong.The first number of each line is 0. I tried to find out the reason and modified it, but I failed.Hope you can help me, thank you!

eecn commented

Sorry, it took so long to reply. I will verify the current code and fix the problem as soon as possible.

This project is designed to construct a common framework, so it is designed to be compatible with the requirements of full supervision and semi-supervised learning, so it is not as intuitive as a normal network. If you want to carry out ordinary supervised training, you can modify the following points to achieve.

  1. in the main.py line 170
    modify N_CLASSES = len(LABEL_VALUES)to N_CLASSES = len(LABEL_VALUES) - len(IGNORED_LABELS)
  2. in the model.py
    line 36 comment out this line
    # weights[torch.LongTensor(kwargs['ignored_labels'])] = 0.
    line 998 1003 1138
    add target = target - 1
  3. in the utils.py
    metrics function line 304
    modify target = target[ignored_mask] to target = target[ignored_mask] -1
    show_results function line 365
    add label_values = label_values[1:]
    This is just to provide a method to solve the issue you raised.And i will try to make the project more valid in the feature.Thanks for your attention.

Your answer helped me solve the problem, thank you very much