rixez / Brats21_KAIST_MRI_Lab

Codes and pretrained weights for winning submission of 2021 Brain Tumor Segmentation (BraTS) Challenge
Apache License 2.0
169 stars 22 forks source link

axial_attention RuntimeError #8

Closed liujiyaoFDU closed 2 years ago

liujiyaoFDU commented 2 years ago

Hello, your work is so great!! When using nnUNetTrainerV2BraTSRegions_DA4_BN_BD_normalUnet_axialattention to train on my dataset, I met the problem :

  File "/home3/anaconda3/envs/nnunet_modify/lib/python3.8/site-packages/axial_attention/axial_attention.py", line 119, in forward
    x = x + getattr(self, f'param_{i}')
RuntimeError: The size of tensor a (10) must match the size of tensor b (4) at non-singleton dimension 3

I check the part of axial_attention.py, and check the x and getattr(self, f'param_{i}') size,

    def forward(self, x):
        for i in range(self.num_axials):
            print(f"size error: x: {x.size()},add: {getattr(self, f'param_{i}').size()}")
            x = x + getattr(self, f'param_{i}')

        return x

print size:

>> size error::x: torch.Size([2, 320, 4, 10, 10]),add: torch.Size([1, 320, 4, 1, 1])
>> size error::x: torch.Size([2, 320, 4, 10, 10]),add: torch.Size([1, 320, 1, 4, 1])

but I don.t know why this problem happend, could you please help me ? Thx

rixez commented 2 years ago

Hi @Jy-stdio, thanks for checking out our repo! I believe the issue is with this line: https://github.com/rixez/Brats21_KAIST_MRI_Lab/blob/6dfd1a4cb66be5ec94b9b7c102b0e5e89d8ec657/nnunet/training/network_training/competitions_with_custom_Trainers/BraTS2020/nnUNetTrainerV2BraTSRegions_moreDA.py#L377 Please change the volume_shape parameter to be the size of the volume in your dataset. Then, the axial attention embedding should be calculated correctly.

liujiyaoFDU commented 2 years ago

Thanks!! I'll try it soon

liujiyaoFDU commented 2 years ago

I've try change the volume_shape to the patch size of my dataset -volume_shape=(16, 320, 320) (this is right), but this error still occur and not the same as before:

RuntimeError: The size of tensor a (4) must match the size of tensor b (0) at non-singleton dimension 2

It's so confused.. Do u have some ideas?

rixez commented 2 years ago

Judging from the error message, it seems like the volume_shape should be (128,320,320) for your data.

liujiyaoFDU commented 2 years ago

I changed to (128,320,320)...but still got the error

RuntimeError: The size of tensor a (16) must match the size of tensor b (32) at non-singleton dimension 2
rixez commented 2 years ago

Seem like the network's configuration is different from the one that I used. You might need to modify this line: https://github.com/rixez/Brats21_KAIST_MRI_Lab/blob/6dfd1a4cb66be5ec94b9b7c102b0e5e89d8ec657/nnunet/network_architecture/generic_UNet.py#L380 The original embedding shape was calculated by dividing the original volume shape by 2^(level) of downsampling, ignoring the level specified by the no_attention parameter. You can try checking the shape of the feature maps and manually specify it.

liujiyaoFDU commented 2 years ago

ok, I'll try it. Thanks a lot!!

ysl2 commented 2 years ago

Same promblem, and cannot solved by above methods.

shifuxiao commented 2 years ago

hello ,how do I use the "BL +AA" training strategy? It‘s nnUNet_train 3d_fullres nnUNetTrainerV2BraTSRegions_DA4_BN_BD_normalUnet_axialattention 501 1 ?But meet the error raise RuntimeError("Could not find trainer class in nnunet.training.network_training") RuntimeError: Could not find trainer class in nnunet.training.network_training?Can you help me work it?thanks

rixez commented 2 years ago

Hi @shifuxiao, Can you post more of the error message? I haven't encountered this with my codes. Judging from this error, it seems like the script cannot find the definition for the trainer. Please check if you have the corresponding function: https://github.com/rixez/Brats21_KAIST_MRI_Lab/blob/6dfd1a4cb66be5ec94b9b7c102b0e5e89d8ec657/nnunet/training/network_training/competitions_with_custom_Trainers/BraTS2020/nnUNetTrainerV2BraTSRegions_moreDA.py#L354 If you do have the function, I think there might be some problem with searching for the definition of the trainer. You can check the code for that here: https://github.com/rixez/Brats21_KAIST_MRI_Lab/blob/6dfd1a4cb66be5ec94b9b7c102b0e5e89d8ec657/nnunet/run/default_configuration.py#L34 Hope this helps!!

shifuxiao commented 2 years ago

hello, can you help mi?I use my dataset train model,but the resulting Dice plot is as follows.The dice keep it 0.0.you know why it there. thanks progress

rixez commented 2 years ago

It would be difficult to figure out the source of the problem without knowing the characteristic of your dataset. Judging from the negative dice score, I think it might have to do with the preprocessing of the dataset. If your dataset does not follow the BraTS dataset convention, maybe you can try training with the default nnUNet trainer and model (instruction at the original repo).

shifuxiao commented 2 years ago

hello , I used "BL " traing my dataset ,But the Dice curve fluctuates too much.Can you help mi work on it.

training_log_2022_9_8_23_12_43 -log.txt progress

rixez commented 2 years ago

The evaluation metric is calculated based on random samples from the validation dataset so it can fluctuate a lot during training. It seems the metric is trending upward so I think it's working well. You can check the validation result at the end of the training for a more accurate evaluation.