(self, epoch=0)
| 214 | |
| 215 | @torch.no_grad() |
| 216 | def validate(self, epoch=0): |
| 217 | self.network.eval() |
| 218 | |
| 219 | if is_main_process(): |
| 220 | pwidgets = [progressbar.Percentage(), " ", progressbar.Counter(format='%(value)02d/%(max_value)d'), " ", progressbar.Bar(), " ", |
| 221 | progressbar.Timer(), ",", progressbar.ETA(), ",", progressbar.Variable('Loss', width=1), ",", |
| 222 | progressbar.Variable('Th2', width=1), ",", progressbar.Variable('Th4', width=1), ",", |
| 223 | progressbar.Variable('Th8', width=1)] |
| 224 | pbar = progressbar.ProgressBar(widgets=pwidgets, max_value=len(self.val_loader), prefix="Val:").start() |
| 225 | |
| 226 | avg_scalars = DictAverageMeter() |
| 227 | |
| 228 | if not self.blendmvs: |
| 229 | color_y=torch.zeros((3,512,640)).cuda() |
| 230 | color_g=torch.zeros((3,512,640)).cuda() |
| 231 | else: |
| 232 | color_y=torch.zeros((3,576,768)).cuda() |
| 233 | color_g=torch.zeros((3,576,768)).cuda() |
| 234 | color_y[1]=1. |
| 235 | color_y[0]=1. |
| 236 | color_g[1]=1. |
| 237 | for batch, data in enumerate(self.val_loader): |
| 238 | data = tocuda(data) |
| 239 | |
| 240 | outputs = self.network(data["imgs"], data["proj_matrices"], data["depth_values"]) |
| 241 | |
| 242 | loss = self.loss_func(outputs, data["depth"], data["mask"], self.args.depth_mode, dlossw=self.args.dlossw) |
| 243 | |
| 244 | gt_depth = data["depth"]["stage{}".format(len(self.args.ndepths))] |
| 245 | mask = data["mask"]["stage{}".format(len(self.args.ndepths))] |
| 246 | thres2mm = Thres_metrics(outputs["depth"], gt_depth, mask > 0.5, 2) |
| 247 | thres4mm = Thres_metrics(outputs["depth"], gt_depth, mask > 0.5, 4) |
| 248 | thres8mm = Thres_metrics(outputs["depth"], gt_depth, mask > 0.5, 8) |
| 249 | abs_depth_error = AbsDepthError_metrics(outputs["depth"], gt_depth, mask > 0.5) |
| 250 | |
| 251 | |
| 252 | |
| 253 | scalar_outputs = {"loss": loss, |
| 254 | "abs_depth_error": abs_depth_error, |
| 255 | "thres2mm_error": thres2mm, |
| 256 | "thres4mm_error": thres4mm, |
| 257 | "thres8mm_error": thres8mm, |
| 258 | |
| 259 | } |
| 260 | |
| 261 | up_dn_mask=((mask>0)&((outputs["depth"] - gt_depth).abs()<2)).unsqueeze(1) |
| 262 | up_dn=torch.where((outputs["depth"]>gt_depth).unsqueeze(1).repeat(1,3,1,1),color_g.unsqueeze(0).repeat(outputs["depth"].shape[0],1,1,1),color_y.unsqueeze(0).repeat(outputs["depth"].shape[0],1,1,1)) |
| 263 | |
| 264 | |
| 265 | image_outputs = {"depth_est": outputs["depth"] * mask, |
| 266 | "depth_est_nomask": outputs["depth"], |
| 267 | "ref_img": data["imgs"][:, 0], |
| 268 | "mask": mask, |
| 269 | "conf":outputs["photometric_confidence"], |
| 270 | "conf_09mask":(outputs["photometric_confidence"]>0.9).float(), |
| 271 | "conf_05mask":(outputs["photometric_confidence"]>0.5).float(), |
| 272 | "conf_01mask":(outputs["photometric_confidence"]>0.1).float(), |
| 273 | "errormap": (outputs["depth"] - gt_depth).abs().clip(0,2) * mask, |
no test coverage detected