-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
156 lines (129 loc) · 5.06 KB
/
Copy pathtest.py
File metadata and controls
156 lines (129 loc) · 5.06 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import torch
import spconv.pytorch as spconv
import logging
import yaml
import hydra
import os
import os.path as osp
import pytorch_lightning as pl
from omegaconf import DictConfig, OmegaConf
import matplotlib.pyplot as plt
plt.switch_backend('agg')
import multidti3d
logger = logging.getLogger(__name__)
@hydra.main(config_path="configs", config_name="test")
def main(cfg: DictConfig) -> None:
html = f"""
<html>
<head>
<style>
table {{
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}}
td, th {{
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}}
tr:nth-child(even) {{
background-color: #dddddd;
}}
</style>
</head>
<body>
<h1>Results</h1>
<table>
<tr>
<th>Experiment</th>
<th>Chamfer</th>
<th>mIoU</th>
<th>Acc</th>
<th>RGB</th>
<th>Intensity</th>
<th>Ground truth</th>
<th>Prediction</th>
<th>Instance pred</th>
<th>Rec intensity</th>
<th>Rec prediction</th>
<th>Protos</th>
<th>Protos labels</th>
<th>Report</th>
</tr>
"""
root = cfg.test.root
for xp in sorted(os.listdir(root)):
if osp.exists(osp.join(root, xp, "checkpoints")):
logger.info("")
logger.info(f"{xp}")
root_xp = osp.join(root, xp)
ckpts = osp.join(root_xp, "checkpoints")
epoch = 0
for ckpt in os.listdir(ckpts):
if "step" in ckpt and ckpt.endswith(".ckpt"):
this_epoch = int(ckpt.split("=")[-1].split(".")[0])
if this_epoch > epoch:
epoch = this_epoch
last_ckpt = osp.join(ckpts, ckpt)
overrides = osp.join(root_xp, ".hydra", "overrides.yaml")
with open(overrides, "r") as stream:
overrides = yaml.safe_load(stream)
cfg = hydra.compose(
config_name="defaults",
overrides=overrides + [
"hydra.searchpath=[file://../../../EarthParserDataset/configs]",
f"model.callbacks.outhtml.points_per_scene=0",
f"mode=test",
]
)
cfg.model.load_weights = last_ckpt
logger.info(f"{xp}\tcfg loaded : {last_ckpt}")
if cfg.seed != 0: pl.seed_everything(cfg.seed)
cfg.data._target_ = f"EarthParserDataset.{cfg.data._target_}"
datamodule = hydra.utils.instantiate(cfg.data)
datamodule.setup("train")
datamodule.setup("test")
logger.info(f"{xp}\tDatamodule loaded : {datamodule}")
model = hydra.utils.instantiate(
cfg.model,
_recursive_=False,
)
model.__initprotos__(datamodule)
if cfg.model.load_weights != "":
logger.info(f"{xp}\tLoading weights from {cfg.model.load_weights}")
model.load_state_dict(torch.load(cfg.model.load_weights)["state_dict"], strict=False)
trainer = multidti3d.trainers.get_trainer(cfg)
trainer.test(model, datamodule=datamodule)
if "fit" in cfg.model.load_weights:
modelname = model.hparams.load_weights.split("fit/")[-1].split("/")[0]
else:
modelname = model.hparams.load_weights.split("outputs/")[-1].split("/")[0]
html += f"""
<tr>
<td>{cfg.experiment}</td>
<td>{1000*trainer.logged_metrics['Losses/chamfer/test']:.3f}</td>
<td>{100*trainer.logged_metrics['IoU/test']:.3f}</td>
<td>{100*trainer.logged_metrics['Acc/test']:.3f}</td>
<td><img width=100px src="{cfg.data.name}_{modelname}_input_rgb_0.png"/></td>
<td><img width=100px src="{cfg.data.name}_{modelname}_input_intensity_0.png"/></td>
<td><img width=100px src="{cfg.data.name}_{modelname}_input_point_y_0.png"/></td>
<td><img width=100px src="{cfg.data.name}_{modelname}_input_point_y_pred_0.png"/></td>
<td><img width=100px src="{cfg.data.name}_{modelname}_input_point_inst_pred_0.png"/></td>
<td><img width=100px src="{cfg.data.name}_{modelname}_reconstruction_intensity_0.png"/></td>
<td><img width=100px src="{cfg.data.name}_{modelname}_reconstruction_point_y_0.png"/></td>
<td><img width=100px src="{cfg.data.name}_{modelname}_prototypes_rgb_0.png"/></td>
<td><img width=100px src="{cfg.data.name}_{modelname}_prototypes_point_y_0.png"/></td>
<td><a href="report_{cfg.data.name}_{modelname}_on_test_end.html">report_{cfg.data.name}_{modelname}_on_test_end.html</a></td>
</tr>
"""
logger.info("{xp}\tDone !")
del trainer, model, datamodule, cfg
html += """
</body>
</html>
"""
with open(f"index.html", "w") as f:
f.write(html)
if __name__ == '__main__':
main()