tensorflow / tensorflow/models

Using TF2.4 TFLite Model in Android App - Error

Open
#9,205 22 comments 0 reactions 5 assignees View on GitHub

@lintian06 is already working on this.

Since Sep 15, 2020.

models:research:odapi type:bug
Dominant language
Python
Stars
77.7k
Forks
44.8k
PR merge metrics
No merged PRs in 30d

Description

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am using the latest TensorFlow Model Garden release and TensorFlow 2.
  • I am reporting the issue to the correct repository. (Model Garden official or research directory)
  • I checked to make sure that this issue has not already been filed.

1. The entire URL of the file you are using

https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/running_on_mobile_tf2.md

2. Describe the bug

I am able to convert the Saved Model (.pb) to a TensorFlow Lite (.tflite) file using the link above, but when I try to run on an android phone, it gives me an error that java.lang.IllegalArgumentException: ByteBuffer is not a valid flatbuffer model. Even with using both a custom model and the SSD MobileNet v2 320x320, it gives me the same error. @srjoglekar246 said that the issue is with wrong constants used for num_classes, etc, but I am unsure of how to fix this.

3. Steps to reproduce

I am using one of the later versions of tf-nightly (2.4.0-dev20200904) and am using the scripts found here which are made by @srjoglekar246 and convert the saved model to tflite.

4. Expected behavior

Usually, it should work without error. However, it is giving the java.lang.IllegalArgumentException: ByteBuffer is not a valid flatbuffer model error. When I run with the same setup with TF 1.14 model, it works perfectly fine.

5. Additional context

@srjoglekar246 has made changes and I have followed everything based on issue #9033

6. System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
  • Mobile device name if the issue happens on a mobile device: Moto E4 and G5 Play
  • TensorFlow installed from (source or binary): Binary
  • TensorFlow version (use command below): 2.4.0-dev20200904
  • Python version: 3.8.0
  • Bazel version (if compiling from source): None
  • GCC/Compiler version (if compiling from source): None
  • CUDA/cuDNN version: None
  • GPU model and memory: None

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.