如何修复 IndexError:标量变量的无效索引?

问题描述 投票:0回答:1

我尝试了很多使用 YOLOv3 输入 mp4 文件,但在使用视频文件测试模型时总是出现错误,尤其是这个错误:

invalid index to scalar variable

我真的需要帮助来解决这个问题,或者是否有更好的代码结构来用视频文件测试 yolov3

import numpy as np
import cv2

# initialize minimum probability to eliminate weak predictions
p_min = 0.5

# threshold when applying non-maxia suppression
thres = 0.

# 'VideoCapture' object and reading video from a file
video = cv2.VideoCapture('parking1.mp4')

# Preparing variable for writer
# that we will use to write processed frames
writer = None

# Preparing variables for spatial dimensions of the frames
h, w = None, None

# Create labels into list
with open('coco.names') as f:
    labels = [line.strip() for line in f]
# Initialize colours for representing every detected object
colours = np.random.randint(0, 255, size=(len(labels), 3), dtype='uint8')

# Loading trained YOLO v3 Objects Detector
# with the help of 'dnn' library from OpenCV
# Reads a network model stored in Darknet model files.
network = cv2.dnn.readNetFromDarknet('yolov3.cfg',
                                     'yolov3.weights')

# Getting only output layer names that we need from YOLO(ERRORRRRRRRRRR HEREEE) 
ln = network.getLayerNames()
ln = [ln[i[0] - 1] for i in network.getUnconnectedOutLayers()]

# Defining loop for catching frames
while True:
    ret, frame = video.read()
    if not ret:
        break

    # Getting dimensions of the frame for once as everytime dimensions will be same
    if w is None or h is None:
        # Slicing and get height, width of the image
        h, w = frame.shape[:2]

    # frame preprocessing for deep learning
    blob = cv2.dnn.blobFromImage(frame, 1 / 255.0, (416, 416),
                                 swapRB=True, crop=False)
machine-learning deep-learning
1个回答
0
投票

[错误截图][1]

这是错误@ajgrinds的截图 [1]: https://i.stack.imgur.com/qzSdW.png

© www.soinside.com 2019 - 2024. All rights reserved.