简体   繁体   中英

Custom tensorflow model in android

I have created a custom model.

After that copied this link " https://github.com/tensorflow/examples/tree/master/lite/examples/object_detection/android " have changed default.tflite with own.tflite After that have changed buffer (my model is not quantized) (I should set by buffer 1080000, default is 270000) BUT the error is in TFLiteObjectDetectionAPIModel.java and line tfLite.runForMultipleInputsOutputs(inputArray, outputMap);

The error in console is "java.lang.IllegalArgumentException: Invalid output Tensor index: 1" I googled it and test most of answers but i could'nt find the true answer!

Ones I have changed " tfLite.runForMultipleInputsOutputs(inputArray, outputMap); " to " tfLite.run(imgData, outputLocations); " and there weren't any problem with that error BUT there wasn't any response for this code " tfLite.runForMultipleInputsOutputs(inputArray, outputMap); " Any help of suggestions?

My model like is " https://dinasys.ir/androidTF/assets2.zip " Or " https://dinasys.ir/androidTF/assets3.zip " they are same but assets3 has been trained for 11 hours and other one less than 10 hours.

I try your model in my project.

In tfLite.run mode there is a problem and it cannot resolve DataType but in tfLite.runForMultipleInputsOutputs mode everything works fine.

You should know that using TF-Lite for Java, according to the docs, both arguments of tflite.run() have to be tensors. But for the output argument you are passing a single float only. So, I'm pretty sure this is the root cause of tfLite.run mode error "cannot resolve DataType of java.lang.Float" .

Note: also according to the docs, raw ByteBuffers as well as multidimensional arrays of the supported data types ( float , int , long , byte ) are supported. You only have to do the same for the output.

I upload my project for you.

Use this link to download it.

Also you can clone it fromhere

Please don't hesitate to comment if you have any questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM