natanielruiz / android-yolo

Real-time object detection on Android using the YOLO network with TensorFlow
Apache License 2.0
667 stars 212 forks source link

Object detection with custom pb file #23

Closed phongnhhn92 closed 6 years ago

phongnhhn92 commented 7 years ago

Hello sir, I had custom pb file which I trained using tiny-yolo-voc with Darknet and then convert it using darkflow command ./flow --model cfg/tiny-yolo-voc.cfg --load bin/tiny-yolo-voc.weights --savepb --verbalise My dataset is very simple which has only 1 class (cat) so the cfg I am using is changed at the final numer of filter `[convolutional] size=1 stride=1 pad=1 filters=30 activation=linear

[region] anchors = 1.08,1.19, 3.42,4.41, 6.63,11.38, 9.42,5.11, 16.62,10.52 bias_match=1 classes=1 coords=4 num=5 softmax=1 jitter=.2 rescore=1` As you said from the readme file, you hardcoded your code with voc dataset with 20 classes. So i would like to ask just in my case when I only have 1 class then what changes should I made or would you give brief explanation to help me ? Thank you so much !

natanielruiz commented 6 years ago

Hi. I hope the README addresses this question - I don't have a lot of time to come up with a detailed step by step answer but if you try to delve into the code you can figure it out.

README: The app is hardcoded for 20 classes and for the tiny-yolo network final output layer. You can check the following code if you want to change this:

https://github.com/natanielruiz/android-yolo/blob/master/app/src/main/java/org/tensorflow/demo/TensorflowClassifier.java

The code describes the interpretation of the output.

The code for the network inference pass is written in C++ and the output is passed to Java. The output of the network is in the form of a String which is converted to a StringTokenizer and is then converted into an array of Floats in line 87 of TensorflowClassifier.java

You can work from there and read the papers to transform the new yolo model output into something that makes sense. (I did it only for one bounding box and also obtained the confidence of this bounding box). This part of the code is commented by me so you can understand what I did. Also read the paper here: https://arxiv.org/abs/1506.02640