I am quantizing a keras h5 model to uint8. To get full uint8 quatization, user dtlam26 told me in this post that the representative dataset should already be in uint8, otherwise the input layer is still in float32.
The problem is, that if I feed uint8 data I receive following error during the call converter.convert()
ValueError: Cannot set tensor: Got tensor of type INT8 but expected type FLOAT32 for input 178, name: input_1
It seems, that the model still expects float32. So I checked the base keras_vggface pretrained model (from here) with
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()
and the resulting h5 model hast the input layer with float32. Next, I changed the model definition using uint8 as input dtype:
def RESNET50(include_top=True, weights='vggface',
...)
if input_tensor is None:
img_input = Input(shape=input_shape, dtype='uint8')
But for int only int32 is allowed. However, using int32 leads to the problem, that the following layers expect float32.
This seems not the right way to do it manually for all layers.
Why does my model during quantization not except the uint8 data and automatically change the input to uint8?
What did I miss? Do you know a solution? thanks a lot.