Segmentation fault in PreSolve(), when initializing solver

22 views
Skip to first unread message

fiorato...@gmail.com

unread,
Nov 6, 2017, 1:14:22 AM11/6/17
to Caffe Users
Good morning everyone,

I have this issue when solver object is initialized and so the function PreSolve() is called. Below there is the error report with gdb.

I have some doubts on how the leveldb is created. So i put down here the code that i used to create the database:

int main(int argc, char** argv) {
    if (argc != 7){
        cout<<"option: name nData mean0 str0 mean1 str1"<<endl;
        return 0;
    }
    int dim = 2;
    const char* path = argv[1];
    int nData = atoi(argv[2]);
    Dtype mean_0 = atof(argv[3]);
    Dtype str_0 = atof(argv[4]);
    Dtype mean_1 = atof(argv[5]);
    Dtype str_1 = atof(argv[6]);

    // generate data from two 2-d gaussians
    Blob<Dtype>* const blob_data = new Blob<Dtype>(nData, dim, 1, 1);
    caffe_rng_gaussian<Dtype>(nData/2*dim, mean_0, str_0, blob_data->mutable_cpu_data());
    caffe_rng_gaussian<Dtype>(nData/2*dim, mean_1, str_1, blob_data->mutable_cpu_data()+blob_data->offset(nData/2,0,0,0));

    // open leveldb
    leveldb::DB* db;
    leveldb::Options options;
    options.error_if_exists = true;
    options.create_if_missing = true;
    options.write_buffer_size = 268435456;
    leveldb::WriteBatch* batch = NULL;
    leveldb::Status status = leveldb::DB::Open(options, path, &db);
    CHECK(status.ok()) << "Failed to open leveldb " << path
                       << ". Is it already existing?";
    batch = new leveldb::WriteBatch();

    // save to db
    const int kMaxKeyLength = 10;
    char key_cstr[kMaxKeyLength];

    leveldb::WriteOptions writeOptions;
    for (int item_id = 0; item_id < nData; ++item_id) {
        Datum datum;
        datum.set_channels(dim);
        datum.set_height(1);
        datum.set_width(1);

        datum.mutable_float_data()->Reserve(dim);
        for(int k=0;k<2;k++){
            datum.add_float_data(blob_data->cpu_data()[blob_data->offset(item_id,k,0,0)]);
        }

        if(item_id < nData/2)  datum.set_label(0);
        else datum.set_label(1);
        snprintf(key_cstr, kMaxKeyLength, "%08d", item_id);
        string keystr(key_cstr);
        db->Put(writeOptions, keystr, datum.SerializeAsString());
    }

    db->Write(leveldb::WriteOptions(), batch);
    delete batch;
    delete db;

    return 0;
}


And here is the error report:

I1106 15:01:45.541523 13838 layer_factory.hpp:77] Creating layer data
I1106 15:01:45.705741 13838 db_leveldb.cpp:18] Opened leveldb train_leveldb
I1106 15:01:45.706275 13838 net.cpp:84] Creating Layer data
I1106 15:01:45.706341 13838 net.cpp:380] data -> data
I1106 15:01:45.706445 13838 net.cpp:380] data -> label
I1106 15:01:45.706585 13838 data_layer.cpp:45] output data size: 200,2,1,1
[New Thread 0x7fffdc8fc700 (LWP 13847)]
I1106 15:01:45.707495 13838 net.cpp:122] Setting up data
I1106 15:01:45.707568 13838 net.cpp:129] Top shape: 200 2 1 1 (400)
I1106 15:01:45.707590 13838 net.cpp:129] Top shape: 200 (200)
I1106 15:01:45.707633 13838 net.cpp:137] Memory required for data: 4800
I1106 15:01:45.707659 13838 layer_factory.hpp:77] Creating layer ip
I1106 15:01:45.707713 13838 net.cpp:84] Creating Layer ip
I1106 15:01:45.707737 13838 net.cpp:406] ip <- data
I1106 15:01:45.707775 13838 net.cpp:380] ip -> ip
I1106 15:01:45.707849 13838 net.cpp:122] Setting up ip
I1106 15:01:45.707875 13838 net.cpp:129] Top shape: 200 2 (400)
I1106 15:01:45.707890 13838 net.cpp:137] Memory required for data: 8000
I1106 15:01:45.707963 13838 layer_factory.hpp:77] Creating layer loss
I1106 15:01:45.707993 13838 net.cpp:84] Creating Layer loss
I1106 15:01:45.708034 13838 net.cpp:406] loss <- ip
I1106 15:01:45.708055 13838 net.cpp:406] loss <- label
I1106 15:01:45.708083 13838 net.cpp:380] loss -> loss
I1106 15:01:45.708120 13838 layer_factory.hpp:77] Creating layer loss
I1106 15:01:45.708171 13838 net.cpp:122] Setting up loss
I1106 15:01:45.708195 13838 net.cpp:129] Top shape: (1)
I1106 15:01:45.708221 13838 net.cpp:132]     with loss weight 1
I1106 15:01:45.708261 13838 net.cpp:137] Memory required for data: 8008
I1106 15:01:45.708278 13838 net.cpp:198] loss needs backward computation.
I1106 15:01:45.708302 13838 net.cpp:198] ip needs backward computation.
I1106 15:01:45.708320 13838 net.cpp:200] data does not need backward computation.
I1106 15:01:45.708338 13838 net.cpp:242] This network produces output loss
I1106 15:01:45.708362 13838 net.cpp:255] Network initialization done.
I1106 15:01:45.708441 13838 solver.cpp:56] Solver scaffolding done.

Thread 1 "logreg_train" received signal SIGSEGV, Segmentation fault.
0x00007ffff7812426 in caffe::SGDSolver<double>::PreSolve() () from /home/nikfio/bin/caffe/build/lib/libcaffe.so.1.0.0
(gdb) bt
#0  0x00007ffff7812426 in caffe::SGDSolver<double>::PreSolve() () from /home/nikfio/bin/caffe/build/lib/libcaffe.so.1.0.0
#1  0x00000000004062a2 in caffe::SGDSolver<double>::SGDSolver(caffe::SolverParameter const&) ()
#2  0x00000000004057a6 in main ()


If you have ideas, please share them with me. Thank you.

Reply all
Reply to author
Forward
0 new messages