diff options
author | Manu Mathew | 2018-06-02 00:09:11 -0500 |
---|---|---|
committer | Manu Mathew | 2018-06-02 00:09:11 -0500 |
commit | d022dc6780ddf603a147252877ed246f16a471e6 (patch) | |
tree | 14567c72780eb75e2f552d1fe9d3ec107e9ae701 | |
parent | f4d32e8e9288dcea4f128d42e57210b538946a18 (diff) | |
download | caffe-jacinto-d022dc6780ddf603a147252877ed246f16a471e6.tar.gz caffe-jacinto-d022dc6780ddf603a147252877ed246f16a471e6.tar.xz caffe-jacinto-d022dc6780ddf603a147252877ed246f16a471e6.zip |
quantization - adding mixed (pow2) quantization
-rw-r--r-- | src/caffe/net.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/caffe/net.cpp b/src/caffe/net.cpp index e43adcf9..b8bfda1a 100644 --- a/src/caffe/net.cpp +++ b/src/caffe/net.cpp | |||
@@ -2122,7 +2122,7 @@ void Net::EnableQuantizationForSelectedLayers() { | |||
2122 | // << layer_type_next2 << ")" << std::endl; | 2122 | // << layer_type_next2 << ")" << std::endl; |
2123 | 2123 | ||
2124 | bool is_merged_layer = false; | 2124 | bool is_merged_layer = false; |
2125 | if(layer_type == "Convolution" || layer_type == "InnerProduct" || "Deconvolution") { | 2125 | if(layer_type == "Convolution" || layer_type == "InnerProduct" || layer_type == "Deconvolution") { |
2126 | if(layer_type_next == "BatchNorm" || layer_type_next == "Scale" || layer_type_next == "ReLU") { | 2126 | if(layer_type_next == "BatchNorm" || layer_type_next == "Scale" || layer_type_next == "ReLU") { |
2127 | is_merged_layer = true; | 2127 | is_merged_layer = true; |
2128 | } | 2128 | } |
@@ -2313,7 +2313,8 @@ void Net::SetQuantizationParamsLayerOutput(const int layer_id) { | |||
2313 | scale_applied_in_max = std::max(scale_applied_in_max, qparam_in.scale_applied()); | 2313 | scale_applied_in_max = std::max(scale_applied_in_max, qparam_in.scale_applied()); |
2314 | } | 2314 | } |
2315 | 2315 | ||
2316 | float scale_applied_w = (layer_type == "Convolution")? quantization_param.mutable_qparam_w(0)->scale_applied() : 1.0; | 2316 | float scale_applied_w = (layer_type == "Convolution" || layer_type == "InnerProduct" || layer_type == "Deconvolution")? |
2317 | quantization_param.mutable_qparam_w(0)->scale_applied() : 1.0; | ||
2317 | 2318 | ||
2318 | int num_top_vecs = top_vecs_[layer_id].size(); | 2319 | int num_top_vecs = top_vecs_[layer_id].size(); |
2319 | for(int blob_id = 0; blob_id<num_top_vecs; blob_id++) { | 2320 | for(int blob_id = 0; blob_id<num_top_vecs; blob_id++) { |
@@ -2335,7 +2336,7 @@ void Net::SetQuantizationParamsLayerOutput(const int layer_id) { | |||
2335 | int fracbits_out = qparam_out.fracbits(); | 2336 | int fracbits_out = qparam_out.fracbits(); |
2336 | 2337 | ||
2337 | int fracbits_weights = num_blobs>0? quantization_param.qparam_w(0).fracbits() : 0; | 2338 | int fracbits_weights = num_blobs>0? quantization_param.qparam_w(0).fracbits() : 0; |
2338 | if(layer_type == "Convolution") { | 2339 | if(layer_type == "Convolution" || layer_type == "InnerProduct" || layer_type == "Deconvolution") { |
2339 | //avoid left shift at output - will lose accuracy | 2340 | //avoid left shift at output - will lose accuracy |
2340 | if((fracbits_in + fracbits_weights) < fracbits_out) { | 2341 | if((fracbits_in + fracbits_weights) < fracbits_out) { |
2341 | fracbits_out = (fracbits_in + fracbits_weights); | 2342 | fracbits_out = (fracbits_in + fracbits_weights); |