Browse Source

fix potential crash on int8 convolution with no bias

tags/20200226
nihui 6 years ago
parent
commit
25eb060b7c
3 changed files with 7 additions and 7 deletions
  1. +3
    -3
      src/layer/arm/convolution_arm.cpp
  2. +2
    -2
      src/layer/arm/convolutiondepthwise_arm.cpp
  3. +2
    -2
      src/layer/x86/convolution_x86.cpp

+ 3
- 3
src/layer/arm/convolution_arm.cpp View File

@@ -1160,7 +1160,7 @@ int Convolution_arm::forward_int8_arm(const Mat& bottom_blob, Mat& top_blob, con

float scale_out = top_blob_int8_scale;//FIXME load param

requantize_int8_to_int8(top_blob_tm_g, top_blob_g, scale_in, scale_out, &bias_data[p], bias_term ? 1 : 0, 0, opt_g);
requantize_int8_to_int8(top_blob_tm_g, top_blob_g, scale_in, scale_out, bias_term ? (const float*)bias_data + p : 0, bias_term ? 1 : 0, 0, opt_g);
}
}
else
@@ -1181,7 +1181,7 @@ int Convolution_arm::forward_int8_arm(const Mat& bottom_blob, Mat& top_blob, con
else
{
conv_im2col_sgemm_int8_neon(bottom_blob_bordered, top_blob, weight_sgemm_data_int8, kernel_w, kernel_h, stride_w, stride_h, opt);
}
}

// dequantize, reverse scale inplace
#pragma omp parallel for num_threads(opt.num_threads)
@@ -1200,7 +1200,7 @@ int Convolution_arm::forward_int8_arm(const Mat& bottom_blob, Mat& top_blob, con
else
scale_in = 1.f / (bottom_blob_int8_scale * weight_data_int8_scales[p]);

dequantize_int32_to_float32(top_blob_g, scale_in, &bias_data[p], bias_term ? 1 : 0, opt_g);
dequantize_int32_to_float32(top_blob_g, scale_in, bias_term ? (const float*)bias_data + p : 0, bias_term ? 1 : 0, opt_g);
}
}



+ 2
- 2
src/layer/arm/convolutiondepthwise_arm.cpp View File

@@ -671,7 +671,7 @@ int ConvolutionDepthWise_arm::forward_int8_arm(const Mat& bottom_blob, Mat& top_
opt_g.blob_allocator = top_blob.allocator;

Mat top_blob_g = top_blob.channel(g);
dequantize_int32_to_float32(top_blob_g, scale_in, &bias_data[g], bias_term ? 0 : 1, opt_g);
dequantize_int32_to_float32(top_blob_g, scale_in, bias_term ? (const float*)bias_data + g : 0, bias_term ? 0 : 1, opt_g);
}

if (activation)
@@ -702,7 +702,7 @@ int ConvolutionDepthWise_arm::forward_int8_arm(const Mat& bottom_blob, Mat& top_
opt_g.blob_allocator = top_blob.allocator;

Mat top_blob_g = top_blob.channel(g);
dequantize_int32_to_float32(top_blob_g, scale_in, &bias_data[g], bias_term ? 0 : 1, opt_g);
dequantize_int32_to_float32(top_blob_g, scale_in, bias_term ? (const float*)bias_data + g : 0, bias_term ? 0 : 1, opt_g);
}

if (activation)


+ 2
- 2
src/layer/x86/convolution_x86.cpp View File

@@ -414,7 +414,7 @@ int Convolution_x86::forward_int8_x86(const Mat& bottom_blob, Mat& top_blob, con

float scale_out = top_blob_int8_scale;//FIXME load param

requantize_int8_to_int8(top_blob_tm_g, top_blob_g, scale_in, scale_out, &bias_data[p], bias_term ? 1 : 0, 0, opt_g);
requantize_int8_to_int8(top_blob_tm_g, top_blob_g, scale_in, scale_out, bias_term ? (const float*)bias_data + p : 0, bias_term ? 1 : 0, 0, opt_g);
}
}
else
@@ -461,7 +461,7 @@ int Convolution_x86::forward_int8_x86(const Mat& bottom_blob, Mat& top_blob, con
else
scale_in = 1.f / (bottom_blob_int8_scale * weight_data_int8_scales[p]);

dequantize_int32_to_float32(top_blob_g, scale_in, &bias_data[p], bias_term ? 1 : 0, opt_g);
dequantize_int32_to_float32(top_blob_g, scale_in, bias_term ? (const float*)bias_data + p : 0, bias_term ? 1 : 0, opt_g);
}
}
else


Loading…
Cancel
Save