def validate_with_gt(args, val_loader, disp_net, epoch, logger, tb_writer, sample_nb_to_log=3): global device batch_time = AverageMeter() error_names = ['abs_diff', 'abs_rel', 'sq_rel', 'a1', 'a2', 'a3'] errors = AverageMeter(i=len(error_names)) log_outputs = sample_nb_to_log > 0 # switch to evaluate mode disp_net.eval() end = time.time() #logger.valid_bar.update(0) for i, (tgt_img, depth) in enumerate(val_loader): tgt_img = tgt_img.to(device) depth = depth.to(device) # compute output output_disp = disp_net(tgt_img) output_depth = 1 / output_disp[:, 0] if log_outputs and i < sample_nb_to_log: if epoch == 0: tb_writer.add_image('val Input/{}'.format(i), tensor2array(tgt_img[0]), 0) depth_to_show = depth[0] tb_writer.add_image( 'val target Depth Normalized/{}'.format(i), tensor2array(depth_to_show, max_value=None), epoch) depth_to_show[depth_to_show == 0] = 1000 disp_to_show = (1 / depth_to_show).clamp(0, 10) tb_writer.add_image( 'val target Disparity Normalized/{}'.format(i), tensor2array(disp_to_show, max_value=None, colormap='magma'), epoch) tb_writer.add_image( 'val Dispnet Output Normalized/{}'.format(i), tensor2array(output_disp[0], max_value=None, colormap='magma'), epoch) tb_writer.add_image('val Depth Output Normalized/{}'.format(i), tensor2array(output_depth[0], max_value=None), epoch) errors.update(compute_errors(depth, output_depth)) # measure elapsed time batch_time.update(time.time() - end) end = time.time() #logger.valid_bar.update(i+1) #if i % args.print_freq == 0: #logger.valid_writer.write('valid: Time {} Abs Error {:.4f} ({:.4f})'.format(batch_time, errors.val[0], errors.avg[0])) #logger.valid_bar.update(len(val_loader)) return errors.avg, error_names
def validate_with_gt(args, val_loader, disp_net, epoch, logger): global device batch_time = AverageMeter() error_names = ['abs_diff', 'abs_rel', 'sq_rel', 'a1', 'a2', 'a3'] errors = AverageMeter(i=len(error_names)) # switch to evaluate mode disp_net.eval() end = time.time() logger.valid_bar.update(0) for i, (tgt_img, depth) in enumerate(val_loader): tgt_img = tgt_img.to(device) depth = depth.to(device) # compute output output_disp = disp_net(tgt_img) output_depth = 1 / output_disp[:, 0] errors.update(compute_errors(depth, output_depth)) # measure elapsed time batch_time.update(time.time() - end) end = time.time() logger.valid_bar.update(i + 1) if i % args.print_freq == 0: logger.valid_writer.write( 'valid: Time {} Abs Error {:.4f} ({:.4f})'.format( batch_time, errors.val[0], errors.avg[0])) logger.valid_bar.update(len(val_loader)) return errors.avg, error_names
def validate_with_gt(args, val_loader, disp_net, epoch, logger, output_writers=[]): global device batch_time = AverageMeter() error_names = ['abs_diff', 'abs_rel', 'sq_rel', 'a1', 'a2', 'a3'] errors = AverageMeter(i=len(error_names)) log_outputs = len(output_writers) > 0 # switch to evaluate mode disp_net.eval() end = time.time() logger.valid_bar.update(0) for i, (tgt_img, depth) in enumerate(val_loader): tgt_img = tgt_img.to(device) depth = depth.to(device) # check gt if depth.nelement() == 0: continue # compute output output_disp = disp_net(tgt_img) output_depth = 1/output_disp[:, 0] if log_outputs and i < len(output_writers): if epoch == 0: output_writers[i].add_image('val Input', tensor2array(tgt_img[0]), 0) depth_to_show = depth[0] output_writers[i].add_image('val target Depth', tensor2array(depth_to_show, max_value=10), epoch) depth_to_show[depth_to_show == 0] = 1000 disp_to_show = (1/depth_to_show).clamp(0, 10) output_writers[i].add_image('val target Disparity Normalized', tensor2array(disp_to_show, max_value=None, colormap='magma'), epoch) output_writers[i].add_image('val Dispnet Output Normalized', tensor2array(output_disp[0], max_value=None, colormap='magma'), epoch) output_writers[i].add_image('val Depth Output', tensor2array(output_depth[0], max_value=10), epoch) if depth.nelement() != output_depth.nelement(): b, h, w = depth.size() output_depth = torch.nn.functional.interpolate(output_depth.unsqueeze(1), [h, w]).squeeze(1) errors.update(compute_errors(depth, output_depth, args.dataset)) # measure elapsed time batch_time.update(time.time() - end) end = time.time() logger.valid_bar.update(i+1) if i % args.print_freq == 0: logger.valid_writer.write('valid: Time {} Abs Error {:.4f} ({:.4f})'.format(batch_time, errors.val[0], errors.avg[0])) logger.valid_bar.update(len(val_loader)) return errors.avg, error_names
def validate_with_gt(val_loader, disp_net, epoch, logger, output_writers=[]): global args batch_time = AverageMeter() error_names = ['abs_diff', 'abs_rel', 'sq_rel', 'a1', 'a2', 'a3'] errors = AverageMeter(i=len(error_names)) log_outputs = len(output_writers) > 0 # switch to evaluate mode disp_net.eval() end = time.time() logger.valid_bar.update(0) for i, (tgt_img, depth) in enumerate(val_loader): tgt_img_var = Variable(tgt_img.cuda(), volatile=True) depth = depth.cuda() # compute output output_disp = disp_net(tgt_img_var) output_depth = 1 / output_disp if log_outputs and i % 100 == 0 and i / 100 < len(output_writers): index = int(i // 100) if epoch == 0: output_writers[index].add_image('val Input', tensor2array(tgt_img[0]), 0) depth_to_show = depth[0].cpu() output_writers[index].add_image( 'val target Depth', tensor2array(depth_to_show, max_value=10), epoch) depth_to_show[depth_to_show == 0] = 1000 disp_to_show = (1 / depth_to_show).clamp(0, 10) output_writers[index].add_image( 'val target Disparity Normalized', tensor2array(disp_to_show, max_value=None, colormap='bone'), epoch) output_writers[index].add_image( 'val Dispnet Output Normalized', tensor2array(output_disp.data[0].cpu(), max_value=None, colormap='bone'), epoch) output_writers[index].add_image( 'val Depth Output', tensor2array(output_depth.data[0].cpu(), max_value=10), epoch) errors.update(compute_errors(depth, output_depth.data)) # measure elapsed time batch_time.update(time.time() - end) end = time.time() logger.valid_bar.update(i + 1) if i % args.print_freq == 0: logger.valid_writer.write( 'valid: Time {} Abs Error {:.4f} ({:.4f})'.format( batch_time, errors.val[0], errors.avg[0])) logger.valid_bar.update(len(val_loader)) return errors.avg, error_names
def validate_with_gt(args, val_loader, disp_net, epoch, output_writers=[]): global device batch_time = AverageMeter() error_names = ['abs_diff', 'abs_rel', 'sq_rel', 'a1', 'a2', 'a3'] errors = AverageMeter(i=len(error_names)) log_outputs = len(output_writers) > 0 # switch to evaluate mode disp_net.eval() end = time.time() for i, (tgt_img, depth) in enumerate(val_loader): tgt_img = tgt_img.to(device) depth = depth.to(device) # compute output output_disp = disp_net(tgt_img) output_depth = 1/output_disp[:,0] if log_outputs and i < len(output_writers): if epoch == 0: output_writers[i].add_image('val Input', tensor2array(tgt_img[0]), 0) depth_to_show = depth[0] output_writers[i].add_image('val target Depth', tensor2array(depth_to_show, max_value=10), epoch) depth_to_show[depth_to_show == 0] = 1000 disp_to_show = (1/depth_to_show).clamp(0,10) output_writers[i].add_image('val target Disparity Normalized', tensor2array(disp_to_show, max_value=None, colormap='bone'), epoch) output_writers[i].add_image('val Dispnet Output Normalized', tensor2array(output_disp[0], max_value=None, colormap='bone'), epoch) output_writers[i].add_image('val Depth Output', tensor2array(output_depth[0], max_value=3), epoch) errors.update(compute_errors(depth, output_depth)) # measure elapsed time batch_time.update(time.time() - end) end = time.time() if i % args.print_freq == 0: print('valid: Time {} Abs Error {:.4f} ({:.4f})'.format(batch_time, errors.val[0], errors.avg[0])) return errors.avg, error_names
def validate_with_gt(args, val_loader, disp_net, epoch, tb_writer, sample_nb_to_log=3): global device batch_time = AverageMeter() error_names = ['abs_diff', 'abs_rel', 'sq_rel', 'a1', 'a2', 'a3'] errors = AverageMeter(i=len(error_names)) log_outputs = sample_nb_to_log > 0 # switch to evaluate mode disp_net.eval() end = time.time() validate_pbar = tqdm( total=len(val_loader), bar_format='{desc} {percentage:3.0f}%|{bar}| {postfix}') validate_pbar.set_description('valid: Abs Error {:.4f} ({:.4f})'.format( 0, 0)) validate_pbar.set_postfix_str('<Time {}>'.format(0)) for i, (tgt_img, depth) in enumerate(val_loader): tgt_img = tgt_img.to(device) depth = depth.to(device) # compute output output_disp = disp_net(tgt_img) output_depth = 1 / output_disp[:, 0] if log_outputs and i < sample_nb_to_log: if epoch == 0: tb_writer.add_image('val Input/{}'.format(i), tensor2array(tgt_img[0]), 0) depth_to_show = depth[0] tb_writer.add_image( 'val target Depth Normalized/{}'.format(i), tensor2array(depth_to_show, max_value=None), epoch) depth_to_show[depth_to_show == 0] = 1000 disp_to_show = (1 / depth_to_show).clamp(0, 10) tb_writer.add_image( 'val target Disparity Normalized/{}'.format(i), tensor2array(disp_to_show, max_value=None, colormap='magma'), epoch) tb_writer.add_image( 'val Dispnet Output Normalized/{}'.format(i), tensor2array(output_disp[0], max_value=None, colormap='magma'), epoch) tb_writer.add_image('val Depth Output Normalized/{}'.format(i), tensor2array(output_depth[0], max_value=None), epoch) errors.update(compute_errors(depth, output_depth)) # measure elapsed time batch_time.update(time.time() - end) end = time.time() validate_pbar.update(1) validate_pbar.set_description( 'valid: Abs Error {:.4f} ({:.4f})'.format(errors.val[0], errors.avg[0])) validate_pbar.set_postfix_str('<Time {}>'.format(batch_time)) validate_pbar.close() time.sleep(1) return errors.avg, error_names