title: Can not run the the tflite model on Interpreter in android studio
body: <p>I am trying to run a TensorFlow-lite model on my App on a smartphone. First, I trained the model with numerical data using LSTM and build the model layer using TensorFlow.Keras. I used TensorFlow V2.x and saved the trained model on a server. After that, the model is downloaded to the internal memory of the smartphone by the App and loaded to the interpreter using &quot;MappedByteBuffer&quot;. Until here everything is working correctly.</p>
  <p>The problem is in the interpreter can not read and run the model.
  I also added the required dependencies on the build.gradle.</p>
  <p><strong>The conversion code to tflite model in python:</strong></p>
  <pre><code>from tensorflow import keras
  from keras.models import Sequential
  from keras.layers import Dense, Dropout, LSTM
  from tensorflow.keras import regularizers
  #Create the network
  model = Sequential()
  model.add(LSTM(...... name = 'First_layer'))
  model.add(Dropout(rate=Drop_out))
  model.add(LSTM(...... name = 'Second_layer'))
  model.add(Dropout(rate=Drop_out))
  
  # compile model
  model.compile(loss=keras.losses.mae, 
  optimizer=keras.optimizers.Adam(learning_rate=learning_rate), metrics=[&quot;mae&quot;])
  
  # fit model
  model.fit(.......)
  #save the model
  tf.saved_model.save(model,'saved_model')
  print(&quot;Model  type&quot;, model1.dtype)# Model type is float32 and size around 2MB
  
  #Convert saved model into TFlite
  converter = tf.lite.TFLiteConverter.from_saved_model('saved_model')
  tflite_model = converter.convert()
  
  with open(&quot;Model.tflite, &quot;wb&quot;) as f:
      f.write(tflite_model)
  f.close()
  </code></pre>
  <p><strong>I tried also other conversion way using Keras</strong></p>
  <pre><code># converter = tf.lite.TFLiteConverter.from_keras_model(keras_model)
  # tflite_model = converter.convert()
  </code></pre>
  <p>After this step, the &quot;Model.tflite&quot; is converted and downloaded to the internal memory of the smartphone.</p>
  <p><strong>Android studio code:</strong></p>
  <pre><code>  try {
          private Interpreter tflite = new Interpreter(loadModelFile());
          Log.d(&quot;Load_model&quot;, &quot;Created a Tensorflow Lite of AutoAuth.&quot;);
  
      } catch (IOException e) {
          Log.e(&quot;Load_model&quot;, &quot;IOException loading the tflite file&quot;);
  
      }
  
  private MappedByteBuffer loadModelFile() throws IOException {
      String model_path = model_directory + model_name + &quot;.tflite&quot;;
      Log.d(TAG, model_path);
      File file = new File(model_path);
      if(file!=null){
      FileInputStream inputStream = new FileInputStream(file);
      FileChannel fileChannel = inputStream.getChannel();
      return fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, file.length());
      }else{
          return null;
      }
  }
  </code></pre>
  <p>The &quot;loadModelFile()&quot; function is working correctly because I checked it with another tflite model using MNIST dataset for image classification. The problem is only the interpreter.</p>
  <p><strong>This is also build.gradle's contents:</strong></p>
  <pre><code>android {
  aaptOptions {
      noCompress &quot;tflite&quot;
  }
   }
    android {
       defaultConfig {
          ndk {
              abiFilters 'armeabi-v7a', 'arm64-v8a'
          }
        }
      }
  
  dependencies {
       implementation 'com.jakewharton:butterknife:8.8.1'
       implementation 'org.tensorflow:tensorflow-lite:0.1.2-nightly'
       annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
       implementation fileTree(dir: 'libs', include: ['*.jar'])
       //noinspection GradleCompatible
       implementation 'com.android.support:appcompat-v7:28.0.0'
      implementation 'com.android.support.constraint:constraint-layout:2.0.4'
      testImplementation 'junit:junit:4.12'
      androidTestImplementation 'com.android.support.test:runner:1.0.2'
      androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
      }
  </code></pre>
  <p>Whenever I run Android studio, I got one of the following errors:
  1-
  <a href="https://i.stack.imgur.com/hdAnT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hdAnT.png" alt="enter image description here" /></a></p>
  <p>or</p>
  <p>2-</p>
  <p><a href="https://i.stack.imgur.com/a3567.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/a3567.png" alt="enter image description here" /></a></p>
  <p>I have gone through many resources and threads and read about saving trained models, TFlite conversion, and Interpreters.
  I am trying for 5 days ago to solve this issue but have no hope. Can anyone give a solution for this?</p>