Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

sparse resnet model #20

@dongxiao92

Description

@dongxiao92

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions