(self, view1, view2, pred1, pred2,
dist='l1',
conf='log',
min_conf_thr=3,
base_scale=0.5,
allow_pw_adaptors=False,
pw_break=20,
rand_pose=torch.randn,
iterationsCount=None,
verbose=True)
| 42 | self._init_from_views(*args, **kwargs) |
| 43 | |
| 44 | def _init_from_views(self, view1, view2, pred1, pred2, |
| 45 | dist='l1', |
| 46 | conf='log', |
| 47 | min_conf_thr=3, |
| 48 | base_scale=0.5, |
| 49 | allow_pw_adaptors=False, |
| 50 | pw_break=20, |
| 51 | rand_pose=torch.randn, |
| 52 | iterationsCount=None, |
| 53 | verbose=True): |
| 54 | super().__init__() |
| 55 | if not isinstance(view1['idx'], list): |
| 56 | view1['idx'] = view1['idx'].tolist() |
| 57 | if not isinstance(view2['idx'], list): |
| 58 | view2['idx'] = view2['idx'].tolist() |
| 59 | self.edges = [(int(i), int(j)) for i, j in zip(view1['idx'], view2['idx'])] |
| 60 | self.is_symmetrized = set(self.edges) == {(j, i) for i, j in self.edges} |
| 61 | self.dist = ALL_DISTS[dist] |
| 62 | self.verbose = verbose |
| 63 | |
| 64 | self.n_imgs = self._check_edges() |
| 65 | |
| 66 | # input data |
| 67 | pred1_pts = pred1['pts3d'] |
| 68 | pred2_pts = pred2['pts3d_in_other_view'] |
| 69 | self.pred_i = NoGradParamDict({ij: pred1_pts[n] for n, ij in enumerate(self.str_edges)}) |
| 70 | self.pred_j = NoGradParamDict({ij: pred2_pts[n] for n, ij in enumerate(self.str_edges)}) |
| 71 | self.imshapes = get_imshapes(self.edges, pred1_pts, pred2_pts) |
| 72 | |
| 73 | # work in log-scale with conf |
| 74 | pred1_conf = pred1['conf'] |
| 75 | pred2_conf = pred2['conf'] |
| 76 | self.min_conf_thr = min_conf_thr |
| 77 | self.conf_trf = get_conf_trf(conf) |
| 78 | |
| 79 | self.conf_i = NoGradParamDict({ij: pred1_conf[n] for n, ij in enumerate(self.str_edges)}) |
| 80 | self.conf_j = NoGradParamDict({ij: pred2_conf[n] for n, ij in enumerate(self.str_edges)}) |
| 81 | self.im_conf = self._compute_img_conf(pred1_conf, pred2_conf) |
| 82 | for i in range(len(self.im_conf)): |
| 83 | self.im_conf[i].requires_grad = False |
| 84 | |
| 85 | # pairwise pose parameters |
| 86 | self.base_scale = base_scale |
| 87 | self.norm_pw_scale = True |
| 88 | self.pw_break = pw_break |
| 89 | self.POSE_DIM = 7 |
| 90 | self.pw_poses = nn.Parameter(rand_pose((self.n_edges, 1+self.POSE_DIM))) # pairwise poses |
| 91 | self.pw_adaptors = nn.Parameter(torch.zeros((self.n_edges, 2))) # slight xy/z adaptation |
| 92 | self.pw_adaptors.requires_grad_(allow_pw_adaptors) |
| 93 | self.has_im_poses = False |
| 94 | self.rand_pose = rand_pose |
| 95 | |
| 96 | # possibly store images for show_pointcloud |
| 97 | self.imgs = None |
| 98 | if 'img' in view1 and 'img' in view2: |
| 99 | imgs = [torch.zeros((3,)+hw) for hw in self.imshapes] |
| 100 | for v in range(len(self.edges)): |
| 101 | idx = view1['idx'][v] |
no test coverage detected