caffe源码解析 — train_net.cpp

train_net.cpp是caffe的主函数所在处,学习caffe时应该由此辐射到各个具体的函数去学习。
  1. 调用ReadProtoFromTextFileOrDie()从argv[1]中读入solver_param:
    SolverParameter solver_param
  2. 用solver_param去初始化solver,solverSGDSolver:
    solver(solver_param)
  3. 调用solver的Solve函数,solver.Solve(argv[2])solver.Solve()

train_net.cpp

int main(int argc, char** argv) {
  ::google::InitGoogleLogging(argv[0]);
  ::google::SetLogDestination(0, "../tmp/");
  if (argc < 2 || argc > 3) {
    LOG(ERROR) << "Usage: train_net solver_proto_file [resume_point_file]";
    return 1;
  }
  SolverParameter solver_param;
  ReadProtoFromTextFileOrDie(argv[1], &solver_param);

  LOG(INFO) << "Starting Optimization";
  SGDSolver<float> solver(solver_param);
  if (argc == 3) {
    LOG(INFO) << "Resuming from " << argv[2];
    solver.Solve(argv[2]);
  } else {
    solver.Solve();
  }
  LOG(INFO) << "Optimization Done.";

  return 0;
}

你可能感兴趣的:(源码,caffe)