text
stringlengths 1
93.6k
|
---|
depth_gt_ms = sample_cuda["depth"]
|
mask_ms = sample_cuda["mask"]
|
sigma_ms = sample_cuda["sigma"]
|
num_stage = len([int(nd) for nd in args.ndepths.split(",") if nd])
|
depth_gt = depth_gt_ms["stage{}".format(num_stage)]
|
mask = mask_ms["stage{}".format(num_stage)]
|
try:
|
outputs = model(sample_cuda["imgs"], sample_cuda["proj_matrices"], sample_cuda["depth_values"])
|
depth_est = outputs["depth"]
|
loss, depth_loss, kl, approx_kl, depth_wta = model_loss(outputs, depth_gt_ms,
|
sigma_ms, mask_ms, dlossw=[float(e) for e in args.dlossw.split(",") if e])
|
if np.isnan(loss.item()):
|
raise NanError
|
if is_distributed and args.using_apex:
|
with amp.scale_loss(loss, optimizer) as scaled_loss:
|
scaled_loss.backward()
|
else:
|
loss.backward()
|
optimizer.step()
|
except NanError:
|
print(f'nan error occur!!')
|
gc.collect()
|
torch.cuda.empty_cache()
|
scalar_outputs = {"loss": loss,
|
"depth_loss": depth_loss,
|
"kl_loss": kl,
|
"approx_kl": approx_kl,
|
"abs_depth_error": AbsDepthError_metrics(depth_est, depth_gt, mask > 0.5),
|
"thres2mm_error": Thres_metrics(depth_est, depth_gt, mask > 0.5, 2),
|
"thres4mm_error": Thres_metrics(depth_est, depth_gt, mask > 0.5, 4),
|
"thres8mm_error": Thres_metrics(depth_est, depth_gt, mask > 0.5, 8),}
|
image_outputs = {"depth_est": depth_est * mask,
|
"depth_est_nomask": depth_est,
|
"depth_gt": sample["depth"]["stage1"],
|
"ref_img": sample["imgs"][:, 0],
|
"mask": sample["mask"]["stage1"],
|
"errormap": (depth_est - depth_gt).abs() * mask,
|
}
|
if is_distributed:
|
scalar_outputs = reduce_scalar_outputs(scalar_outputs)
|
return tensor2float(scalar_outputs["loss"]), tensor2float(scalar_outputs), tensor2numpy(image_outputs)
|
@make_nograd_func
|
def test_sample_depth(model, model_loss, sample, args):
|
if is_distributed:
|
model_eval = model.module
|
else:
|
model_eval = model
|
model_eval.eval()
|
sample_cuda = tocuda(sample)
|
depth_gt_ms = sample_cuda["depth"]
|
mask_ms = sample_cuda["mask"]
|
sigma_ms = sample_cuda["sigma"]
|
num_stage = len([int(nd) for nd in args.ndepths.split(",") if nd])
|
depth_gt = depth_gt_ms["stage{}".format(num_stage)]
|
mask = mask_ms["stage{}".format(num_stage)]
|
outputs = model_eval(sample_cuda["imgs"], sample_cuda["proj_matrices"], sample_cuda["depth_values"])
|
depth_est = outputs["depth"]
|
loss, depth_loss, kl, approx_kl, depth_wta = model_loss(outputs, depth_gt_ms,
|
sigma_ms, mask_ms, dlossw=[float(e) for e in args.dlossw.split(",") if e])
|
scalar_outputs = {"loss": loss,
|
"depth_loss": depth_loss,
|
"kl_loss": kl,
|
"approx_kl": approx_kl,
|
"abs_depth_error": AbsDepthError_metrics(depth_est, depth_gt, mask > 0.5),
|
"thres2mm_error": Thres_metrics(depth_est, depth_gt, mask > 0.5, 2),
|
"thres4mm_error": Thres_metrics(depth_est, depth_gt, mask > 0.5, 4),
|
"thres8mm_error": Thres_metrics(depth_est, depth_gt, mask > 0.5, 8),
|
"thres14mm_error": Thres_metrics(depth_est, depth_gt, mask > 0.5, 14),
|
"thres20mm_error": Thres_metrics(depth_est, depth_gt, mask > 0.5, 20),
|
"thres2mm_abserror": AbsDepthError_metrics(depth_est, depth_gt, mask > 0.5, [0, 2.0]),
|
"thres4mm_abserror": AbsDepthError_metrics(depth_est, depth_gt, mask > 0.5, [2.0, 4.0]),
|
"thres8mm_abserror": AbsDepthError_metrics(depth_est, depth_gt, mask > 0.5, [4.0, 8.0]),
|
"thres14mm_abserror": AbsDepthError_metrics(depth_est, depth_gt, mask > 0.5, [8.0, 14.0]),
|
"thres20mm_abserror": AbsDepthError_metrics(depth_est, depth_gt, mask > 0.5, [14.0, 20.0]),
|
"thres>20mm_abserror": AbsDepthError_metrics(depth_est, depth_gt, mask > 0.5, [20.0, 1e5]),
|
}
|
image_outputs = {"depth_est": depth_est * mask,
|
"depth_est_nomask": depth_est,
|
"depth_gt": sample["depth"]["stage1"],
|
"ref_img": sample["imgs"][:, 0],
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.