提交 53db6a6c 编写于 作者: 吴承辉

Merge branch 'master' into 'master'

Refactor quantize adjust

See merge request !214
...@@ -53,16 +53,28 @@ void Quantizer::QuantizeAdjustRange(float min_in, ...@@ -53,16 +53,28 @@ void Quantizer::QuantizeAdjustRange(float min_in,
float *recip_stepsize_out) { float *recip_stepsize_out) {
float minval = std::min(0.0f, min_in); float minval = std::min(0.0f, min_in);
float maxval = std::max(0.0f, max_in); float maxval = std::max(0.0f, max_in);
float range = fmaxf(0.0001f, maxval - minval); float range = std::max(0.0001f, maxval - minval);
float stepsize = range / 254.0f; float recip_stepsize = 255.0f / range;
float recip_stepsize = 254.0f / range; // make z(q0) integer
// round quantized_zero up so min_out <= minval if (minval < 0.0f) {
int quantized_zero = ((0.0f - minval) * recip_stepsize) + 0.999; float z = -minval * recip_stepsize;
float newmin = -quantized_zero * stepsize; float zi = floorf(z);
float newmax = 255.0f * stepsize + newmin; float zf = z - zi;
*min_out = newmin; if (zf > 0.0001f && zf < 0.9999f) {
*max_out = newmax; if (zi > 0.0f && (zi >= 254.0f || (zf - 1.0f) * minval > zf * maxval)) {
*stepsize_out = stepsize; range = -255.0f * minval / zi;
maxval = minval + range;
} else {
range = 255.0f * maxval / (254.0f - zi);
minval = maxval - range;
}
recip_stepsize = 255.0f / range;
}
}
*min_out = minval;
*max_out = maxval;
*stepsize_out = range / 255.0f;
*recip_stepsize_out = recip_stepsize; *recip_stepsize_out = recip_stepsize;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册