TransUNet icon indicating copy to clipboard operation
TransUNet copied to clipboard

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

Open lisherlock opened this issue 3 years ago • 7 comments

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 avatar Mar 19 '21 03:03 lisherlock

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

lisherlock avatar Mar 19 '21 04:03 lisherlock

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!

Beckschen avatar Mar 22 '21 11:03 Beckschen

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 avatar Jun 12 '21 06:06 linyingyingkarina

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.

linyingyingkarina avatar Jun 12 '21 08:06 linyingyingkarina

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 avatar Nov 12 '21 15:11 LeelaWo

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.

LeelaWo avatar Nov 12 '21 15:11 LeelaWo

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?

sym330 avatar May 30 '24 07:05 sym330