So I have trained a YOLOv3 model and want to test the accuracy of the model. I am trying to load the model by using the command 'cv2.dnn.readNetFromDarknet'. Every time I try I receive the error
Traceback (most recent call last):
File "C:\Users\Philip\PycharmProjects\Scriptie\venv\tester.py", line 9, in <module>
net = cv2.dnn.readNetFromDarknet(modelConfiguration, modelWeights)
cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\darknet\darknet_io.cpp:660: error: (-215:Assertion failed) separator_index < line.size() in function 'cv::dnn::darknet::ReadDarknetFromCfgStream'
The python code that I am using is shown below:
import cv2
import numpy as np
import matplotlib.pyplot as pl
classes = ['TEETH']
modelConfiguration = r"C:\Users\Philip\PycharmProjects\Scriptie\venv\yolov3_custom.cfg"
modelWeights = r"C:\Users\Philip\PycharmProjects\Scriptie\venv\yolov3_custom_2000.weights"
net = cv2.dnn.readNetFromDarknet(modelConfiguration, modelWeights)
I have tried changing the paths to absolute paths but it didn't work, anyone that can help me with this?
Related
I have installed scikit-learn 0.23.2 via pip3, however, I get this error from my code
Traceback (most recent call last):
File "pca_iris.py", line 12, in <module>
X = StandardScaler().fit_transform(X)
NameError: name 'StandardScaler' is not defined
I searched the web and saw similar topics, however the version is correct and I don't know what to do further. The line import sklearn is in the top of the script.
Any thought?
StandardScaler is a method under sklearn.preprocessing. You need to import the StandardScaler like this:
from sklearn.preprocessing import StandardScaler
X = StandardScaler().fit_transform(X)
Or
import sklearn
X = sklearn.preprocessing.StandardScaler().fit_transform(X)
I try to convert an ONNX model to Keras, but when I call the conversion function I receive the following error message "TypeError: unhashable type: 'google.protobuf.pyext._message.RepeatedScalarContainer'"
ONNX Model Input: input_1
You can see the ONNX Model here: https://ibb.co/sKnbxWY
import onnx2keras
from onnx2keras import onnx_to_keras
import keras
import onnx
onnx_model = onnx.load('onnxModel.onnx')
k_model = onnx_to_keras(onnx_model, ['input_1'])
keras.models.save_model(k_model,'kerasModel.h5',overwrite=True,include_optimizer=True)
File "C:/../onnx2Keras.py", line 7, in <module>
k_model = onnx_to_keras(onnx_model, ['input_1'])
File "..\site-packages\onnx2keras\converter.py", line 80, in onnx_to_keras
weights[onnx_extracted_weights_name] = numpy_helper.to_array(onnx_w)
TypeError: unhashable type: 'google.protobuf.pyext._message.RepeatedScalarContainer'
The problem was resolved in the new version of the onnx2keras library
You can see the issue on the GitHub https://github.com/nerox8664/onnx2keras/issues/23
I am new to opencv with tensorflow ,I have a simple hand gesture recognition notebook that am trying to run on my jupyter . After running the kernel the windows load for less than two minutes then i get an error
TypeError Traceback (most recent call last)
<ipython-input-10-2396a75050b8> in <module>()
----> 8 roi=vidimg[0:224,0:224]
TypeError: 'NoneType' object has no attribute '__getitem__'
How do i solve this
using MacOS
#full code
import cv2
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.models import load_model
import os
handornot_model=load_model("handornot.h5")
hand_model=load_model("handgesture.h5")
def predict_image(image):
return(hand_model.predict(image))
def predict_handornot(image):
return(handornot_model.predict(image))
k=0
cap=cv2.VideoCapture(0)
while True:
_,vidimg=cap.read()
cv2.rectangle(vidimg,(0,0),(224,224),(225,0,0),4)
roi=vidimg[0:224,0:224]
cv2.imwrite("tempdata//{}.jpg".format(k),roi)
img=cv2.imread("tempdata//{}.jpg".format(k))
img=img[:,:,::-1]
img2=img.reshape((1,img.shape[0],img.shape[1],img.shape[2]))
handornot=predict_handornot(img2)
result=str(np.argmax(handornot))
if result=="0":
writeonimg="Please show your hand"
else:
result2=predict_image(img2)
writeonimg=str(np.argmax(result)+1)
os.remove("tempdata//{}.jpg".format(k))
k+=1
cv2.putText(vidimg,writeonimg,(110,250),cv2.FONT_HERSHEY_COMPLEX,1,
(225,225,0),2)
cv2.imshow("vidimg",vidimg)
cv2.imshow("roi",roi)
if cv2.waitKey(2) & 0xFF==ord("q"):
break
cap.release()
cv2.destroyAllWindows()
Rasa NLU version (e.g. 0.7.3): rasa-nlu-0.11.3
Used backend / pipeline : spacy_sklearn
Operating system : Windows 10
Issue:
I am trying to follow the sample code for training as stated in the rasa website.
from rasa_nlu.training_data import load_data
from rasa_nlu.config import RasaNLUConfig
from rasa_nlu.model import Trainer
training_data = load_data('data/examples/rasa/demo-rasa.json')
trainer = Trainer(RasaNLUConfig("sample_configs/config_spacy.json"))
trainer.train(training_data)
model_directory = trainer.persist('./projects/default/')
But I can't find the load_data function from rasa_nlu.training_data, therefore, I get the following error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-07f2f1a6c2ac> in <module>()
----> 1 from rasa_nlu.training_data import load_data
2 from rasa_nlu.config import RasaNLUConfig
3 from rasa_nlu.model import Trainer
ImportError: cannot import name 'load_data'
Can someone please help me?
use from rasa_nlu.converters import load_data instead of from rasa_nlu.training_data import load_data
See
http://rasa-nlu.readthedocs.io/en/latest/python.html
https://nlu.rasa.ai/0.11.3/python.html
Solution
from rasa.shared.nlu.training_data.loading import load_data
More info: https://github.com/RasaHQ/rasa/issues/1536
I am trying to start with basics of opencv with python but when i executed the below code :
import cv2
import numpy as np
img = cv2.imread('bg.jpg',cv2.IMREAD_GRAYSCALE)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
But i am getting this error:-
Traceback (most recent call last):
File "F:\OpenCV Programs\OpenCV1.py", line 7, in <module>
cv2.imshow('image',img)
error: C:\build\master_winpack-bindings-win32-vc14-
static\opencv\modules\highgui\src\window.cpp:331: error: (-215) size.width>0
&& size.height>0 in function cv::imshow
Plz help me out thank you..!
The code you posted works, if there is an image called bg.jpg within the same directory where you are running the code.
Anyway, you could try to reference the full path to the image:
import os
img_path = os.path.join(os.getcwd(), 'bg.jpg')
img = cv2.imread(img_path,cv2.IMREAD_GRAYSCALE)
The image you attempt to load does not exist.
As you cannot display a non-existing image you get an error messsage for trying.
You'll most likely messed up the path. Maybe use an absolute path to the image.