Yolov5-Deepsort icon indicating copy to clipboard operation
Yolov5-Deepsort copied to clipboard

too many indices for tensor of dimension 1

Open yuhongsheng110 opened this issue 3 years ago • 8 comments

File "/home/car/code/laserscan_camera_fuse/Yolov5-Deepsort-ros/demo.py", line 63, in main()

File "/home/car/code/laserscan_camera_fuse/Yolov5-Deepsort-ros/demo.py", line 31, in main result = det.feedCap(im)

File "/home/car/code/laserscan_camera_fuse/Yolov5-Deepsort-ros/utils/BaseDetector.py", line 35, in feedCap im, faces, face_bboxes,bboxes_draw = update_tracker(self, im)

File "/home/car/code/laserscan_camera_fuse/Yolov5-Deepsort-ros/tracker.py", line 60, in update_tracker outputs = deepsort.update(xywhs, confss, clss, image)

File "/home/car/code/laserscan_camera_fuse/Yolov5-Deepsort-ros/deep_sort/deep_sort/deep_sort.py", line 32, in update bbox_tlwh = self._xywh_to_tlwh(bbox_xywh)

File "/home/car/code/laserscan_camera_fuse/Yolov5-Deepsort-ros/deep_sort/deep_sort/deep_sort.py", line 55, in _xywh_to_tlwh bbox_tlwh[:, 0] = bbox_xywh[:, 0] - bbox_xywh[:, 2]/2.

IndexError: too many indices for tensor of dimension 1

when i try to debug ,i found that the issues occured when the image cannot be detected anything

Easy skip : USE TRY EXCEPT: use except to skip this try: result = det.feedCap(im) except Exception as e: result = {} print(e)

if the bug can be solved perfectly ,that 's would be wonderful! thanks @Sharpiless

yuhongsheng110 avatar Jun 15 '21 02:06 yuhongsheng110

同样的问题。。您现在是否解决了这个问题?@yuhongsheng110 @Sharpiless

monoloxo avatar Jul 12 '21 03:07 monoloxo

同样的问题。。您现在是否解决了这个问题?@yuhongsheng110 @Sharpiless

没能完全解决,只能跳过这个问题让程序正常运行。

USE TRY EXCEPT: use except to skip this try: result = det.feedCap(im) except Exception as e: result = {} print(e)

yuhongsheng110 avatar Jul 12 '21 05:07 yuhongsheng110

同样的问题。。您现在是否解决了这个问题?@yuhongsheng110 @Sharpiless

没能完全解决,只能跳过这个问题让程序正常运行。

USE TRY EXCEPT: use except to skip this try: result = det.feedCap(im) except Exception as e: result = {} print(e)

我好像解决了,参考他之前的那个版本,在tracker.pyz中: `bboxes2draw = []######################### face_bboxes = []######################### current_ids = []####################

if len(bboxes):#############################################

    for x1, y1, x2, y2, cls_id, conf in bboxes:

        obj = [
            int((x1+x2)/2), int((y1+y2)/2),
            x2-x1, y2-y1
        ]
        bbox_xywh.append(obj)
        confs.append(conf)
        clss.append(cls_id)

    xywhs = torch.Tensor(bbox_xywh)
    confss = torch.Tensor(confs)

    outputs = deepsort.update(xywhs, confss, clss, image)

    #bboxes2draw = []####################
    #face_bboxes = []######################
    #current_ids = []`###########################

后面一串###是改动的地方。

monoloxo avatar Jul 12 '21 05:07 monoloxo

同样的问题。。您现在是否解决了这个问题?@yuhongsheng110 @Sharpiless

没能完全解决,只能跳过这个问题让程序正常运行。 USE TRY EXCEPT: use except to skip this try: result = det.feedCap(im) except Exception as e: result = {} print(e)

我好像解决了,参考他之前的那个版本,在tracker.pyz中: `bboxes2draw = []######################### face_bboxes = []######################### current_ids = []####################

if len(bboxes):#############################################

    for x1, y1, x2, y2, cls_id, conf in bboxes:

        obj = [
            int((x1+x2)/2), int((y1+y2)/2),
            x2-x1, y2-y1
        ]
        bbox_xywh.append(obj)
        confs.append(conf)
        clss.append(cls_id)

    xywhs = torch.Tensor(bbox_xywh)
    confss = torch.Tensor(confs)

    outputs = deepsort.update(xywhs, confss, clss, image)

    #bboxes2draw = []####################
    #face_bboxes = []######################
    #current_ids = []`###########################

后面一串###是改动的地方。

这后面的###########是改动的地方,请问可以详细告知一下,怎么解决的嘛?感激不尽!

thebestYezhang avatar Jul 14 '21 13:07 thebestYezhang

@monoloxo Nice! 还有一个小问题我也顺带解决发出来,供参考。

在tracker.py中 update_tracker() 函数如下:

