segmentation_models.pytorch
segmentation_models.pytorch copied to clipboard
Runtime Error on dice loss But model calculating loss while training
RuntimeError: cannot reshape tensor of 0 elements into shape [0, 1, -1] because the unspecified dimension size -1 can be any value and is ambiguous
But how the loss is calculated while the 1st epoch training !? Is this a bug or I done any mistake ?
Hi @MUKILAN-2003
The message suggests that the batch size of y_true
is zero (bs == 0
).
The bs
is defined in dice.py in the following way:
bs == y_true.size(0)
So I think you might have passed an empty y_true
. I recommend you confirm the condition y_true.size(0) > 0
is satisfied in your training loop.
@i-aki-y Thank You Yeah I checked it too. and also I double checked the train and valid loader which return the y_true shape as (512,512)
I see. But it seems weird because dataloader returns batched labels, so the shape of y_true would be (batch_size, 512, 512). Can the dataloaders (train and validation) pass the following test?
for batch in data_loader:
x, y = batch
assert len(y.shape) == 3
assert y.shape[0] > 0
@i-aki-y Sure I will check
Hi @MUKILAN-2003 . Unfortunately, I could not reproduce the error. I think it is difficult to identify the problem from current information.
If you can reproduce the error, you can get more information by running the %pdb
magic before the training code and seeing what is happening in the data in debug mode.
Sure @i-aki-y I will update Once I have done
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.