I wrote an article before “This Mid-Autumn Festival, I developed an app to identify dogs”. Image recognition is one of the main themes of deep learning, and almost every book and tutorial uses it as an introductory example. There are plenty of tutorials for image recognition on mobile, most of which were inspired by Google tutorials TensorFlow for Poets and TensorFlow for Poets 2: Android. With this tutorial, I am confident that I can achieve dog image recognition and that the focus is on the presentation of information and the collection of dog information.

However, years of development experience have taught me that when I do it myself, I’m bound to run into problems, especially with a product like TensorFlow Lite that iterates frequently. Sure enough, I fell headlong into the TensorFlow Lite pit. I’m going to talk about the pit.

With reference to the tutorial mentioned above, the basic functionality is working out just fine. However, when the code is built and installed on the phone, a test with an image of a dog has a top 1 probability between 0.0 and 0.02, as does the test with trained images. In order to better test, I wrote a test case: predictSingleImage(), which directly tests the picture on the SD card. The troubleshooting process is as follows:

  1. Verify that the bitmap passed to the ImageClassifier is normal. This can be confirmed by saving the bitmap to a file. Upon human observation, the image of the dog in the Bitmap sent to ImageClassifier is still obvious.
  2. Identify model problems. I started with the Google Inception V3 model and switched to the Mobilenet model used in the tutorial, the problem remains. Put the mobilenet model I trained into the example code of TensorFlow for Poets 2: Android, it works fine, although the accuracy is not high, but the probability of top 1 is greater than 0.4. You can confirm that the model is ok.
  3. Confirm that the code, which is basically a copy of TensorFlow for Poets 2: Android sample code, is not likely to be a problem.

Arrived at this step, very depressed, then the Internet search, see to have and I encounter the same problem. Accuracy score of inceptionV3 tflite model is not good as of retrained_graph.pb file Stackoverflow.com/questions/4…

This post describes the steps of the problem in great detail and ends with the test results:

However, this question was not answered. There was a moment of doubt about life: Is there a fundamental difference between recognizing a still photo and a frame of image in a Camer stream?

During a search, I came across a post: TfLite Image classification score is not consistent it keeps increasing for same image untill it reaches to some Saturation (actual score). Links: groups.google.com/a/tensorflo…

For the same image, Tflite image classification results are different, each recognition, the probability of top 1 will increase, until it reaches a fixed value.

When I saw this, I had an Epiphany. Recall that the difference between my code and the tutorial code is that I only call the recognition process once, whereas the tutorial is for the image frame recognition, will call the recognition process again and again, perhaps with a low probability before, but soon covered by the results.

At first, I guessed that tensorFlow Lite was calling its recognition procedure in code that was not properly initialized. But I added a delay to the test code, and it didn’t work. Add a loop to recognize an image several times, the recognition behind the normal. It is worth mentioning that there is no need to repeatedly identify the same picture, change several picture recognition, and then change other picture recognition is no problem. To do this, I added the predictImages() method, which tests a series of images. You can see that the top 1 score is low at the beginning, but after a few images are recognized, the probability of the top 1 is normal.

At this point, I knew I had fallen into a tensorFlow Lite pit. The problem with Tensorflow Lite is that the output of the same input and the same processing is different, and it really changes my understanding of programming.

Faced with quantum mechanics, Einstein asked, “Is God playing dice?” The question.

So is deep learning?