Error to run on tensorflow model
This code (https://sites.google.com/view/tensorflow-example-java-api) is running successfully on YOLOv2 model, but not runs on my tensorflow model which I have trained by using python tutorial:
(https://github.com/EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10/tree/d1c5b59803543e48362c27c48d704d4b0d92d135)
That produce .pb file for object detection, when i run this code on this trained model it gives error at the line: Tensor<Float> result = session.runner().feed("input", image).fetch("output").run().get(0).expect(Float.class)) {
ERROR: Exception in thread "main" java.lang.IllegalArgumentException: In[0] is not a matrix. Instead it has shape [1,416,416,3] [[{{node MatMul}} = MatMul[T=DT_FLOAT, transpose_a=false, transpose_b=false, _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_input_0_0, W)]] at org.tensorflow.Session.run(Native Method) at org.tensorflow.Session.access$100(Session.java:48) at org.tensorflow.Session$Runner.runHelper(Session.java:314) at org.tensorflow.Session$Runner.run(Session.java:264) at com.tensorflow.ObjectDetector.executeYOLOGraph(ObjectDetector.java:91) at com.tensorflow.ObjectDetector.detect(ObjectDetector.java:49) at com.tensorflow.Main.main(Main.java:9)
I have used the python scripts:
- train.py: For training dataset
- Object_detection_image.py: For exporting trained data into protobuf(.pb) file.
Can you tell me please where i am going wrong to detect the objects, i think it is something about trainig variables. that we are using here:
Tensor result = session.runner().feed("input", image).fetch("output").run().get(0).expect(Float.class)) {
Hi, I don't know that tutorial so I need some time to check that implementation, however I also created my own tutorial for training YOLOv2 models, you can access it here: https://sites.google.com/view/tensorflow-example-java-api. I created description both for training with DarkNet and DarkFlow: https://sites.google.com/view/tensorflow-example-java-api/complete-guide-to-train-yolo. Have you tried this tutorial? Best regards, Zoltan
Thanks @szaza , Which one you have used Darkflow or Darknet to train model that you are using in this java code.
I prefer using Darknet for training YOLO, however both solutions should work.
Hi @szaza , thanks for your help,
I am using your code, it code can detect the object from an image, but i want to detect the object from live webcam, to do so i am converting Mat object into BufferedImage then pass it to decode into Jpeg, it is working but too much slow, it takes almost 25-30 seconds to process image.
It can be process little bit fast by passing stream directly without encode/decode into jpeg.
Your help will be highly appreciable if you help me to solve this issue. Thanks once again.