tensorflow: This model does not contain associated files, and is not a Zip file

So, i’m trying to use SSD ResNet101 V1 FPN 640x640 (RetinaNet101) found here model for my android application. After converting the model using this script:

converter = tf.lite.TFLiteConverter.from_saved_model('/content/drive/My Drive/ssd_resnet101_v1_fpn_640x640_coco17_tpu-8/saved_model/',signature_keys=['serving_default'])
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.experimental_new_converter = True
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]

tflite_model = converter.convert()

with tf.io.gfile.GFile('model.tflite', 'wb') as f:
  f.write(tflite_model)

I tried to use it inside the android application, but doesn’t work. While the application works just fine using the model from this example

Example


E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.sd_detect, PID: 23556
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sd_detect/com.example.sd_detect.MainActivity}: java.lang.IllegalStateException: This model does not contain associated files, and is not a Zip file.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3374)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3513)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2109)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 34 (22 by maintainers)

Most upvoted comments

You’ll need to pack as least the label file in the model. You can do this as follows:

from tflite_support import metadata as _metadata

populator = _metadata.MetadataPopulator.with_model_file(model_file)
populator.load_associated_files(["your_path_to_label_file"])
populator.populate() 

The metadata library can be installed through:

pip install tflite-support

See more about how to add metadata here.

Here is an example of adding metadata to an object detection model (not only the label file), through I think in your case, packing the label file should be good enough.