我可以在Tensorflow Lite模型上获取指标吗?

我一直在使用自定义指标构建复杂的Keras模型,最近我将其转换为tensorflow lite。这些模型并不完全相同,并且输出是不同的,但是由于输出是大小为128的张量,因此难以评估。有什么方法可以在此模型上运行自定义指标?我一直在使用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()
baorry 回答:我可以在Tensorflow Lite模型上获取指标吗?

应该认为模型是不同的,因为转换器会进行图变换(例如保险丝激活和倍增批范数),并且生成的图仅在推理情况下针对。

要运行指标:解释器提供一个API以获取输出值(作为数组):

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

然后将指标应用于输出。

本文链接:https://www.f2er.com/3070219.html

大家都在问