1 #include "caffe2/core/logging.h" 2 #include "kl_minimization.h" 11 int main(
int argc,
const char* argv[]) {
13 cerr <<
"Usage: " << argv[0] <<
" in_file out_file [preserve_sparsity]" 19 ofstream out(argv[2]);
20 bool preserve_sparsity = argc >= 4 ? atoi(argv[3]) : false;
23 while (getline(in, line)) {
24 istringstream ist(line);
26 int op_index, output_index;
27 string op_type, tensor_name;
31 ist >> op_index >> op_type >> output_index >> tensor_name >> min >> max >>
34 vector<uint64_t> bins;
35 for (
int i = 0; i < nbins; ++i) {
40 assert(bins.size() == nbins);
43 TensorQuantizationParams qparams =
45 hist, preserve_sparsity);
47 out << op_index <<
" " << op_type <<
" " << output_index <<
" " 48 << tensor_name <<
" " << qparams.Min() <<
" " << qparams.Max() << endl;
A quantization scheme that minimizes Kullback-Leiber divergence.
bin_width = (max - min)/nbins ith bin (zero-based indexing) contains [i*bin_width, (i+1)*bin_width) with an exception that (nbins - 1)th bin contains [(nbins-1)*bin_width, nbins*bin_width]