From c0b0729386b9c6fca072b507599499570e13177a Mon Sep 17 00:00:00 2001 From: chaoqin <33347064+XevenQC@users.noreply.github.com> Date: Wed, 3 Jan 2024 15:10:10 +0800 Subject: [PATCH] Fix the bug that multi webcam detection failed with OpenVINO (#11935) * Fix the bug that multi webcam detection failed with OpenVINO It would failed with the following error when detect multi webcam. "Input blob size is not equal network input size (2457600!=1228800)" Signed-off-by: Chao Qin * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Signed-off-by: Chao Qin Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- detect.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/detect.py b/detect.py index 1ea4e0b60dd7..03bc29de999e 100644 --- a/detect.py +++ b/detect.py @@ -124,12 +124,22 @@ def run( im /= 255 # 0 - 255 to 0.0 - 1.0 if len(im.shape) == 3: im = im[None] # expand for batch dim + if model.xml and im.shape[0] > 1: + ims = torch.chunk(im, im.shape[0], 0) # Inference with dt[1]: visualize = increment_path(save_dir / Path(path).stem, mkdir=True) if visualize else False - pred = model(im, augment=augment, visualize=visualize) - + if model.xml and im.shape[0] > 1: + pred = None + for image in ims: + if pred is None: + pred = model(image, augment=augment, visualize=visualize).unsqueeze(0) + else: + pred = torch.cat((pred, model(image, augment=augment, visualize=visualize).unsqueeze(0)), dim=0) + pred = [pred, None] + else: + pred = model(im, augment=augment, visualize=visualize) # NMS with dt[2]: pred = non_max_suppression(pred, conf_thres, iou_thres, classes, agnostic_nms, max_det=max_det)