Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Re)quantize existing QKeras model with model_quantize #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions qkeras/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def model_quantize(model,
# Dense becomes QDense
# Activation converts activation functions

if layer["class_name"] == "Dense":
if layer["class_name"] in ["Dense", "QDense"]:
layer["class_name"] = "QDense"
# needs to add kernel/bias quantizers
kernel_quantizer = get_config(
Expand All @@ -290,7 +290,7 @@ def model_quantize(model,
else:
quantize_activation(layer_config, activation_bits)

elif layer["class_name"] in ["Conv1D", "Conv2D"]:
elif layer["class_name"] in ["Conv1D", "Conv2D", "QConv1D", "QConv2D"]:
q_name = "Q" + layer["class_name"]
layer["class_name"] = q_name
# needs to add kernel/bias quantizers
Expand All @@ -311,7 +311,7 @@ def model_quantize(model,
else:
quantize_activation(layer_config, activation_bits)

elif layer["class_name"] == "DepthwiseConv2D":
elif layer["class_name"] in ["DepthwiseConv2D", "QDepthwiseConv2D"]:
layer["class_name"] = "QDepthwiseConv2D"
# needs to add kernel/bias quantizers
depthwise_quantizer = get_config(quantizer_config, layer,
Expand All @@ -330,7 +330,7 @@ def model_quantize(model,
else:
quantize_activation(layer_config, activation_bits)

elif layer["class_name"] == "Activation":
elif layer["class_name"] in ["Activation", "QActivation"]:
quantizer = get_config(quantizer_config, layer, "QActivation")
# this is to avoid softmax from quantizing in autoq
if quantizer is None:
Expand All @@ -351,7 +351,7 @@ def model_quantize(model,
else:
quantize_activation(layer_config, activation_bits)

elif layer["class_name"] == "BatchNormalization":
elif layer["class_name"] in ["BatchNormalization", "QBatchNormalization"]:
layer["class_name"] = "QBatchNormalization"
# needs to add kernel/bias quantizers
gamma_quantizer = get_config(
Expand Down