SegNet-Tutorial icon indicating copy to clipboard operation
SegNet-Tutorial copied to clipboard

solver_factory.hpp error: ‘const class caffe::SolverParameter’ has no member named ‘type’

Open marwaSaid opened this issue 9 years ago • 2 comments

I am working on ubuntu 14 and compiled caffe as described on its official website of Berkely I want to compile my code by including some caffe functions using qmake here is the .pro file

`TEMPLATE = app CONFIG += console c++11 CONFIG -= app_bundle CONFIG -= qt

SOURCES += ../main.cpp

INCLUDEPATH += "pkg-config opencv --cflags" INCLUDEPATH += /home/user1/caffe/src INCLUDEPATH += /usr/include INCLUDEPATH += /home/user1/caffe/build/include INCLUDEPATH += /home/user1/caffe/include INCLUDEPATH += /usr/include/atlas INCLUDEPATH += /usr/include/opencv INCLUDEPATH += /usr/local/cuda/include INCLUDEPATH += /usr/local/include INCLUDEPATH += /usr/include/opencv

LIBS += pkg-config opencv --libs LIBS += -L/usr/lib/x86_64-linux-gnu/ -lboost_system -lboost_thread -lboost_filesystem -lpthread -lglog -lgflags -lprotobuf -lhdf5_hl -lhdf5 -lhdf5_hl -llmdb -lleveldb -lcuda

LIBS += -L/usr/lib/ -lsnappy -llapack -lcblas -latlas LIBS += -L/home/user1/caffe/build/lib/ -lcaffe LIBS += -L/home/user1/caffe/build/install/lib/ -lcaffe LIBS += -L/home/user1/caffe/build/lib/ -lproto LIBS += -L/usr/local/cuda/lib64/ -lcudart -lcublas -lcurand `

And this is the main file

`#ifdef WITH_PYTHON_LAYER #include "boost/python.hpp" namespace bp = boost::python; #endif

#include <gflags/gflags.h> #include <glog/logging.h>

#include #include #include #include

#include "boost/algorithm/string.hpp" #include "caffe/caffe.hpp" #include "caffe/util/signal_handler.h"

using caffe::Blob; using caffe::Caffe; using caffe::Net; using caffe::Layer; using caffe::Solver; using caffe::shared_ptr; using caffe::string; using caffe::Timer; using caffe::vector; using std::ostringstream;

static void get_gpus(vector* gpus,string gpu) { if (gpu == "all") { int count = 0; #ifndef CPU_ONLY CUDA_CHECK(cudaGetDeviceCount(&count)); #else NO_GPU; #endif for (int i = 0; i < count; ++i) { gpus->push_back(i); } } else if (gpu.size()) { vector strings; boost::split(strings, gpu, boost::is_any_of(",")); for (int i = 0; i < strings.size(); ++i) { gpus->push_back(boost::lexical_cast(strings[i])); } } else { CHECK_EQ(gpus->size(), 0); } }

// Device Query: show diagnostic information for a GPU device. int device_query(string gpu) { std::cout << "Querying GPUs " << gpu<<std::endl; vector gpus; get_gpus(&gpus,gpu); for (int i = 0; i < gpus.size(); ++i) { caffe::Caffe::SetDevice(gpus[i]); caffe::Caffe::DeviceQuery(); } return 0; }

// Load the weights from the specified caffemodel(s) into the train and // test nets. void CopyLayers(caffe::Solver* solver, const std::string& model_list) { std::vectorstd::string model_names; boost::split(model_names, model_list, boost::is_any_of(",") ); for (int i = 0; i < model_names.size(); ++i) { LOG(INFO) << "Finetuning from " << model_names[i]; solver->net()->CopyTrainedLayersFrom(model_names[i]); for (int j = 0; j < solver->test_nets().size(); ++j) { solver->test_nets()[j]->CopyTrainedLayersFrom(model_names[i]); } } }

// Train / Finetune a model. int train(string solverFile, string weightFile){//,string gpu) { if(solverFile.empty()){ std::cout<<"Need a solver definition to train. "<<std::endl; }

caffe::SolverParameter solver_param;
caffe::ReadSolverParamsFromTextFileOrDie(solverFile, &solver_param);


// If the gpus flag is not provided, allow the mode and device to be set
// in the solver prototxt.

string gpu;
if (gpu.size() == 0 && solver_param.solver_mode() == caffe::SolverParameter_SolverMode_GPU){
   if (solver_param.has_device_id()) {
        gpu = "" +  boost::lexical_cast<string>(solver_param.device_id());
    }
    else {  // Set default GPU if unspecified
        gpu = "" + boost::lexical_cast<string>(0);
    }
}

vector<int> gpus;
get_gpus(&gpus,gpu);
if (gpus.size() == 0) {
    std::cout << "Use CPU."<<std::endl;
    Caffe::set_mode(Caffe::CPU);
}
else {
    ostringstream s;
    for (int i = 0; i < gpus.size(); ++i) {
        s << (i ? ", " : "") << gpus[i];
    }
    LOG(INFO) << "Using GPUs " << s.str();

#ifndef CPU_ONLY cudaDeviceProp device_prop; for (int i = 0; i < gpus.size(); ++i) { cudaGetDeviceProperties(&device_prop, gpus[i]); std::cout << "GPU " << gpus[i] << ": " << device_prop.name<<std::endl;

    }

#endif solver_param.set_device_id(gpus[0]); Caffe::SetDevice(gpus[0]); Caffe::set_mode(Caffe::GPU); Caffe::set_solver_count(gpus.size()); } boost::shared_ptr<caffe::Solver > solver(caffe::SolverRegistry::CreateSolver(solver_param)); if (weightFile.size()) { CopyLayers(solver.get(), weightFile); }

if (gpus.size() > 1) {
    caffe::P2PSync<float> sync(solver, NULL, solver->param());
    sync.Run(gpus);
}
else {
    std::cout << "Starting Optimization"<<std::endl;
    solver->Solve();
}
std::cout << "Optimization Done."<<std::endl;
//delete solver;
return 0;

}

int main() { string filename="solver.prototxt"; train(filename,""); } `

I got this error

In file included from ../../user1/include/caffe/solver.hpp:8:0, from ../../user1/include/caffe/parallel.hpp:13, from ../../user1/include/caffe/caffe.hpp:13, from ../main.cpp:15: ../../user1/include/caffe/solver_factory.hpp: In static member function ‘static caffe::Solver<Dtype>* caffe::SolverRegistry<Dtype>::CreateSolver(const caffe::SolverParameter&)’: ../../user1/include/caffe/solver_factory.hpp:74:32: error: ‘const class caffe::SolverParameter’ has no member named ‘type’ const string& type = param.type();

marwaSaid avatar Nov 04 '16 03:11 marwaSaid

@marwaSaid, the problem was solved?

Maxfashko avatar Jul 28 '17 06:07 Maxfashko

how did you solve the problem?

AlexGbenimachor avatar Oct 30 '17 04:10 AlexGbenimachor