Rohan Choudhary
Rohan Choudhary

Reputation: 303

Android Tensorflow tflite error.Didn't find op for builtin opcode 'FULLY_CONNECTED' version '12'. An older version of this builtin might be supported

Internal error: Cannot create interpreter: Didn't find op for builtin opcode 'FULLY_CONNECTED' version '12'. An older version of this builtin might be supported. Are you using an old TFLite binary with a newer model?

This is the code used

@Throws(IOException::class)
    fun loadModelFile(
        context: Context,
        modelFileName: String = "constant_output_model.tflite"
    ): MappedByteBuffer {
        val fileDescriptor = context.assets.openFd(modelFileName)
        val inputStream = FileInputStream(fileDescriptor.fileDescriptor)
        val fileChannel = inputStream.channel
        val startOffset = fileDescriptor.startOffset
        val declareLength = fileDescriptor.declaredLength
        return fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declareLength)
    }

This is the interpreter API initialization

InterpreterApi.create(
            TfLiteUtils.loadModelFile(this, "voice_detection_2_17_0_new_ops.tflite"),
            InterpreterApi.Options().apply {
                numThreads = 1
            }
        )

This is the dummy model architecture with same shape and output.

input_shape = (None, 39, 63, 1)  # Input shape (excluding batch dimension)
inputs = tf.keras.Input(shape=input_shape[1:])
x = tf.keras.layers.Conv2D(filters=128, kernel_size=(8, 8), activation='relu', padding='same')(inputs)
x = tf.keras.layers.AveragePooling2D(pool_size=(2, 2))(x)
x = tf.keras.layers.Conv2D(filters=64, kernel_size=(3, 3), activation='relu', padding='same')(x)
x = tf.keras.layers.AveragePooling2D(pool_size=(2, 2))(x)
x = tf.keras.layers.Conv2D(filters=128, kernel_size=(3, 3), activation='relu', padding='same')(x)
x = tf.keras.layers.MaxPooling2D(pool_size=(2, 2))(x)
x = tf.keras.layers.Flatten()(x) # if I remove this then model works
x = tf.keras.layers.Dense(units=256)(x)
x = tf.keras.layers.LeakyReLU(alpha=0.1)(x)
x = tf.keras.layers.Dense(units=2, activation='softmax')(x)
outputs = tf.keras.layers.Dense(units=1)(x)
model = tf.keras.Model(inputs=inputs, outputs=outputs)
return model

Currently using 2.17 AAR file of tensorflow. It is not present on maven but can be built using official repo. Using lite-rt of google is also not working with same error coming. implementation "com.google.ai.edge.litert:litert:1.0.1"

It is not working for 2.17 hence, if you utilize 2.16 then it works by using different API for Interpretor 2.16 has Interpreter, 2.17 has InterpreterApi

Upvotes: 1

Views: 122

Answers (1)

Sandeep Karanam
Sandeep Karanam

Reputation: 68

I too got this same issue but solved by changing the libraries.

Refer this:

https://stackoverflow.com/a/79108363/7521690

Upvotes: 0

Related Questions