Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use predefined weights in onnx format for YoloV5n, error is generated. #21

Open
emergentsoft opened this issue Jan 19, 2024 · 0 comments

Comments

@emergentsoft
Copy link

Dear cansik,

Thank you for providing the facility to use custom trained networks in onnx format with your Deep Vision library for Processing (V4, windows 10 and 11).

I've trained a custom detector in VS code using YoloV5n and exported it to onnx format, along with a file describing the labels (there is only a single class to be detected).

Unfortunately when I try to run detections on a single image I get the error below:

java.lang.NullPointerException: Cannot invoke "org.bytedeco.opencv.opencv_dnn.Net.setInput(org.bytedeco.opencv.opencv_core.Mat)" because "this.net" is null
at ch.bildspur.vision.YOLONetwork.run(YOLONetwork.java:81)
at ch.bildspur.vision.YOLONetwork.run(YOLONetwork.java:20)
at ch.bildspur.vision.network.BaseNeuralNetwork.run(BaseNeuralNetwork.java:21)
at YOLOv5.setup(YOLOv5.java:99)
at processing.core.PApplet.handleDraw(PApplet.java:2051)
at processing.awt.PSurfaceAWT$9.callDraw(PSurfaceAWT.java:1386)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:356)
Hi

I thought it might be an issue setting the path to the model and labels. The labels and onnx file are both contained in the sketch's data folder The paths are shown below (some private info removed):

pl: C:\Users\xxxj\xxx\xxx\xxx\src\proc4sketches\YOLOv5\data\classes.txt
pm: C:\Users\jxxxj\xxx\xxx\xxx\src\proc4sketches\YOLOv5\data\best.onnx

below is the setup part of the processing sketch if that is any help:

network = new YOLONetwork(
null, // for yolov5 the weights already contains the model in onnx format
pm, // trained weights of the model
640, 640, // inference size
false
);

network.loadLabels(pl);
network.setConfidenceThreshold(0.5f);
//network.setTopK(100);
//if (network == null)
if (loadimage == null)
println("it is null");

do
{
Thread.yield();
println("waiting ...");
}
while (network == null);
// note - waiting is only printing once, suggesting that the network was created in the constructor

try{
detections = network.run(loadimage);
}catch(NullPointerException e){e.printStackTrace();}
println("Hi");
}
// note the error I mentioned before is displayed from the stacktrace

Many thanks for any suggestions you can provide. I am happy to PM the complete sketch code to you.

Sincerely,

Zeffman

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant