Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

IndexError: list index out of range #725

Open
langjiliang opened this issue Apr 29, 2019 · 16 comments · May be fixed by #1053
Open

IndexError: list index out of range #725

langjiliang opened this issue Apr 29, 2019 · 16 comments · May be fixed by #1053

Comments

@langjiliang
Copy link

❓ Questions and Help

Hello, I have a problem. I encountered an error while training the data set. Please ask how to solve this problem. Thank you in advance.
Traceback (most recent call last):
File "tools/train_net.py", line 186, in
main()
File "tools/train_net.py", line 179, in main
model = train(cfg, args.local_rank, args.distributed)
File "tools/train_net.py", line 85, in train
arguments,
File "/home/sineva/github/maskrcnn-benchmark/maskrcnn_benchmark/engine/trainer.py", line 57, in do_train
for iteration, (images, targets, _) in enumerate(data_loader, start_iter):
File "/home/sineva/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 582, in next
return self._process_next_batch(batch)
File "/home/sineva/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 608, in _process_next_batch
raise batch.exc_type(batch.exc_msg)
IndexError: Traceback (most recent call last):
File "/home/sineva/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 99, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "/home/sineva/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 99, in
samples = collate_fn([dataset[i] for i in batch_indices])
File "/home/sineva/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/dataset.py", line 85, in getitem
return self.datasets[dataset_idx][sample_idx]
File "/home/sineva/github/maskrcnn-benchmark/maskrcnn_benchmark/data/datasets/coco.py", line 83, in getitem
masks = SegmentationMask(masks, img.size, mode='poly')
File "/home/sineva/github/maskrcnn-benchmark/maskrcnn_benchmark/structures/segmentation_mask.py", line 467, in init
self.instances = PolygonList(instances, size)
File "/home/sineva/github/maskrcnn-benchmark/maskrcnn_benchmark/structures/segmentation_mask.py", line 344, in init
assert isinstance(polygons[0][0], (list, tuple)), str(
IndexError: list index out of range

Configuration file:

MODEL:
META_ARCHITECTURE: "GeneralizedRCNN"
WEIGHT: "catalog://ImageNetPretrained/MSRA/R-50"
BACKBONE:
CONV_BODY: "R-50-FPN"
RESNETS:
BACKBONE_OUT_CHANNELS: 256
RPN:
USE_FPN: True
ANCHOR_STRIDE: (4, 8, 16, 32, 64)
PRE_NMS_TOP_N_TRAIN: 2000
PRE_NMS_TOP_N_TEST: 1000
POST_NMS_TOP_N_TEST: 1000
FPN_POST_NMS_TOP_N_TEST: 1000
ROI_HEADS:
USE_FPN: True
ROI_BOX_HEAD:
POOLER_RESOLUTION: 7
POOLER_SCALES: (0.25, 0.125, 0.0625, 0.03125)
POOLER_SAMPLING_RATIO: 2
FEATURE_EXTRACTOR: "FPN2MLPFeatureExtractor"
PREDICTOR: "FPNPredictor"
ROI_MASK_HEAD:
POOLER_SCALES: (0.25, 0.125, 0.0625, 0.03125)
FEATURE_EXTRACTOR: "MaskRCNNFPNFeatureExtractor"
PREDICTOR: "MaskRCNNC4Predictor"
POOLER_RESOLUTION: 14
POOLER_SAMPLING_RATIO: 2
RESOLUTION: 28
SHARE_BOX_FEATURE_EXTRACTOR: False
MASK_ON: False
DATASETS:
TRAIN: ("coco_2014_train", "coco_2014_val")
TEST: ("coco_2014_test",)
DATALOADER:
SIZE_DIVISIBILITY: 32
SOLVER:
BASE_LR: 0.0025
WEIGHT_DECAY: 0.0001
STEPS: (60000, 80000)
MAX_ITER: 90000

Json file:
{
"area": 1320,
"iscrowd": 0,
"image_id": 1211098,
"bbox": [
1160,
21,
33,
40
],
"category_id": 12,
"id": 19781,
"ignore": 0,
"segmentation": []
}

@maxuba
Copy link

maxuba commented Aug 7, 2019

do you solve this problem? I get this problem too.if you solve it, please tell me .Thank you very much.
my problems are as follow:
Traceback (most recent call last):
File "tools/train_net.py", line 213, in
main()
File "tools/train_net.py", line 206, in main
model = train(cfg, args.local_rank, args.distributed)
File "tools/train_net.py", line 98, in train
arguments,
File "/home/ouc/maskrcnn-benchmark/maskrcnn_benchmark/engine/trainer.py", line 64, in do_train
for iteration, (images, targets, _) in enumerate(data_loader, start_iter):
File "/home/ouc/anaconda3/envs/maskrcnn/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 819, in next
return self._process_data(data)
File "/home/ouc/anaconda3/envs/maskrcnn/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 846, in _process_data
data.reraise()
File "/home/ouc/anaconda3/envs/maskrcnn/lib/python3.6/site-packages/torch/_utils.py", line 369, in reraise
raise self.exc_type(msg)
IndexError: Caught IndexError in DataLoader worker process 1.
Original Traceback (most recent call last):
File "/home/ouc/anaconda3/envs/maskrcnn/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
data = fetcher.fetch(index)
File "/home/ouc/anaconda3/envs/maskrcnn/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/ouc/anaconda3/envs/maskrcnn/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/ouc/maskrcnn-benchmark/maskrcnn_benchmark/data/datasets/coco.py", line 94, in getitem
target = target.clip_to_image(remove_empty=True)
File "/home/ouc/maskrcnn-benchmark/maskrcnn_benchmark/structures/bounding_box.py", line 223, in clip_to_image
return self[keep]
File "/home/ouc/maskrcnn-benchmark/maskrcnn_benchmark/structures/bounding_box.py", line 208, in getitem
bbox.add_field(k, v[item])
File "/home/ouc/maskrcnn-benchmark/maskrcnn_benchmark/structures/segmentation_mask.py", line 554, in getitem
selected_instances = self.instances.getitem(item)
File "/home/ouc/maskrcnn-benchmark/maskrcnn_benchmark/structures/segmentation_mask.py", line 463, in getitem
selected_polygons.append(self.polygons[i])
IndexError: list index out of range

@zimenglan-sysu-512
Copy link
Contributor

i use pytorch-1.2, it meets this problem.
any help is appreciated.

@cnavarrete72
Copy link

Did any of you manage to solve the problem? I'm getting exactly the same error as gravitymxb. Are you using your own dataset?

@Yanhong-Li
Copy link

I got same error too.
Traceback (most recent call last):
File "tools/train_net.py", line 191, in
main()
File "tools/train_net.py", line 184, in main
model = train(cfg, args.local_rank, args.distributed)
File "tools/train_net.py", line 85, in train
arguments,
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/engine/trainer.py", line 57, in do_train
for iteration, (images, targets, _) in enumerate(data_loader, start_iter):
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 819, in next
return self._process_data(data)
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 846, in _process_data
data.reraise()
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/_utils.py", line 369, in reraise
raise self.exc_type(msg)
IndexError: Caught IndexError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
data = fetcher.fetch(index)
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/data/datasets/coco.py", line 94, in getitem
target = target.clip_to_image(remove_empty=True)
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/structures/bounding_box.py", line 223, in clip_to_image
return self[keep]
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/structures/bounding_box.py", line 208, in getitem
bbox.add_field(k, v[item])
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/structures/segmentation_mask.py", line 553, in getitem
selected_instances = self.instances.getitem(item)
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/structures/segmentation_mask.py", line 462, in getitem
selected_polygons.append(self.polygons[i])
IndexError: list index out of range

Traceback (most recent call last):
File "tools/train_net.py", line 191, in
main()
File "tools/train_net.py", line 184, in main
model = train(cfg, args.local_rank, args.distributed)
File "tools/train_net.py", line 85, in train
arguments,
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/engine/trainer.py", line 57, in do_train
for iteration, (images, targets, _) in enumerate(data_loader, start_iter):
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 819, in next
return self._process_data(data)
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 846, in _process_data
data.reraise()
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/_utils.py", line 369, in reraise
raise self.exc_type(msg)
IndexError: Caught IndexError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
data = fetcher.fetch(index)
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/data/datasets/coco.py", line 94, in getitem
target = target.clip_to_image(remove_empty=True)
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/structures/bounding_box.py", line 223, in clip_to_image
return self[keep]
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/structures/bounding_box.py", line 208, in getitem
bbox.add_field(k, v[item])
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/structures/segmentation_mask.py", line 553, in getitem
selected_instances = self.instances.getitem(item)
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/structures/segmentation_mask.py", line 462, in getitem
selected_polygons.append(self.polygons[i])
IndexError: list index out of range

Traceback (most recent call last):
File "tools/train_net.py", line 191, in
main()
File "tools/train_net.py", line 184, in main
model = train(cfg, args.local_rank, args.distributed)
File "tools/train_net.py", line 85, in train
arguments,
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/engine/trainer.py", line 57, in do_train
for iteration, (images, targets, _) in enumerate(data_loader, start_iter):
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 819, in next
return self._process_data(data)
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 846, in _process_data
data.reraise()
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/_utils.py", line 369, in reraise
raise self.exc_type(msg)
IndexError: Caught IndexError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
data = fetcher.fetch(index)
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/data/datasets/coco.py", line 94, in getitem
target = target.clip_to_image(remove_empty=True)
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/structures/bounding_box.py", line 223, in clip_to_image
return self[keep]
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/structures/bounding_box.py", line 208, in getitem
bbox.add_field(k, v[item])
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/structures/segmentation_mask.py", line 553, in getitem
selected_instances = self.instances.getitem(item)
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/structures/segmentation_mask.py", line 462, in getitem
selected_polygons.append(self.polygons[i])
IndexError: list index out of range

Traceback (most recent call last):
File "tools/train_net.py", line 191, in
main()
File "tools/train_net.py", line 184, in main
model = train(cfg, args.local_rank, args.distributed)
File "tools/train_net.py", line 85, in train
arguments,
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/engine/trainer.py", line 57, in do_train
for iteration, (images, targets, _) in enumerate(data_loader, start_iter):
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 819, in next
return self._process_data(data)
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 846, in _process_data
data.reraise()
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/_utils.py", line 369, in reraise
raise self.exc_type(msg)
IndexError: Caught IndexError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
data = fetcher.fetch(index)
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/data/datasets/coco.py", line 94, in getitem
target = target.clip_to_image(remove_empty=True)
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/structures/bounding_box.py", line 223, in clip_to_image
return self[keep]
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/structures/bounding_box.py", line 208, in getitem
bbox.add_field(k, v[item])
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/structures/segmentation_mask.py", line 553, in getitem
selected_instances = self.instances.getitem(item)
File "/home/liyh/maskrcnn-benchmark/maskrcnn_benchmark/structures/segmentation_mask.py", line 462, in getitem
selected_polygons.append(self.polygons[i])
IndexError: list index out of range

Traceback (most recent call last):
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/distributed/launch.py", line 246, in
main()
File "/home/liyh/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/distributed/launch.py", line 242, in main
cmd=cmd)
Any one could help us?Thanks.

