SkimCaffe icon indicating copy to clipboard operation
SkimCaffe copied to clipboard

sparse resnet model

Open dongxiao92 opened this issue 5 years ago • 1 comments

Issue summary

I'd like to use the sparse resnet model. I have downloaded the model from "SkimCaffe/models/resnet/ResNet-50-model.caffemodel.bz2" and loaded it using caffe c++ interface. But when iterating the entry of convolution parameters, I find it seems no entry has the exact 0 value. Instead, the values are very small and close to 0.
So I'd like to know if there is some threasholds. Or I downloaded the wrong model.

Steps to reproduce

  1. download the model from "SkimCaffe/models/resnet/ResNet-50-model.caffemodel.bz2" and unzip it.
  2. load the model using caffe c++ interface
/**
 * Parse the caffemodel based on the model path.
 **/
bool ParseCaffeModel(const string&caffemodel_path, caffe::NetParameter&param){
    //use coded stream to increase the size limit.
    int fd = open(caffemodel_path.c_str(), O_RDONLY);
    if(fd == -1){
        cerr<<"failed to parse caffemodel:"<<caffemodel_path<<endl;
        return false;
    }   
    ZeroCopyInputStream* raw_input = new FileInputStream(fd);
    CodedInputStream* coded_input = new CodedInputStream(raw_input);
    coded_input->SetTotalBytesLimit(1024*1024*512, 1024*1024*256);
    param.ParseFromCodedStream(coded_input);
    
    delete coded_input;
    delete raw_input;
    close(fd);
    return true;
}
  1. iterate the entries
//find convolution layers and get weight blob
caffe::BlobProto weights = layer.blobs(0);
    for(int k=0; k<filter_number; k+=1){
            const float*data = weights.mutable_data()->data()+k*filter_size;
            for(int i=0; i<filter_size; i+=1){
                float val = data[i];
                cout<<"val "<<i<<":"<<val<<endl;
                if( val == static_cast<float>(0) ){
                    zero_count += 1;
                }else{
                    //record the coordinate
                    coos.push_back(make_pair(k,i));
                }
            }
        }
        //layer type information, layer name
        cout<<layer.type()<<","<<layer.name()<<","<<zero_count<<endl;

the nnz_count is zero.

Your system configuration

Operating system: Ubuntu 16.04 Compiler: gcc (Ubuntu 5.4.0-6ubuntu1~16.04.10) 5.4.0 20160609

dongxiao92 avatar Oct 26 '18 08:10 dongxiao92

Please grab the one in SkimCaffe/models/resnet/logs/0.0001_0.00005_0.0001_10_0_0_0_0_2017-04-02-22-29-02/

jspark1105 avatar Nov 28 '18 17:11 jspark1105