Hi , I have error related to object detection project

2024/11/16 3:20:30

I have error related to simple object detection .

output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]
IndexError: invalid index to scalar variable.

import cv2.cv2 as cv
import numpy as np# Load Yolonet = cv.dnn.readNet('yolov3.weights','yolov3.cfg')
classes = []
with open ("coco.names","r") as f:classes = [line.strip() for line in f.readlines()]layer_names = net.getLayerNames()
otputlayers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]#Loading imageimg = cv.imread("room_ser.jpg")cv.imshow("Image",img)
cv.waitKey(0)
cv.destroyAllWindows()
Answer

getUnconnectedOutLayers() returns an integer, not an iterable. Instead, use

outputlayers = [layer_names[i-1] for i in net.getUnconnectedOutLayers()]

The examples shown here are incorrect. More information on the method can be found on the cv2 docs here.

The error itself (IndexError) tells you that you are trying to index something that is a scalar.

https://en.xdnf.cn/q/71387.html

Related Q&A

What is the fastest way to calculate / create powers of ten?

If as the input you provide the (integer) power, what is the fastest way to create the corresponding power of ten? Here are four alternatives I could come up with, and the fastest way seems to be usin…

How to disable date interpolation in matplotlib?

Despite trying some solutions available on SO and at Matplotlibs documentation, Im still unable to disable Matplotlibs creation of weekend dates on the x-axis.As you can see see below, it adds dates to…

Continuous error band with Plotly Express in Python [duplicate]

This question already has answers here:Plotly: How to make a figure with multiple lines and shaded area for standard deviations?(5 answers)Closed 2 years ago.I need to plot data with continuous error …

How to preprocess training set for VGG16 fine tuning in Keras?

I have fine tuned the Keras VGG16 model, but Im unsure about the preprocessing during the training phase.I create a train generator as follow:train_datagen = ImageDataGenerator(rescale=1./255) train_ge…

Using Python like PHP in Apache/Windows

I understand that I should use mod_wsgi to run Python, and I have been trying to get that set up, but Im confused about it:This is a sample configuration I found for web.py:LoadModule wsgi_module modul…

django-oauth-toolkit : Customize authenticate response

I am new to Django OAuth Toolkit. I want to customize the authenticate response.My authenticate url configuration on django application is : url(authenticate/,include(oauth2_provider.urls, namespace=oa…

Pushing local branch to remote branch

I created new repository in my Github repository.Using the gitpython library Im able to get this repository. Then I create new branch, add new file, commit and try to push to the new branch.Please chec…

Does Pandas, SciPy, or NumPy provide a cumulative standard deviation function?

I have a Pandas series. I need to get sigma_i, which is the standard deviation of a series up to index i. Is there an existing function which efficiently calculates that? I noticed that there are the …

Python: compile into an Unix commandline app

I am not sure if I searched for the wrong terms, but I could not find much on this subject. I am on osx and Id like to compile a commandline python script into a small commandline app, that I can put i…

ModuleNotFoundError in PySpark Worker on rdd.collect()

I am running an Apache Spark program in python, and I am getting an error that I cant understand and cant begin to debug. I have a driver program that defines a function called hound in a file called h…