未验证 提交 f8d7d2be 编写于 作者: H hong19860320 提交者: GitHub

[RKNPU][APU] Fix the incorrect inference results from mobilenetv1-int8 on RKNPU and APU (#4368)

上级 f802feea
...@@ -463,6 +463,38 @@ void SubgraphFuser::InsertNewNode(SSAGraph *graph, ...@@ -463,6 +463,38 @@ void SubgraphFuser::InsertNewNode(SSAGraph *graph,
idata_var_names); idata_var_names);
subgraph_op_desc.SetAttr<std::vector<std::string>>("output_data_names", subgraph_op_desc.SetAttr<std::vector<std::string>>("output_data_names",
odata_var_names); odata_var_names);
// Set input/output scale values of input/output var nodes for
// type_precision_cast_pass.
std::vector<float> input_data_scales;
std::vector<float> output_data_scales;
for (auto &var_node : idata_var_nodes) {
auto any_op_node = var_node->outlinks.front();
CHECK(any_op_node->IsStmt());
auto &any_inst = any_op_node->AsStmt();
if (any_inst.op_info()->HasAttr("input_scale")) {
input_data_scales.push_back(
any_inst.op_info()->GetAttr<float>("input_scale"));
}
}
for (auto &var_node : odata_var_nodes) {
auto any_op_node = var_node->inlinks.front();
CHECK(any_op_node->IsStmt());
auto &any_inst = any_op_node->AsStmt();
if (any_inst.op_info()->HasAttr("output_scale")) {
output_data_scales.push_back(
any_inst.op_info()->GetAttr<float>("output_scale"));
}
}
if (input_data_scales.size() > 0) {
subgraph_op_desc.SetAttr<std::vector<float>>("input_data_scales",
input_data_scales);
}
if (output_data_scales.size() > 0) {
subgraph_op_desc.SetAttr<std::vector<float>>("output_data_scales",
output_data_scales);
}
// Set all of the inputs and outputs to the target subgraph op // Set all of the inputs and outputs to the target subgraph op
// To prevent vars are removed in RuntimeProgram::UpdateVarsOfProgram() // To prevent vars are removed in RuntimeProgram::UpdateVarsOfProgram()
std::vector<std::string> input_var_names; std::vector<std::string> input_var_names;
......
...@@ -104,7 +104,7 @@ int SoftmaxConverter(void* ctx, OpLite* op, KernelBase* kernel) { ...@@ -104,7 +104,7 @@ int SoftmaxConverter(void* ctx, OpLite* op, KernelBase* kernel) {
// Add out operand // Add out operand
NeuronOperandType outType; NeuronOperandType outType;
outType.type = NEURON_TENSOR_QUANT8_ASYMM; outType.type = NEURON_TENSOR_QUANT8_ASYMM;
outType.scale = out_scale / 127; outType.scale = out_scale;
outType.zeroPoint = 128; outType.zeroPoint = 128;
outType.dimensionCount = x_dims.size(); outType.dimensionCount = x_dims.size();
outType.dimensions = &dims_x[0]; outType.dimensions = &dims_x[0];
......
...@@ -60,13 +60,6 @@ static std::string to_string(const T& v) { ...@@ -60,13 +60,6 @@ static std::string to_string(const T& v) {
return ss.str(); return ss.str();
} }
static std::string to_string(int index) {
const int BUFFER_LENGTH = 15;
char buffer[BUFFER_LENGTH];
snprintf(buffer, sizeof(buffer), "%d", index);
return std::string(buffer);
}
template <typename T = std::string> template <typename T = std::string>
static T parse_string(const std::string& v) { static T parse_string(const std::string& v) {
return v; return v;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册