Estimate optical flow between pair of frames
(self, image1, image2, iters=12, test_mode=False)
| 90 | return up_flow.reshape(N, 2, 8 * H, 8 * W) |
| 91 | |
| 92 | def forward(self, image1, image2, iters=12, test_mode=False): |
| 93 | """ Estimate optical flow between pair of frames """ |
| 94 | |
| 95 | image1 = 2 * (image1 / 255.0) - 1.0 |
| 96 | image2 = 2 * (image2 / 255.0) - 1.0 |
| 97 | |
| 98 | image1 = image1.contiguous() |
| 99 | image2 = image2.contiguous() |
| 100 | |
| 101 | hdim = self.hidden_dim |
| 102 | cdim = self.context_dim |
| 103 | |
| 104 | # run the feature network |
| 105 | with autocast(enabled=self.args.mixed_precision): |
| 106 | # fmap1, fmap2 = self.fnet([image1, image2]) |
| 107 | fmap1, fmap2 = self.fnet(image1), self.fnet(image2) |
| 108 | |
| 109 | fmap1 = fmap1.float() |
| 110 | fmap2 = fmap2.float() |
| 111 | |
| 112 | if self.args.alternate_corr: |
| 113 | corr_fn = AlternateCorrBlock(fmap1, fmap2, radius=self.args.corr_radius) |
| 114 | corr_fn2 = AlternateCorrBlock(fmap2, fmap1, radius=self.args.corr_radius) |
| 115 | else: |
| 116 | corr_fn = CorrBlock(fmap1, fmap2, radius=self.args.corr_radius) |
| 117 | corr_fn2 = CorrBlock(fmap2, fmap1, radius=self.args.corr_radius) |
| 118 | |
| 119 | # run the context network |
| 120 | with autocast(enabled=self.args.mixed_precision): |
| 121 | cnet = self.cnet(image1) |
| 122 | net, inp = torch.split(cnet, [hdim, cdim], dim=1) |
| 123 | net = torch.tanh(net) |
| 124 | inp = torch.relu(inp) |
| 125 | |
| 126 | cnet2 = self.cnet(image2) |
| 127 | net2, inp2 = torch.split(cnet2, [hdim, cdim], dim=1) |
| 128 | net2 = torch.tanh(net2) |
| 129 | inp2 = torch.relu(inp2) |
| 130 | |
| 131 | coords0, coords1 = self.initialize_flow(image1) |
| 132 | coords2, coords3 = self.initialize_flow(image2) |
| 133 | |
| 134 | flow_init = None |
| 135 | flow_init2 = None |
| 136 | if flow_init is not None: |
| 137 | coords1 = coords1 + flow_init |
| 138 | |
| 139 | if flow_init2 is not None: |
| 140 | coords2 = coords2 + flow_init2 |
| 141 | |
| 142 | flow_predictions = [] |
| 143 | flow_predictions2 = [] |
| 144 | flow_up = [] |
| 145 | flow_up2 = [] |
| 146 | |
| 147 | for itr in range(iters): |
| 148 | coords1 = coords1.detach() |
| 149 | corr = corr_fn(coords1) # index correlation volume |
nothing calls this directly
no test coverage detected