-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IndexError: too many indices for array #224
Comments
Hi @mama110, I was facing this error too, but while training on my own dataset. The problem for me was an annotation file without any object in it. Don't know if this will help you but, here is the script I used to check my annotations files : import argparse
import sys
import cv2
import os
import os.path as osp
import numpy as np
if sys.version_info[0] == 2:
import xml.etree.cElementTree as ET
else:
import xml.etree.ElementTree as ET
parser = argparse.ArgumentParser(
description='Single Shot MultiBox Detector Training With Pytorch')
train_set = parser.add_mutually_exclusive_group()
parser.add_argument('--root', help='Dataset root directory path')
args = parser.parse_args()
CLASSES = ( # always index 0
'aeroplane', 'bicycle', 'bird', 'boat',
'bottle', 'bus', 'car', 'cat', 'chair',
'cow', 'diningtable', 'dog', 'horse',
'motorbike', 'person', 'pottedplant',
'sheep', 'sofa', 'train', 'tvmonitor')
annopath = osp.join('%s', 'Annotations', '%s.{}'.format("xml"))
imgpath = osp.join('%s', 'JPEGImages', '%s.{}'.format("jpg"))
def vocChecker(image_id, width, height, keep_difficult = False):
target = ET.parse(annopath % image_id).getroot()
res = []
for obj in target.iter('object'):
difficult = int(obj.find('difficult').text) == 1
if not keep_difficult and difficult:
continue
name = obj.find('name').text.lower().strip()
bbox = obj.find('bndbox')
pts = ['xmin', 'ymin', 'xmax', 'ymax']
bndbox = []
for i, pt in enumerate(pts):
cur_pt = int(bbox.find(pt).text) - 1
# scale height or width
cur_pt = float(cur_pt) / width if i % 2 == 0 else float(cur_pt) / height
bndbox.append(cur_pt)
print(name)
label_idx = dict(zip(CLASSES, range(len(CLASSES))))[name]
bndbox.append(label_idx)
res += [bndbox] # [xmin, ymin, xmax, ymax, label_ind]
# img_id = target.find('filename').text[:-4]
print(res)
try :
print(np.array(res)[:,4])
print(np.array(res)[:,:4])
except IndexError:
print("\nINDEX ERROR HERE !\n")
exit(0)
return res # [[xmin, ymin, xmax, ymax, label_ind], ... ]
if __name__ == '__main__' :
i = 0
for name in sorted(os.listdir(osp.join(args.root,'Annotations'))):
# as we have only one annotations file per image
i += 1
img = cv2.imread(imgpath % (args.root,name.split('.')[0]))
height, width, channels = img.shape
print("path : {}".format(annopath % (args.root,name.split('.')[0])))
res = vocChecker((args.root, name.split('.')[0]), height, width)
print("Total of annotations : {}".format(i)) |
@Eralaf It worked like a charm. Thanks a lot! I pasted the following code after
|
@ankitksharma Indeed, it should work better ! haha |
@Eralaf It help me a lot |
facing same error, img, boxes, labels = self.transform(img, target[:, :4], target[:, 4]) |
@Eralaf i have tried your method on pycharm,but error shows up : TypeError: expected str, bytes or os.PathLike object, not NoneType. so could tell me how to solve the problem ,thanks! |
@barcahoo Did you call the script with the root argument ? Let's say the script I used to check my annotations files is called check.py : python check.py --root="Dataset root directory path" In this root directory there must be an "Annotations" folder and a "JPEGImages" folder. @charan1561 it's a bit late, sorry. |
@Eralaf thanks a lot ! it works |
1 similar comment
@Eralaf thanks a lot ! it works |
@Eralaf thanks! it works, but what puzzies me is that, I added a print log to the top of this sentence, like |
I have this error too,and i use @Eralaf method to check xml |
I think that will happend when there are not objects in the xml file,because this code does not process this condition |
I feel the same way, but how to solve it ?
|
I feel the same way, but how to solve it ?
Excuse me , When we check out these files that are empty, what do we do with them? delete?Hope to receive our reply ! |
From the beginning to the end of the loss has always been equal to 2.000, what is the reason |
File "/home/kun/Software/ssd-pytorch-master/data/voc0712.py", line 145, in pull_item
img, boxes, labels = self.transform(img, target[:, :4], target[:, 4])
IndexError: too many indices for array
I want to train voc dataset, but after i modify the path and run train.py, the error shows up. Please help me .
Thank you .
The text was updated successfully, but these errors were encountered: