model-optimization
model-optimization copied to clipboard
Depthwise convolution min_max dimension
Hello, i met a new issue when i tried to translate the weight of a pytorch model after QAT to a keras model. My model contains a depthwise convolution layer and it's weight shape is 334801 as showed in .h5 file. In QAT stage, the fake noded will be construced according to this shape, so the dimension of depthwise_kernel_min and depthwise_kernel_max will be 1. I found it is because the Default8BitConvQuantizeConfig will build the shape based on the weight tensor_shape[-1]. However, in per_axis way, the depthwise_kernel_min and depthwise_kernel_max should be tensor_shape[-2]. As for above example, the dimension of depthwise convolution is 334801, so the dimension of depthwise_kernel_min and depthwise_kernel_max should be 480. In pytorch, the depthwise convolution kernel_min and kernel_max are also 480. So it confused me when i tried to translate the weight of pytorch to a keras model.
@Xhark could you take a look?
I have another question, does tensorflow2.3 support folding op of conv+BN+Relu or conv+BN in QAT like pytorch?
My model contains a lot of conv+BN+relu, but when i use
quant_aware_model = tfmot.quantization.keras.quantize_apply(annotated_model)
i found this function can't translate the conv+BN+relu into Conv2DBatchNormReLUFold layer.
If there is a way to fold these options for model, and perform QAT afterwards like pytorch??