-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain_r50fpn.cpp
74 lines (67 loc) · 2.03 KB
/
train_r50fpn.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <algorithm>
#include <filesystem>
#include <ios>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include <boost/program_options.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include "trainer.h"
int main(int argc, char **argv)
{
std::string config_file_path;
int gpu_id = -1;
try
{
boost::program_options::options_description train_options_desc("Model training options");
// clang-format off
train_options_desc.add_options()
("help,h", "help guide")
("path,p", boost::program_options::value(&config_file_path)->default_value("./config/faster_rcnn_r50_fpn_1x_voc.json"), "config file path")
("gpu,g", boost::program_options::value(&gpu_id), "id of gpu");
// clang-format on
boost::program_options::variables_map vm;
// if (argc < 2)
// {
// std::cerr << train_options_desc << std::endl;
// return -1;
// }
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, train_options_desc), vm);
if (vm.count("help") > 0)
{
std::cout << train_options_desc << std::endl;
return -1;
}
boost::program_options::notify(vm);
}
catch (const std::exception &e)
{
std::cerr << e.what() << '\n';
return -1;
}
try
{
if (std::filesystem::exists(config_file_path) == false)
{
std::cerr << config_file_path << " NOT exist, check path!" << '\n';
return -1;
}
boost::property_tree::ptree opts;
boost::property_tree::read_json(config_file_path, opts);
if (gpu_id != -1)
{
opts.put("gpu", gpu_id);
std::cout << "use gpu: " << opts.get("gpu", -1) << std::endl;
}
trainer::BasicTrainer m(opts);
m.train();
}
catch (std::exception &e)
{
std::cerr << e.what() << '\n';
return -1;
}
return 0;
}