-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathslam_trainer.cpp
More file actions
76 lines (66 loc) · 2.89 KB
/
slam_trainer.cpp
File metadata and controls
76 lines (66 loc) · 2.89 KB
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
75
76
#include "dataset_reader.h"
#include "slam_pipeline.h"
#include "InfiniTAM_tools.h"
int main(int argc, char *argv[])
{
std::cout << "ours trainer demo!" << std::endl;
const char *config_filename = argv[1];
YAML::Node config = YAML::LoadFile(config_filename);
std::string workspace_dir = config["workspace_dir"].as<std::string>();
std::string work_mode = config["work_mode"].as<std::string>();
// setup cout precision
std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
// setup cuda device
const std::string devId = config["dev_id"].as<std::string>();
setenv("CUDA_VISIBLE_DEVICES", devId.c_str(), 1);
std::cout << "======= load camera data ======" << std::endl;
DatasetReader data_reader(config["READER"]);
data_reader.read();
data_reader.updateSceneGeo();
std::cout << "======= Convert InfiniTAM data ======" << std::endl;
CLIEngine *tsdf_engine = createTsdfEngine(data_reader, config["PIPE"]["TSDF"]);
SLAMPipeline pipe;
pipe.setTsdfEngine(tsdf_engine);
pipe.work_mode = work_mode;
pipe.device_id = config["dev_id"].as<int>();
if (work_mode == "train" || work_mode == "recon")
{
std::cout << "======= setup Gaussian model ======" << std::endl;
SLAMGaussianModel model;
model.loadConfig(config["MODEL"]);
std::cout << "======= setup training pipe ======" << std::endl;
pipe.scene_scale = data_reader.scene_scale;
createWorkSpace(config_filename);
pipe.loadConfig(config["PIPE"], workspace_dir, true);
std::cout << "======= start training ======" << std::endl;
pipe.SLAMTrainCams(model, data_reader.train_vec);
std::cout << "train finish" << std::endl;
std::cout << "keyframe num: " << pipe.keyframe_cam_list.size() << std::endl;
if (pipe.save_after_train)
{
std::cout << "======= save model, mesh and tsdf ======" << std::endl;
pipe.save(model, data_reader.getAllCams());
pipe.saveEngine();
pipe.saveMesh();
data_reader.savePose(pipe.eval_path + "/pose");
}
if (pipe.eval_after_train)
{
std::cout << "======= render eval images ======" << std::endl;
pipe.renderEvalImgs(model, data_reader.train_vec, {"rgb"});
}
}
else if (work_mode == "eval")
{
std::cout << "======= setup Gaussian model ======" << std::endl;
SLAMGaussianModel model;
model.loadConfig(config["MODEL"]);
model.loadParamsTensor(workspace_dir + "/gs_model/model.pt");
std::cout << "======= setup eval pipe ======" << std::endl;
pipe.scene_scale = data_reader.scene_scale;
pipe.loadConfig(config["PIPE"], workspace_dir, false);
pipe.loadEngine();
std::cout << "======= start eval ======" << std::endl;
pipe.renderEvalImgs(model, data_reader.train_vec, {"rgb"});
}
}