簡體   English   中英

我可以獲取 tensorflow lite model 的指標嗎?

[英]Can I get metrics on a tensorflow lite model?

我一直在使用自定義指標研究復雜的 Keras model,我最近將其轉換為 tensorflow lite。 模型不完全相同,輸出也不同,但是很難評估,因為 output 是大小為 128 的張量。有什么方法可以在這個 model 上運行我的自定義指標? 我一直在使用 Tf 1.14。 下面是一些相關的代碼。

# compiler and train the model
model.save('model.h5')

# save the model in TFLite
converter = tf.lite.TFLiteConverter.from_keras_model_file('model.h5', custom_objects={'custom_metric': custom_metric})
tflite_model = converter.convert()
open('model.tflite', 'wb').write(tflite_model)

# run the model
interpreter = tf.lite.Interpreter(model_path='model.tflite')
interpreter.allocate_tensors()
input_dets = interpreter.get_input_details()
output_dets = interpreter.get_output_details()
input_shape = input_dets[0]['shape']
input_data = np.array(np.random.random_sample(input_shape), dtype=np.float32)
interpreter.set_tensor(input_dets[0]['index'], input_data)
interpreter.invoke()

這些模型應該是不同的,因為轉換器會進行圖形轉換(例如熔斷器激活和折疊批量規范),並且生成的圖形僅針對推理場景。

要運行指標:解釋器提供 API 以獲取 output 值(作為數組):

output = interpreter.tensor(interpreter.get_output_details()[0]["index"])

然后將您的指標應用於 output。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM