The line "tflite_model = converter.convert()" gives the AttributeError: 'str' object has no attribute 'call'.

See screenshot of code ->1

CODE:

import tensorflow as tf
converter = tf.lite.TFLiteConverter.from_keras_model('///Users/theunskuhn/Desktop/Savedfile/basic_malaria_pos_neg_v3.h5')
converter.experimental_new_converter = True
tflite_model = converter.convert()
open("basic_malaria_pos_neg_v3.tflite", "wb").write(tflite_model)  

ERROR: AttributeError: 'str' object has no attribute 'call'

The Error points to the line 4: "tflite_model = converter.convert()"

Screenshot of new code from answer below

1

There are 1 best solutions below

4
On

If you're using the TFLiteConverter API in TensorFlow 2.0 or above, the TFLiteConverter.from_keras_model takes in a Keras Model object and not the path of the model which is str.

First, load the model using tf.keras.models.load_model() and then pass this model to the TFLiteConverter API.

import tensorflow as tf

model = tf.keras.models.load_model( '///Users/theunskuhn/Desktop/Savedfile/basic_malaria_pos_neg_v3.h5' )

converter = tf.lite.TFLiteConverter.from_keras_model( model )
tflite_model = converter.convert()
open("basic_malaria_pos_neg_v3.tflite", "wb").write(tflite_model)  

The method TFLiteConverter.from_keras_model_file() was replaced by TFLiteConverter.from_keras_model() in TF 2.0. See the docs.