IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed

Following the jetson-inference “Collecting your own Detection datasets”, I faced this issue when I was trying to train the model, where my label.txt file was not used and also and array issue.

Hope someone could give me some advice on how to solve this issue.

2022-12-22 05:42:48 - Using CUDA…
2022-12-22 05:42:48 - Namespace(balance_data=False, base_net=None, base_net_lr=0.001, batch_size=4, checkpoint_folder=‘models/sticker’, dataset_type=‘voc’, datasets=[‘data/sticker’], debug_steps=10, extra_layers_lr=None, freeze_base_net=False, freeze_net=False, gamma=0.1, lr=0.01, mb2_width_mult=1.0, milestones=‘80,100’, momentum=0.9, net=‘mb1-ssd’, num_epochs=30, num_workers=2, pretrained_ssd=‘models/mobilenet-v1-ssd-mp-0_675.pth’, resume=None, scheduler=‘cosine’, t_max=100, use_cuda=True, validation_epochs=1, weight_decay=0.0005)
2022-12-22 05:42:48 - Prepare training datasets.
warning - could not find image 20221220-081821 - ignoring from dataset
warning - could not find image 20221220-110025 - ignoring from dataset
warning - could not find image 20221220-110912 - ignoring from dataset
warning - could not find image 20221220-111029 - ignoring from dataset
warning - could not find image 20221220-112046 - ignoring from dataset
warning - could not find image 20221221-050345 - ignoring from dataset
warning - could not find image 20221221-050345 - ignoring from dataset
warning - could not find image 20221221-050520 - ignoring from dataset
warning - could not find image 20221221-091026 - ignoring from dataset
2022-12-22 05:42:48 - No labels file, using default VOC classes.
2022-12-22 05:42:48 - Stored labels into file models/sticker/labels.txt.
2022-12-22 05:42:48 - Train dataset size: 458
2022-12-22 05:42:48 - Prepare Validation datasets.
2022-12-22 05:42:48 - No labels file, using default VOC classes.
2022-12-22 05:42:48 - Validation dataset size: 50
2022-12-22 05:42:48 - Build network.
2022-12-22 05:42:48 - Init from pretrained ssd models/mobilenet-v1-ssd-mp-0_675.pth
2022-12-22 05:42:49 - Took 0.56 seconds to load the model.
2022-12-22 05:43:03 - Learning rate: 0.01, Base net learning rate: 0.001, Extra Layers learning rate: 0.01.
2022-12-22 05:43:03 - Uses CosineAnnealingLR scheduler.
2022-12-22 05:43:03 - Start training from epoch 0.
/usr/local/lib/python3.6/dist-packages/torch/optim/lr_scheduler.py:134: UserWarning: Detected call of lr_scheduler.step() before optimizer.step(). In PyTorch 1.1.0 and later, you should call them in the opposite order: optimizer.step() before lr_scheduler.step(). Failure to do this will result in PyTorch skipping the first value of the learning rate schedule.
warning - image 20221221-091128 has object with unknown class ‘Tie’
warning - image 20221221-043444 has object with unknown class ‘Broccoli’
warning - image 20221220-111832 has object with unknown class ‘Apple’
Traceback (most recent call last):
warning - image 20221220-112030 has object with unknown class ‘Apple’
File “train_ssd.py”, line 343, in
device=DEVICE, debug_steps=args.debug_steps, epoch=epoch)
File “train_ssd.py”, line 113, in train
for i, data in enumerate(loader):
File “/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py”, line 521, in next
data = self._next_data()
File “/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py”, line 1203, in _next_data
return self._process_data(data)
File “/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py”, line 1229, in _process_data
data.reraise()
File “/usr/local/lib/python3.6/dist-packages/torch/_utils.py”, line 425, in reraise
warning - image 20221221-063150 has object with unknown class ‘Tie’
raise self.exc_type(msg)
IndexError: Caught IndexError in DataLoader worker process 0.
Original Traceback (most recent call last):
File “/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/worker.py”, line 287, in _worker_loop
data = fetcher.fetch(index)
File “/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py”, line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File

“/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py”, line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File “/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataset.py”, line 257, in getitem
return self.datasets[dataset_idx][sample_idx]
File “/jetson-inference/python/training/detection/ssd/vision/datasets/voc_dataset.py”, line 81, in getitem
image, boxes, labels = self.transform(image, boxes, labels)
File “/jetson-inference/python/training/detection/ssd/vision/ssd/data_preprocessing.py”, line 34, in call
return self.augment(img, boxes, labels)
File “/jetson-inference/python/training/detection/ssd/vision/transforms/transforms.py”, line 55, in call
img, boxes, labels = t(img, boxes, labels)
File “/jetson-inference/python/training/detection/ssd/vision/transforms/transforms.py”, line 345, in call
boxes[:, :2] += (int(left), int(top))
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed

Hi @2001245f, this typically means there is a malformed/corrupt XML file in your dataset somewhere. What you can do to find out which image/XML file is causing the issue is to run train_ssd.py with the following debug options:

train_ssd.py --log-level=debug --debug_steps=1 --batch-size=1 --workers=1  --model-dir=models/sticker --dataset_type=voc --data=data/sticker 

This will print out a bunch of info every time PyTorch loads an image and XML annotation. The file that gets printed out directly preceding the exception is the one that is causing the issue. Investigate that image’s XML file, and either fix it or remove it from your image lists.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.