【发布时间】:2020-09-10 13:17:55
【问题描述】:
我正在将 keras h5 模型量化为 uint8。为了得到完整的uint8量化,用户dtlam26在this post告诉我代表数据集应该已经在uint8中,否则输入层仍然在float32中。
问题是,如果我提供 uint8 数据,我会在调用 converter.convert() 期间收到以下错误
ValueError: 无法设置张量: 得到了 INT8 类型的张量但预期 输入 FLOAT32 输入 178,名称:input_1
看来,模型仍然需要 float32。所以我检查了基础 keras_vggface 预训练模型 (from here) 与
from keras_vggface.vggface import VGGFace
import keras
pretrained_model = VGGFace(model='resnet50', include_top=False, input_shape=(224, 224, 3), pooling='avg') # pooling: None, avg or max
pretrained_model.save()
得到的 h5 模型具有 float32 的输入层。 接下来,我使用 uint8 作为输入 dtype 更改了模型定义:
def RESNET50(include_top=True, weights='vggface',
...)
if input_tensor is None:
img_input = Input(shape=input_shape, dtype='uint8')
但对于 int,只允许使用 int32。但是,使用 int32 会导致以下层需要 float32 的问题。
这似乎不是为所有层手动执行此操作的正确方法。
为什么我的模型在量化过程中除了 uint8 数据之外,并自动将输入改为 uint8?
我错过了什么?你知道解决办法吗?非常感谢。
【问题讨论】:
标签: python tensorflow keras quantization tensorflow-lite