@liyz15 liyz15 linked a pull request Aug 20, 2019 that will close this issue
@liyz15
Copy link

liyz15 commented Aug 20, 2019

See #1053

@sarahmass
Copy link

sarahmass commented Aug 23, 2019

Update: I replaced the one occurrence of torch.uint8 with torch.bool in the segmentation_mask.py file and my code is now running!

I read what little was posted under #1053 and the fix is not quite clear. I think I need the fix spelled out more clearly for me. I am trying to get the model to load and run tools/test_net.py on a Linux virtual machine. I can not seem to find a useable PyTorch version 1.1.0 for lynux for Conda=10.0 (if you have a link to one I would love to try it). The earlier version of pytorch for windows (1.1.0) is working on my desktop. I have been working on this for a couple of weeks now trying to get the VM all set up. This is the closest I have been. I appreciate any help offered. -Thanks, Sarah

@zsc1220
Copy link

zsc1220 commented Aug 26, 2019

This problem has been bothering me for a week. The key problem is that the pytorch's version is too high.Before I used version pytorch 1.2 ,it always had this error. When I changed the pytorch version to 1.1,and used this code 'python setup.py build develop' to recompile. Now my code running successfully !

@zimenglan-sysu-512
Copy link
Contributor

hi @zsc1220
if u want to us torch-1.2.0, u should replace torch.unit8 with torch.bool in the code. more details can see here.

