• 大小: 13.12MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-09
  • 语言: 其他
  • 标签: 代码  

资源简介

CLIP-Q: Deep Network Compression Learning by In-Parallel Pruning-Quantization,CVPR2018 code

资源截图

代码片段和文件信息

% Updated decode_sparse_quantized_net.m to match
% encode_sparse_quantized_net_v2.m
function decode_sparse_quantized_net_v2(non_wq_prototxt sqnet_dat)

net = caffe.Net(non_wq_prototxt ‘test‘);

fid = fopen(sqnet_dat ‘r‘);

for j = 1 : length(net.layer_names)
    if ~isempty(net.layers(net.layer_names{j}).params)
        is_quantized = fread(fid 1);
        if is_quantized
            if length(net.layers(net.layer_names{j}).params) == 2
                % Read count of bias terms then bias terms as floats
                n = fread(fid 1 ‘single‘);
                bias = fread(fid n ‘single‘);
                net.layers(net.layer_names{j}).params(2).set_data(bias);
            end

            % Read count of codewords then codewords as floats
            n = fread(fid 1 ‘single‘);
            codewords = fread(fid n ‘single‘);

            % Read ‘diff‘ and ‘value‘ arrays (Fig. 2 in Han et al. 2016)
            n = fread(fid 1 ‘single‘); % length of diff/value arrays 
            best_c = fread(fid 1);
            b = fread(fid 1);
            diffs_bin = fread(fid ceil(n*best_c/8) ‘*uint8‘);
            values_bin = fread(fid ceil(n*b/8) ‘*uint8‘);
            diffs = unpack_bit_vector(diffs_bin best_c) + 1;
            values = unpack_bit_vector(values_bin b);
            assert(length(diffs) >= n && length(values) >= n);

            % Decode weights
            w_decoded = zeros(size(net.layers(net.layer_names{j}).params(1).get_data));
            pos = 0;
            for k = 1 : n
                pos = pos + diffs(k);
                if values(k) > 0
                    w_decoded(pos) = codewords(values(k));
                end
            end
            net.layers(net.layer_names{j}).params(1).set_data(w_decoded);
        else
            for k = 1 : length(net.layers(net.layer_names{j}).params)
                w = net.layers(net.layer_names{j}).params(k).get_data;
                if ndims(w) == 4 && size(w1) == 1 && size(w2) == 1
                    w(11::) = fread(fid [size(w3) size(w4)] ‘*single‘);
                else
                    w = fread(fid size(w) ‘*single‘);
                end
                net.layers(net.layer_names{j}).params(k).set_data(w);
            end
        end
        fprintf(‘Finished decoding %s\n‘ net.layer_names{j});
    end
end
net.save(‘decoded_net.caffemodel‘);
caffe.reset_all();
fclose(fid);

end

% % Packs integer values between 0 and 2^(b-1) into bit string
% function B = pack_bit_vector(values b)

% B = zeros(ceil(length(values)*b/8) 1 ‘uint8‘);
% m = 1;
% for k = 1 : length(values)
%     s = dec2bin(values(k) b);
%     assert(length(s) <= b)
%     for l = 1 : b
%         if s(l) == ‘1‘
%             row = ceil(m/8);
%             col = mod(m-18)+1;
%             B(row) = bitset(B(row) col);
%         end
%         m = m + 1;
%     end
% end

% end

function values = unpack_bit_vector(B b)

values = zeros(floor(length(B)*8/b) 1);
m = 1;
for i = 1 : le

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-03-22 16:35  caffe-files\
     目录           0  2018-01-11 16:54  caffe-files\include\
     目录           0  2018-01-11 16:54  caffe-files\include\caffe\
     目录           0  2018-01-11 16:54  caffe-files\include\caffe\layers\
     文件        2826  2017-07-18 16:30  caffe-files\include\caffe\layers\weight_quant_conv_layer.hpp
     文件        1968  2017-07-18 16:30  caffe-files\include\caffe\layers\weight_quant_inner_product_layer.hpp
     目录           0  2018-01-11 16:54  caffe-files\include\caffe\util\
     文件         740  2017-07-31 17:02  caffe-files\include\caffe\util\eh_functions.hpp
     文件        1178  2018-03-22 16:15  caffe-files\instructions.txt
     目录           0  2018-01-11 16:53  caffe-files\src\
     目录           0  2018-01-11 16:53  caffe-files\src\caffe\
     目录           0  2018-03-22 16:10  caffe-files\src\caffe\layers\
     文件       12510  2017-08-10 15:12  caffe-files\src\caffe\layers\weight_quant_conv_layer.cpp
     文件        5727  2018-03-22 16:07  caffe-files\src\caffe\layers\weight_quant_conv_layer.cu
     文件        8016  2017-08-10 15:12  caffe-files\src\caffe\layers\weight_quant_inner_product_layer.cpp
     文件        4281  2018-03-22 16:10  caffe-files\src\caffe\layers\weight_quant_inner_product_layer.cu
     目录           0  2018-01-11 16:58  caffe-files\src\caffe\util\
     文件       12288  2018-01-11 16:58  caffe-files\src\caffe\util\eh_functions.cu
     文件        3214  2017-12-02 15:21  decode_sparse_quantized_net_v2.m
     文件        4480  2017-12-02 14:50  encode_sparse_quantized_net_v2.m
     文件        2226  2018-01-08 12:52  get_layer_storage_req.m
     目录           0  2017-04-03 10:35  mlcircus-bayesopt\
     文件         174  2015-04-03 10:02  mlcircus-bayesopt\.hg_archival.txt
     文件         215  2015-04-03 10:02  mlcircus-bayesopt\README.md
     文件       18772  2015-04-03 10:02  mlcircus-bayesopt\bayesopt.m
     目录           0  2017-04-03 10:35  mlcircus-bayesopt\demo\
     文件         419  2015-04-03 10:02  mlcircus-bayesopt\demo\defaultopt.m
     文件        2539  2015-04-03 10:02  mlcircus-bayesopt\demo\demo.m
     文件         846  2015-04-03 10:02  mlcircus-bayesopt\demo\samplef.m
     目录           0  2017-04-03 10:35  mlcircus-bayesopt\gpml\
     文件           8  2015-04-03 10:02  mlcircus-bayesopt\gpml\.octaverc
............此处省略208个文件信息

评论

共有 条评论