Skip to content
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

too many indices for tensor of dimension 1 #1

Open
yuhongsheng110 opened this issue Jun 15, 2021 · 8 comments
Open

too many indices for tensor of dimension 1 #1

yuhongsheng110 opened this issue Jun 15, 2021 · 8 comments

Comments

@yuhongsheng110
Copy link

yuhongsheng110 commented Jun 15, 2021

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

@monoloxo
Copy link

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

@yuhongsheng110
Copy link
Author

yuhongsheng110 commented Jul 12, 2021

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

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

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

@monoloxo
Copy link

monoloxo commented Jul 12, 2021

同样的问题。。您现在是否解决了这个问题?@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
Copy link

同样的问题。。您现在是否解决了这个问题?@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 = []`###########################

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

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

@yuhongsheng110
Copy link
Author

yuhongsheng110 commented Jul 15, 2021

@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

@ccq1n
Copy link

ccq1n commented Jul 24, 2022

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

@lilili666-hit
Copy link

@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
您好,这个修改的位置怎么没有找到

@cuixiaofei
Copy link

cuixiaofei commented Sep 5, 2022

@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)

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

No branches or pull requests

6 participants