@zsc1220
Copy link

zsc1220 commented Aug 26, 2019

hello @zimenglan-sysu-512
so in which file i need to replace ? A little more detail,thanks a lot!

@zimenglan-sysu-512
Copy link
Contributor

suggest that u should replace all of them

@sarahmass
Copy link

At the very least you should change the segmentation_mask.py file.

@TheLostIn
Copy link

Thanks to @zimenglan-sysu-512 , I've replaced torch.unit8 with torch.bool,and it worked.

@Zy1013921842
Copy link

@zimenglan-sysu-512 @zsc1220 @liyz15
Hello, friends! I'm using pytorch1.1 but I still meet the same problem and I replaced 2 torch.uint8 with torch.bool in segmatation_mask.py but it doesn't work, any advice? Thanks so much!

@AllenYuQ
Copy link

i use pytorch-1.2, it meets this problem.
any help is appreciated.

Are u sure? The required pytorch vision for maskrcnn_bench is 1.0 or it will never be installed successfully. My torch is 1.0 and encouter the same errror.

@Amir22010
Copy link

Amir22010 commented Mar 3, 2020

I too replaced torch.unit8 with torch.bool in segmentation_mask.py and it worked :) thanks guys for helping me in rotated mask_rcnn

but i am getting warning -
/pytorch/aten/src/ATen/native/IndexingUtils.h:20: UserWarning: indexing with dtype torch.uint8 is now deprecated, please use a dtype torch.bool instead.

@ersen-zh
Copy link

ersen-zh commented Apr 5, 2020

I too replaced torch.unit8 with torch.bool in segmentation_mask.py and it worked ^_^

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.