'How test the accuracy for tensorflow lite model
I train a CNN tensorflow model, and convert for a tensorflow lite model. And now i want to know how can i make the evaluate for the TFLITE model.
I make this code :
interpreter = tf.lite.Interpreter(model_save)
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
interpreter.resize_tensor_input(input_details[0]['index'], ((len(X_test)), 180,180, 3))
interpreter.resize_tensor_input(output_details[0]['index'], (len(X_test), 4))
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
interpreter.set_tensor(input_details[0]['index'], X_test)
interpreter.invoke()
loss, accuracy = interpreter.evaluate(X_test)
But, show me the error:
'Interpreter' object has no attribute 'evaluate'
After this I tried:
loss, accuracy = interpreter.evaluate_tflite(X_test)
But apparently this just it works for Model Makers model. So now i just don't know how to preceed.
Solution 1:[1]
If your tflite model has a signature, then you can leverage the signature, see the guide.
If the model doesn't have signatures, then you can see what are the outputs like this
output_details = interpreter.get_output_details()
# Assuming you have 2 outputs
output_1 = interpreter.get_tensor(output_details[0]['index'])
output_2 = interpreter.get_tensor(output_details[1]['index'])
The signature is the suggested way, and is safer for output reordering issues.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Karim Nosseir |
