segmentation_models.pytorch icon indicating copy to clipboard operation
segmentation_models.pytorch copied to clipboard

Runtime Error on dice loss But model calculating loss while training

Open MUKILAN-2003 opened this issue 2 years ago • 6 comments

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

image

But how the loss is calculated while the 1st epoch training !? Is this a bug or I done any mistake ?

MUKILAN-2003 avatar Aug 15 '22 05:08 MUKILAN-2003

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 avatar Aug 19 '22 12:08 i-aki-y

@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)

MUKILAN-2003 avatar Aug 19 '22 14:08 MUKILAN-2003

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 avatar Aug 19 '22 16:08 i-aki-y

@i-aki-y Sure I will check

MUKILAN-2003 avatar Aug 19 '22 16:08 MUKILAN-2003

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.

i-aki-y avatar Aug 23 '22 06:08 i-aki-y

Sure @i-aki-y I will update Once I have done

MUKILAN-2003 avatar Aug 23 '22 12:08 MUKILAN-2003

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.

github-actions[bot] avatar Oct 23 '22 02:10 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Oct 30 '22 02:10 github-actions[bot]