tensorflow-example-java icon indicating copy to clipboard operation
tensorflow-example-java copied to clipboard

Error to run on tensorflow model

Open msarfrazcss opened this issue 7 years ago • 5 comments

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)

msarfrazcss avatar Nov 20 '18 11:11 msarfrazcss

I have used the python scripts:

  1. train.py: For training dataset
  2. 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)) {

train.py.txt Object_detection_image.py.txt

msarfrazcss avatar Nov 22 '18 09:11 msarfrazcss

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

szaza avatar Nov 22 '18 09:11 szaza

Thanks @szaza , Which one you have used Darkflow or Darknet to train model that you are using in this java code.

msarfrazcss avatar Nov 22 '18 09:11 msarfrazcss

I prefer using Darknet for training YOLO, however both solutions should work.

szaza avatar Nov 22 '18 09:11 szaza

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.

msarfrazcss avatar Nov 30 '18 11:11 msarfrazcss