我的工作是量化在传输学习中使用MobilenetV2的个人数据集。我尝试过两种方法:
(一)仅训练后量化:它工作良好,并正在产生0.04s的平均时间来推断在224,224维60图像。
(二.)量化感知训练+训练后量化:与单纯的训练后量化相比,它产生了更高的精度,但对于相同的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'])我搜索了很多次,但是没有得到任何答复。如果可能的话,请帮助,为什么在量化感知训练+训练后量化的情况下,我的推理时间较高?
发布于 2020-09-10 04:39:41
我不认为你应该做量化感知训练+训练后量化到一起。
根据https://www.tensorflow.org/model_optimization/guide/quantization/training_example,如果你使用量化感知训练,转换将给你一个int8权重的模型。因此,在这里做训练后量化是没有意义的。
https://stackoverflow.com/questions/63805820
复制相似问题