diff --git a/ethosu/regor/architecture/ethosu85/ethos_u85_register_cs_generator.cpp b/ethosu/regor/architecture/ethosu85/ethos_u85_register_cs_generator.cpp index 322cc6c732e4a973b21ad5df1ca2839d091c4be5..68cd2827e546c3291d9bccb9da73800dfc948322 100644 --- a/ethosu/regor/architecture/ethosu85/ethos_u85_register_cs_generator.cpp +++ b/ethosu/regor/architecture/ethosu85/ethos_u85_register_cs_generator.cpp @@ -771,10 +771,8 @@ void EthosU85RCSGenerator::GenerateScalingForElementwise(HLCOperation *op) if ( opType == OpType::LeakyRelu ) { - // ifm1Scale is used for rescaling and ifm2Scale is used for alpha - float alpha = op->parameters.leaky_relu.alpha; - float ifm1Scale = float(input1Scale.Dequantize()); - input2Scale = QuantizedScale(alpha * ifm1Scale); + // input2Scale is used for alpha + input2Scale = op->ifm[0].quantization.scales.back(); ifmCnt = 2; } else if ( opType == OpType::Add || opType == OpType::Sub ) diff --git a/ethosu/regor/architecture/ethosu85/ethos_u85_scaling.cpp b/ethosu/regor/architecture/ethosu85/ethos_u85_scaling.cpp index 166774d02ec5f0dd30228c1f44170c008617ec42..cffe836a780dde214f3e52b679d3f9c83b4e3fe2 100644 --- a/ethosu/regor/architecture/ethosu85/ethos_u85_scaling.cpp +++ b/ethosu/regor/architecture/ethosu85/ethos_u85_scaling.cpp @@ -162,7 +162,9 @@ void RescaleElementwise(HLCOperation *op) } else if ( opType == OpType::LeakyRelu ) { - input1Scale = QuantizedScale(ifm1Scale / ofmScale); + // input1Scale is used for rescaling and input2Scale is used for alpha. + input1Scale = QuantizedScale(float(ifm1Scale) / float(ofmScale)); + input2Scale = QuantizedScale(float(op->parameters.leaky_relu.alpha) * float(ifm1Scale) / float(ofmScale)); } else if ( opType == OpType::Add || opType == OpType::Sub ) { @@ -191,6 +193,10 @@ void RescaleElementwise(HLCOperation *op) ofmQuant->scales.push_back(outScale); ofmQuant->type = QuantizationType::EXPLICIT; } + if ( opType == OpType::LeakyRelu ) + { + ifm1Quant->scales.push_back(input2Scale); + } } void RescalePooling(HLCOperation *op, bool isNoOp)