opencv、pytorch、valueerror:tile无法扩展外部图像

zvokhttg  于 2021-08-25  发布在  Java
关注(0)|答案(1)|浏览(323)

我收到以下错误:valueerror:tile无法扩展外部图像
在推断人脸识别软件的过程中,该软件会检查您是否佩戴了新冠病毒口罩。
这是密码

transformations = Compose([
        ToPILImage(),
        Resize((100, 100)),
        ToTensor(),
    ])

[...]

    for frame in vreader(str(videopath)):
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        faces = faceDetector.detect(frame)
        for face in faces:
            xStart, yStart, width, height = face

            # clamp coordinates that are outside of the image
            xStart, yStart = max(xStart, 0), max(yStart, 0)

            # predict mask label on extracted face
            faceImg = frame[yStart:yStart+height, xStart:xStart+width]
            output = model(transformations(faceImg).unsqueeze(0).to(device))
            _, predicted = torch.max(output.data, 1)

            # draw face frame
            cv2.rectangle(frame,
                          (xStart, yStart),
                          (xStart + width, yStart + height),
                          (126, 65, 64),
                          thickness=2)

主要问题源于这个片段

output = model(transformations(faceImg).unsqueeze(0).to(device))

可能是facedetector.py中的“detect”函数,它是一个单独的元素,仅用于查找图片中的面:

def detect(self, image):
    """ detect faces in image
    """
    net = self.classifier
    height, width = image.shape[:2]
    blob = blobFromImage(resize(image, (300, 300)), 1.0,
                         (300, 300), (104.0, 177.0, 123.0))
    net.setInput(blob)
    detections = net.forward()
    faces = []
    for i in range(0, detections.shape[2]):
        confidence = detections[0, 0, i, 2]
        if confidence < self.confidenceThreshold:
            continue
        box = detections[0, 0, i, 3:7] * np.array([width, height, width, height])
        startX, startY, endX, endY = box.astype("int")
        faces.append(np.array([startX, startY, endX-startX, endY-startY]))
    return faces

我试图在1280x720p视频上运行推断。不知道怎么了。它开始推理,从我收集的数据来看,模型工作了,但很快就出现了错误。。。
你怎么认为?

fivyi3re

fivyi3re1#

当bboxes或数组(如果分段)的值无效,因此无法用于索引图像时,会导致此错误。
例如,类似于[10,20,30,40]的bbox可以正常工作,但类似于[10,-5,30,40]的bbox不会因为负值而出现。
同样,传入诸如[]之类的bbox也会导致此错误。
因此,我建议打印您的BBox,以查看是否会得到这样的意外数组。
萨尔塔克贾因

相关问题