@@ -23,11 +23,19 @@ void SoftmaxLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
2323 scale_.Reshape (scale_dims);
2424 input_scale_ = this ->layer_param_ .softmax_param ().input_scale (); // CUSTOMIZATION
2525 output_scale_ = this ->layer_param_ .softmax_param ().output_scale (); // CUSTOMIZATION
26+ input_zero_point_ = this ->layer_param_ .softmax_param ().input_zero_point (); // CUSTOMIZATION
27+ output_zero_point_ = this ->layer_param_ .softmax_param ().output_zero_point (); // CUSTOMIZATION
2628}
2729
2830template <typename Dtype>
2931void SoftmaxLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
3032 const vector<Blob<Dtype>*>& top) {
33+ const bool quant_in = (input_scale_ != Dtype (1.0 ) || input_zero_point_ != 0 );
34+ const bool quant_out = (output_scale_ != Dtype (1.0 ) || output_zero_point_ != 0 );
35+ if (quant_in) {
36+ caffe_cpu_dequantize<Dtype>(bottom[0 ]->count (), bottom[0 ]->mutable_cpu_data (),
37+ input_scale_, input_zero_point_);
38+ }
3139 const Dtype* bottom_data = bottom[0 ]->cpu_data ();
3240 Dtype* top_data = top[0 ]->mutable_cpu_data ();
3341 Dtype* scale_data = scale_.mutable_cpu_data ();
@@ -59,6 +67,14 @@ void SoftmaxLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
5967 top_data += inner_num_;
6068 }
6169 }
70+ if (quant_out) {
71+ // do not reuse "top_data"; it is shifted during the computation
72+ caffe_cpu_quantize<Dtype>(top[0 ]->count (), top[0 ]->mutable_cpu_data (), output_scale_, output_zero_point_);
73+ }
74+ if (quant_in) {
75+ caffe_cpu_quantize<Dtype>(bottom[0 ]->count (), bottom[0 ]->mutable_cpu_data (),
76+ input_scale_, input_zero_point_);
77+ }
6278}
6379
6480template <typename Dtype>
0 commit comments