(self, epoch)
| 103 | torch.cuda.empty_cache() |
| 104 | |
| 105 | def train_epoch(self, epoch): |
| 106 | self.network.train() |
| 107 | |
| 108 | if is_main_process(): |
| 109 | pwidgets = [progressbar.Percentage(), " ", progressbar.Counter(format='%(value)02d/%(max_value)d'), " ", progressbar.Bar(), " ", |
| 110 | progressbar.Timer(), ",", progressbar.ETA(), ",", progressbar.Variable('LR', width=1), ",", |
| 111 | progressbar.Variable('Loss', width=1), ",", progressbar.Variable('Th2', width=1), ",", |
| 112 | progressbar.Variable('Th4', width=1), ",", progressbar.Variable('Th8', width=1)] |
| 113 | |
| 114 | pbar = progressbar.ProgressBar(widgets=pwidgets, max_value=len(self.train_loader), |
| 115 | prefix="Epoch {}/{}: ".format(epoch, self.args.epochs)).start() |
| 116 | |
| 117 | avg_scalars = DictAverageMeter() |
| 118 | if not self.blendmvs: |
| 119 | color_y=torch.zeros((3,512,640)).cuda() |
| 120 | color_g=torch.zeros((3,512,640)).cuda() |
| 121 | else: |
| 122 | color_y=torch.zeros((3,576,768)).cuda() |
| 123 | color_g=torch.zeros((3,576,768)).cuda() |
| 124 | color_y[1]=1. |
| 125 | color_y[0]=1. |
| 126 | color_g[1]=1. |
| 127 | for batch, data in enumerate(self.train_loader): |
| 128 | data = tocuda(data) |
| 129 | |
| 130 | outputs = self.network(data["imgs"], data["proj_matrices"], data["depth_values"]) |
| 131 | |
| 132 | loss = self.loss_func(outputs, data["depth"], data["mask"], self.args.depth_mode, dlossw=self.args.dlossw) |
| 133 | |
| 134 | self.optimizer.zero_grad() |
| 135 | loss.backward() |
| 136 | self.optimizer.step() |
| 137 | |
| 138 | self.lr_scheduler.step(epoch + batch / len(self.train_loader)) |
| 139 | |
| 140 | gt_depth = data["depth"]["stage{}".format(len(self.args.ndepths))] |
| 141 | mask = data["mask"]["stage{}".format(len(self.args.ndepths))] |
| 142 | |
| 143 | thres2mm = Thres_metrics(outputs["depth"], gt_depth, mask > 0.5, 2) |
| 144 | thres4mm = Thres_metrics(outputs["depth"], gt_depth, mask > 0.5, 4) |
| 145 | thres8mm = Thres_metrics(outputs["depth"], gt_depth, mask > 0.5, 8) |
| 146 | abs_depth_error = AbsDepthError_metrics(outputs["depth"], gt_depth, mask > 0.5) |
| 147 | |
| 148 | |
| 149 | scalar_outputs = {"loss": loss, |
| 150 | "abs_depth_error": abs_depth_error, |
| 151 | "thres2mm_error": thres2mm, |
| 152 | "thres4mm_error": thres4mm, |
| 153 | "thres8mm_error": thres8mm, |
| 154 | } |
| 155 | |
| 156 | if "depth_refine" in outputs: |
| 157 | thres2mm_r = Thres_metrics(outputs["depth_refine"], gt_depth, mask > 0.5, 2) |
| 158 | thres4mm_r = Thres_metrics(outputs["depth_refine"], gt_depth, mask > 0.5, 4) |
| 159 | thres8mm_r = Thres_metrics(outputs["depth_refine"], gt_depth, mask > 0.5, 8) |
| 160 | abs_depth_error_r = AbsDepthError_metrics(outputs["depth_refine"], gt_depth, mask > 0.5) |
| 161 | |
| 162 | if "depth_refine" in outputs: |
no test coverage detected