`

def update_tracker(target_detector, image):

new_faces = []
_, bboxes = target_detector.detect(image)

bbox_xywh = []
confs = []
clss = []
outputs = []   ####################
if len(bboxes):
    for x1, y1, x2, y2, cls_id, conf in bboxes:

        obj = [
            int((x1+x2)/2), int((y1+y2)/2),
            x2-x1, y2-y1
        ]
        bbox_xywh.append(obj)
        confs.append(conf)
        clss.append(cls_id)

    xywhs = torch.Tensor(bbox_xywh)
    confss = torch.Tensor(confs)

    outputs = deepsort.update(xywhs, confss, clss, image)

bboxes2draw = []
face_bboxes = []
current_ids = []
for value in list(outputs):
    x1, y1, x2, y2, cls_, track_id = value
    bboxes2draw.append(
        (x1, y1, x2, y2, cls_, track_id)
    )
    current_ids.append(track_id)
    if cls_ == 'face':
        if not track_id in target_detector.faceTracker:
            target_detector.faceTracker[track_id] = 0
            face = image[y1:y2, x1:x2]
            new_faces.append((face, track_id))
        face_bboxes.append(
            (x1, y1, x2, y2)
        )

ids2delete = []
for history_id in target_detector.faceTracker:
    if not history_id in current_ids:
        target_detector.faceTracker[history_id] -= 1
    if target_detector.faceTracker[history_id] < -5:
        ids2delete.append(history_id)

for ids in ids2delete:
    target_detector.faceTracker.pop(ids)
    print('-[INFO] Delete track id:', ids)

image = plot_bboxes(image, bboxes2draw)

return image, new_faces, face_bboxes,copy.deepcopy(bboxes2draw)

`

后面一串###是改动的地方。

@monoloxo @thebestYezhang

yuhongsheng110 avatar Jul 15 '21 02:07 yuhongsheng110

这个错误主要是由于没有检测出任何目标造成的,bboxes这个list里面什么都没有就会报错

ccq1n avatar Jul 24 '22 11:07 ccq1n

@monoloxo Nice! 还有一个小问题我也顺带解决发出来,供参考。

在tracker.py中 update_tracker() 函数如下:

`

def update_tracker(target_detector, image):

new_faces = []
_, bboxes = target_detector.detect(image)

bbox_xywh = []
confs = []
clss = []
outputs = []   ####################
if len(bboxes):
    for x1, y1, x2, y2, cls_id, conf in bboxes:

        obj = [
            int((x1+x2)/2), int((y1+y2)/2),
            x2-x1, y2-y1
        ]
        bbox_xywh.append(obj)
        confs.append(conf)
        clss.append(cls_id)

    xywhs = torch.Tensor(bbox_xywh)
    confss = torch.Tensor(confs)

    outputs = deepsort.update(xywhs, confss, clss, image)

bboxes2draw = []
face_bboxes = []
current_ids = []
for value in list(outputs):
    x1, y1, x2, y2, cls_, track_id = value
    bboxes2draw.append(
        (x1, y1, x2, y2, cls_, track_id)
    )
    current_ids.append(track_id)
    if cls_ == 'face':
        if not track_id in target_detector.faceTracker:
            target_detector.faceTracker[track_id] = 0
            face = image[y1:y2, x1:x2]
            new_faces.append((face, track_id))
        face_bboxes.append(
            (x1, y1, x2, y2)
        )

ids2delete = []
for history_id in target_detector.faceTracker:
    if not history_id in current_ids:
        target_detector.faceTracker[history_id] -= 1
    if target_detector.faceTracker[history_id] < -5:
        ids2delete.append(history_id)

for ids in ids2delete:
    target_detector.faceTracker.pop(ids)
    print('-[INFO] Delete track id:', ids)

image = plot_bboxes(image, bboxes2draw)

return image, new_faces, face_bboxes,copy.deepcopy(bboxes2draw)

`

后面一串###是改动的地方。

@monoloxo @thebestYezhang 您好,这个修改的位置怎么没有找到

lilili666-hit avatar Sep 01 '22 01:09 lilili666-hit

@lilili666-hit

您好,这个修改的位置怎么没有找到

Hello, maybe I can help, the key of the correction is to add len(bboxes), which figures out the bboxes is empty or not. if len(bboxes):#############################################

你好,我觉得问题的关键就是判断bboxes这个变量是否为空,这里修改的就是在这段代码前,添加一个对bboxes长度的if判断。 具体来说就是下面这段,增加了if语句,并且后面的语句缩进了一格。不知道我理解的对否?

if len(bboxes):
    for x1, y1, x2, y2, cls_id, conf in bboxes:
        obj = [
            int((x1+x2)/2), int((y1+y2)/2),
            x2-x1, y2-y1
        ]
        bbox_xywh.append(obj)
        confs.append(conf)
        clss.append(cls_id)

    xywhs = torch.Tensor(bbox_xywh)
    confss = torch.Tensor(confs)

    outputs = deepsort.update(xywhs, confss, clss, image)

cuixiaofei avatar Sep 05 '22 07:09 cuixiaofei