likyoo / change_detection.pytorch

Deep learning models for change detection of remote sensing images

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BCL

opened this issue · comments

There is a bcl.py in losses but it is not compatible with the package and I received error. Could you please advise?

Could you please show more detals about the error you received?

There is a bcl.py in losses but it is not compatible with the package and I received error. Could you please advise?

Could you please show more detals about the error you received?

In the local_test.py, I changed the loss ("loss = cdp.utils.losses.CrossEntropyLoss()") with "loss = cdp.losses.bcl.BCLLoss()" but I received this error:
"RuntimeError: The size of tensor a (2) must match the size of tensor b (8) at non-singleton dimension 1"

In the local_test.py, I changed the loss ("loss = cdp.utils.losses.CrossEntropyLoss()") with "loss = cdp.losses.bcl.BCLLoss()" but I received this error: "RuntimeError: The size of tensor a (2) must match the size of tensor b (8) at non-singleton dimension 1"

BCLLoss function received pred.shape is (Batch,1,Height,Weight), which pred is distance map. Reference:https://www.researchgate.net/publication/341586750_A_Spatial-Temporal_Attention-Based_Method_and_a_New_Dataset_for_Remote_Sensing_Image_Change_Detection

Thanks for the clarification. I just checked the input of the loss functions in local_test.py:
y_pred.shape is "(8, 2, 256, 256)" --> 8 is batch size, 256 is height/width; what is 2 here? probably number of classes
y_true.shape is "(8, 256, 256)" --> 8 is batch size, 256 is height/width

The error comes from this 2, I think. How cross entropy loss handles this 2, while others cannot?
I see the problem not only for loss=cdp.losses.bcl.BCLLoss but also for loss=cdp.utils.losses.{L1Loss, MSELoss, BCELoss, BCEWithLogitsLoss}:
RuntimeError: The size of tensor a (2) must match the size of tensor b (8) at non-singleton dimension 1

Could you please advise how can we use those loss functions in local_test.py example?

Hi, @ghasem-abdi
"2" means the 'classes=2' in your model configuration, here.
If you want to use BCE loss, you can set ‘classes=1’, or convert your label to a one-hot form.

There may be other errors when using Epoch.run directly (this is just a sample function, not robust enough). The squeeze() function and some data type conversions may be helpful to you.

By the way, the activation function in your ‘metrics’ may need to be changed from "argmax2d" to "sigmoid".