本文整理汇总了C++中SolverParameter类的典型用法代码示例。如果您正苦于以下问题:C++ SolverParameter类的具体用法?C++ SolverParameter怎么用?C++ SolverParameter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SolverParameter类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InitSolverFromProtoString
virtual void InitSolverFromProtoString(const string& proto) {
SolverParameter param;
CHECK(google::protobuf::TextFormat::ParseFromString(proto, ¶m));
// Set the solver_mode according to current Caffe::mode.
switch (Caffe::mode()) {
case Caffe::CPU:
param.set_solver_mode(SolverParameter_SolverMode_CPU);
break;
case Caffe::GPU:
param.set_solver_mode(SolverParameter_SolverMode_GPU);
break;
default:
LOG(FATAL) << "Unknown Caffe mode: " << Caffe::mode();
}
solver_.reset(new SGDSolver<Dtype>(param));
}
示例2: blob_shape_by_name
SolverParameter ModelServer<Dtype>::prepare_model() {
NetParameter net;
solver->net()->ToProto(&net);
for (int i = 0; i < net.layer_size(); ++i) {
LayerParameter& layer = *net.mutable_layer(i);
layer.clear_blobs();
if ((layer.type().find("Data") != std::string::npos)
&& (layer.has_remote_data_param())) {
layer.set_type("RemoteData");
for (int j = 0; j < layer.top_size(); ++j) {
*layer.mutable_remote_data_param()->add_shape()
= blob_shape_by_name(layer.top(j));
}
}
}
SolverParameter ret = solver->param();
ret.clear_net();
ret.clear_net_param();
ret.clear_test_net();
ret.clear_test_net_param();
ret.clear_train_net();
*ret.mutable_train_net_param() = net;
return ret;
}
示例3: LOG
P2PSync<Dtype>::P2PSync(shared_ptr<Solver<Dtype> > root_solver,
P2PSync<Dtype>* parent, const SolverParameter& param)
: GPUParams<Dtype>(root_solver, param.device_id()),
parent_(parent),
children_(),
queue_(),
initial_iter_(root_solver->iter()),
solver_() {
#ifndef CPU_ONLY
int initial_device;
CUDA_CHECK(cudaGetDevice(&initial_device));
const int self = param.device_id();
CUDA_CHECK(cudaSetDevice(self));
if (parent == NULL) {
solver_ = root_solver;
} else {
Caffe::set_root_solver(false);
solver_.reset(new WorkerSolver<Dtype>(param, root_solver.get()));
Caffe::set_root_solver(true);
}
this->configure(solver_.get());
solver_->add_callback(this);
if (parent) {
// Enable p2p access between devices
const int peer = parent->solver_->param().device_id();
int access;
CUDA_CHECK(cudaDeviceCanAccessPeer(&access, self, peer));
if (access) {
CUDA_CHECK(cudaDeviceEnablePeerAccess(peer, 0));
} else {
LOG(INFO)<< "GPU " << self << " does not have p2p access to GPU " << peer;
}
// Allocate receiving buffer on parent
CUDA_CHECK(cudaSetDevice(peer));
CUDA_CHECK(cudaMalloc(&parent_grads_, size_ * sizeof(Dtype)));
CUDA_CHECK(cudaSetDevice(self));
}
CUDA_CHECK(cudaSetDevice(initial_device));
#else
NO_GPU;
#endif
}
示例4:
int
SolverHooks::setOption(const char *optionname, Value val, Simulation *S){
/* FIXME need to check if the system is built? */
/* FIXME check if we have got a solver assigned? */
SolverParameters pp = S->getParameters();
try{
SolverParameter p = pp.getParameter(optionname);
try{
p.setValueValue(val);
}catch(std::runtime_error E){
return SLVREQ_WRONG_OPTION_VALUE_TYPE;
}
}catch(std::runtime_error E){
return SLVREQ_INVALID_OPTION_NAME;
}
return 0;
}
示例5: InitSolverFromProtoString
virtual void InitSolverFromProtoString(const string& proto) {
SolverParameter param;
CHECK(google::protobuf::TextFormat::ParseFromString(proto, ¶m));
// Disable saving a final snapshot so the tests don't pollute the user's
// working directory with useless snapshots.
param.set_snapshot_after_train(false);
// Set the solver_mode according to current Caffe::mode.
switch (Caffe::mode()) {
case Caffe::CPU:
param.set_solver_mode(SolverParameter_SolverMode_CPU);
break;
case Caffe::GPU:
param.set_solver_mode(SolverParameter_SolverMode_GPU);
break;
default:
LOG(FATAL) << "Unknown Caffe mode: " << Caffe::mode();
}
solver_.reset(new MockSGDSolver(param));
}
示例6: InitSolverFromProtoString
virtual void InitSolverFromProtoString(const string& proto) {
SolverParameter param;
CHECK(google::protobuf::TextFormat::ParseFromString(proto, ¶m));
// Set the solver_mode according to current Caffe::mode.
switch (Caffe::mode()) {
case Caffe::CPU:
param.set_solver_mode(SolverParameter_SolverMode_CPU);
break;
case Caffe::GPU:
param.set_solver_mode(SolverParameter_SolverMode_GPU);
break;
default:
LOG(FATAL) << "Unknown Caffe mode: " << Caffe::mode();
}
InitSolver(param);
delta_ = (solver_type() == SolverParameter_SolverType_ADAGRAD ||
solver_type() == SolverParameter_SolverType_RMSPROP) ?
param.delta() : 0;
}
示例7: LOG
void Solver<Dtype>::Init(const SolverParameter& param) {
LOG(INFO) << "Initializing solver from parameters: " << std::endl
<< param.DebugString();
param_ = param;
if (param_.random_seed() >= 0) {
Caffe::set_random_seed(param_.random_seed());
}
// Scaffolding code
InitTrainNet();
InitTestNets();
LOG(INFO) << "Solver scaffolding done.";
}
示例8: LOG
void Solver<Dtype>::Init(const SolverParameter& param) {
LOG(INFO) << "Initializing solver from parameters: " << std::endl
<< param.DebugString();
param_ = param;
CHECK_GE(param_.average_loss(), 1) << "average_loss should be non-negative.";
if (param_.random_seed() >= 0) {
Caffe::set_random_seed(param_.random_seed());
}
// Scaffolding code
InitTrainNet();
InitTestNets();
LOG(INFO) << "Solver scaffolding done.";
iter_ = 0;
current_step_ = 0;
}
示例9: CHECK
void Solver<Dtype>::Init(const SolverParameter& param) {
CHECK(Caffe::root_solver() || root_solver_)
<< "root_solver_ needs to be set for all non-root solvers";
LOG_IF(INFO, Caffe::root_solver()) << "Initializing solver from parameters: "
<< std::endl << param.DebugString();
param_ = param;
CHECK_GE(param_.average_loss(), 1) << "average_loss should be non-negative.";
CheckSnapshotWritePermissions();
if (Caffe::root_solver() && param_.random_seed() >= 0) {
Caffe::set_random_seed(param_.random_seed());
}
// Scaffolding code
InitTrainNet();
if (Caffe::root_solver()) {
InitTestNets();
LOG(INFO) << "Solver scaffolding done.";
}
iter_ = 0;
current_step_ = 0;
}
示例10: runtime_error
const string
SolverParameters::toString() const{
stringstream ss;
ss << "SOLVERPARAMETERS:TOSTRING:" << endl;
ss << "Number of parameters: " << p.num_parms << endl;
iterator i;
for(i = begin(); i<end(); ++i){
SolverParameter p = *i;
#if 0
ss << p.getLabel() << " [" << p.getDescription() << "]: ";
#else
ss << p.getName() << ": ";
#endif
if(p.isInt()){
ss << p.getIntValue();
}else if(p.isReal()){
ss << p.getRealValue();
}else if(p.isBool()){
ss << (p.getBoolValue() ? "true" : "false");
}else if(p.isStr()){
ss << p.getStrValue();
}else{
throw runtime_error("Unhandled case");
}
ss << endl;
}
return ss.str();
}