for (uint32_t i = 0; i < tensors->Length(); ++i)
{
auto tensor = tensors->Get(i);
- // TODO support quantization
- assert(tensor->quantization() == nullptr);
// check buffer
if (tensor->buffer() >= buffers->size())
filler->add_arg(ss.str());
}
}
+
+ auto quant = tensor->quantization();
+ if (quant != nullptr)
+ {
+ // Note: Calling 'operand->mutable_quant()' will create empty 'quant' node
+ // in the recipe file. We want this only when valid parameter exist.
+ if (quant->min() != nullptr && quant->min()->size() > 0)
+ {
+ tflchef::TensorQuantization *chef_quant = operand->mutable_quant();
+ for (uint32_t idx = 0; idx < quant->min()->size(); ++idx)
+ chef_quant->add_min(quant->min()->Get(idx));
+ }
+ if (quant->max() != nullptr && quant->max()->size() > 0)
+ {
+ tflchef::TensorQuantization *chef_quant = operand->mutable_quant();
+ for (uint32_t idx = 0; idx < quant->max()->size(); idx++)
+ chef_quant->add_max(quant->max()->Get(idx));
+ }
+ if (quant->scale() != nullptr && quant->scale()->size() > 0)
+ {
+ tflchef::TensorQuantization *chef_quant = operand->mutable_quant();
+ for (uint32_t idx = 0; idx < quant->scale()->size(); ++idx)
+ chef_quant->add_scale(quant->scale()->Get(idx));
+ }
+ if (quant->zero_point() != nullptr && quant->zero_point()->size() > 0)
+ {
+ tflchef::TensorQuantization *chef_quant = operand->mutable_quant();
+ for (uint32_t idx = 0; idx < quant->zero_point()->size(); ++idx)
+ chef_quant->add_zero_point(quant->zero_point()->Get(idx));
+ }
+ }
}
// add all operators