ChenHongruixuan / MambaCD

[IEEE TGRS 2024] ChangeMamba: Remote Sensing Change Detection Based on Spatio-Temporal State Space Model
Apache License 2.0
327 stars 15 forks source link

Questions about issue 45 #69

Open heikeyuhuajia opened 1 week ago

heikeyuhuajia commented 1 week ago

Hi, I'm having the same problem as issue 45 when I'm working on an SCD task, but I don't see a solution. Firstly, the problem arises on the premise that:

  1. I downloaded the processed SECOND dataset posted in your link directly, without any changes;
  2. there should be no problem with the runtime environment, as my BCD task is running fine;
  3. train_MambaSCD.py is used for training, and the programme proceeds to

                    for (pred_scd, label_scd) in zip(preds_scd, labels_scd):
                        acc_A, valid_sum_A = accuracy(pred_scd, label_scd)
                        preds_all.append(pred_scd)
                        labels_all.append(label_scd)
                        acc = acc_A
                        acc_meter.update(acc)
    
            kappa_n0, Fscd, IoU_mean, Sek = SCDD_eval_all(preds_all, labels_all, 37)
def SCDD_eval_all(preds, labels, num_class):
    hist = np.zeros((num_class, num_class))
    for pred, label in zip(preds, labels):
        infer_array = np.array(pred)
        unique_set = set(np.unique(infer_array))
        assert unique_set.issubset(set([x for x in range(num_class)])), "unrecognized label number"
        label_array = np.array(label)
        assert infer_array.shape == label_array.shape, "The size of prediction and target must be the same"
        hist += get_hist(infer_array, label_array, num_class)

There is a

 File "/models/changedetection/utils_func/mcd_utils.py", line 209, in SCDD_eval_all
    assert unique_set.issubset(set([x for x in range(num_class)])), "unrecognized label number"
AssertionError: unrecognized label number

problem.

I debugged and found that in

for pred, labels in zip(preds, labels):
  infer_array = np.array(pred)
  unique_set = set(np.unique(infer_array))
  assert unique_set.issubset(set([x for x in range(num_class)])),

{-1} in uniqueset at some point in the loop. ![44981728526549 pic](https://github.com/user-attachments/assets/cfb96974-a08c-4b8a-919c-445c6786f2ce)

This question has puzzled me for a long time, I hope you can solve my problem in your free time, thank you very much!

ChenHongruixuan commented 4 days ago

Hi @heikeyuhuajia ,

Thank you so much for your question. We have not encountered this problem. I think it may be out of this part of the assignment.

preds_scd = (preds_A - 1) * 6 + preds_B preds_scd[change_mask == 0] = 0 labels_scd = (labels_A - 1) * 6 + labels_B labels_scd[labels_cd == 0] = 0

When the network is adequately trained at the begining before the first validation, it should not encounter this problem. So I suggest you just assign the negative number to 0. This will solve the problem.

Best,

heikeyuhuajia commented 1 day ago

Thank you very much for your answer, during the validation process, the code had the part you mentioned:

preds_scd = (preds_A - 1) * 6 + preds_B
                    preds_scd[change_mask == 0] = 0

                    labels_scd = (labels_A - 1) * 6 + labels_B
                    labels_scd[labels_cd == 0] = 0

                    for (pred_scd, label_scd) in zip(preds_scd, labels_scd):
                        acc_A, valid_sum_A = accuracy(pred_scd, label_scd)
                        preds_all.append(pred_scd)
                        labels_all.append(label_scd)
                        acc = acc_A
                        acc_meter.update(acc)

            kappa_n0, Fscd, IoU_mean, Sek = SCDD_eval_all(preds_all, labels_all, 37)

Unfortunately, there is still no solution to this problem, I hope you keep this issue and when I finish my recent paper I will come back and look into this again, thank you for your patience!

ChenHongruixuan commented 1 day ago

Hi @heikeyuhuajia ,

Unfortunately, there is still no solution to this problem

As I said, [you can just assign the negative number to 0. This will solve the problem].

Best,