Beckschen / TransUNet

This repository includes the official project of TransUNet, presented in our paper: TransUNet: Transformers Make Strong Encoders for Medical Image Segmentation.
Apache License 2.0
2.42k stars 502 forks source link

IndexError:index 1 is out of bounds for dimension 0 with size 1 #18

Open lisherlock opened 3 years ago

lisherlock commented 3 years ago

Hi, I have prepared dataset as your suggestion, but there's wrong information when i was training. Here is the error info.

File in line 74, in trainer_synapse: image = image_batch[1, 0:1, :, :] IndexError: index 1 is out of bounds for dimension 0 with size 1.

And my settings of training: batch:4, image size: 224. GPU:2080Ti *1. I have tried to change the batch num, but it can't work.

Looking forward to your reply soon!

lisherlock commented 3 years ago

And the tensor size of image_batch is [bs, 1, 224, 224]. But i don't know why the channel is 1.

Beckschen commented 3 years ago

Hello, thanks for your comments!

(1) The default channel in Synapse dataset is 1. But line 386-397 in vit_seg_modeling.py suggests:

if x.size()[1] == 1: x = x.repeat(1,3,1,1)

So the code will automatically handle it.

(2) Line 74 you mentioned in trainer_synapse is used for visualization in tensorboard. Please remove it if you don't need it.

IndexError: index 1 is out of bounds for dimension 0 with size 1.

It suggests that the batch_size is 1 instead of >1. Please just simply print(len(image)) to see how many the batch_size is used during training.

Let me know if you have further questions. Thanks!

linyingyingkarina commented 3 years ago

print(len(image))

hi, I have the same error during my training, my batch_size was set 16. when I print(len(image)), it was 1. how can I fix?? thanks

linyingyingkarina commented 3 years ago

print(len(image))

hi, I have the same error during my training, my batch_size was set 16. when I print(len(image)), it was 1. how can I fix?? thanks

fixed by reducing some data, also adding more data can work.

LeelaWo commented 3 years ago

print(len(image))

hi, I have the same error during my training, my batch_size was set 16. when I print(len(image)), it was 1. how can I fix?? thanks

fixed by reducing some data, also adding more data can work.

hello, I have the same question during my training. But I can't understand exactly what you mean "by reducing some data, also adding more data". Can you explain more details please ? thanks

LeelaWo commented 3 years ago

print("{} {}".format(image_batch.type(), image_batch.size())) image = image_batch[1, 0:1, :, :] print(len(image))

The image_batch print torch.Size([6, 1, 224, 224]), and len(image) print 1 as @linyingyingkarina. my settings of training: batch:6, image size: 224.

sym330 commented 5 months ago

print(len(image))

hi, I have the same error during my training, my batch_size was set 16. when I print(len(image)), it was 1. how can I fix?? thanks

fixed by reducing some data, also adding more data can work.

Sorry, I didn't understand. Can you be more specific?

csyfjiang commented 1 month ago

I meet the same question when set batch_size to 1.

Solve it to use batch size > 1.