我正在使用MobilenetV2对个人数据集进行迁移学习中的量化研究。我尝试了两种方法:
i.)仅训练后量化:它工作良好,在224224维上推断60幅图像的平均时间为0.04s。
ii.)量化感知训练+训练后量化:它比仅训练后量化产生更高的精度,但对相同的60幅图像产生了0.55s的更高推理时间。
1.)只有训练后量化模型(.tflite)可以通过以下方式推断:
images_ = cv2.resize(cv2.cvtColor(cv2.imread(imagepath), cv2.COLOR_BGR2RGB), (224, 224))
images = preprocess_input(images_)
interpreter.set_tensor(
interpreter.get_input_details()[0]['index'], [x])
interpreter.invoke()
classes = interpreter.get_tensor(
interpreter.get_output_details()[0]['index'])
2.)量化感知训练+训练后量化可以通过以下代码推断出来。不同之处在于,这里它要求float32输入。
images_ = cv2.resize(cv2.cvtColor(cv2.imread(imagepath), cv2.COLOR_BGR2RGB), (224, 224))
images = preprocess_input(images_)
x = np.expand_dims(images, axis=0).astype(np.float32)
interpreter.set_tensor(
interpreter.get_input_details()[0]['index'], x)
interpreter.invoke()
classes = interpreter.get_tensor(
interpreter.get_output_details()[0]['index'])
我搜索了很多,但这个问题没有得到任何回应。如果可能的话,请帮忙
为什么与仅训练后量化相比,在量化感知训练+训练后量化的情况下,我的推理时间很高?