IntelLabs / SkimCaffe

Caffe for Sparse Convolutional Neural Network
Other
238 stars 64 forks source link

sparse resnet model #20

Open dongxiao92 opened 5 years ago

dongxiao92 commented 5 years ago

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;
    }
  3. 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

jspark1105 commented 5 years ago

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/