MCPcopy Create free account
hub / github.com/drinkingcoder/FlowFormer-Official / validate_kitti

Function validate_kitti

evaluate_FlowFormer_tile.py:192–247  ·  view source on GitHub ↗
(model, sigma=0.05)

Source from the content-addressed store, hash-verified

190
191@torch.no_grad()
192def validate_kitti(model, sigma=0.05):
193 IMAGE_SIZE = [376, 1242]
194 TRAIN_SIZE = [376, 720]
195
196 hws = compute_grid_indices(IMAGE_SIZE, TRAIN_SIZE)
197 weights = compute_weight(hws, IMAGE_SIZE, TRAIN_SIZE, sigma)
198 model.eval()
199 val_dataset = datasets.KITTI(split='training')
200
201 out_list, epe_list = [], []
202 for val_id in range(len(val_dataset)):
203 image1, image2, flow_gt, valid_gt = val_dataset[val_id]
204 new_shape = image1.shape[1:]
205 if new_shape[1] != IMAGE_SIZE[1]:
206 print(f"replace {IMAGE_SIZE} with {new_shape}")
207 IMAGE_SIZE[0] = 376
208 IMAGE_SIZE[1] = new_shape[1]
209 hws = compute_grid_indices(IMAGE_SIZE, TRAIN_SIZE)
210 weights = compute_weight(hws, IMAGE_SIZE, TRAIN_SIZE, sigma)
211
212 padder = InputPadder(image1.shape, mode='kitti376')
213 image1, image2 = padder.pad(image1[None].cuda(), image2[None].cuda())
214
215 flows = 0
216 flow_count = 0
217
218 for idx, (h, w) in enumerate(hws):
219 image1_tile = image1[:, :, h:h+TRAIN_SIZE[0], w:w+TRAIN_SIZE[1]]
220 image2_tile = image2[:, :, h:h+TRAIN_SIZE[0], w:w+TRAIN_SIZE[1]]
221 flow_pre, flow_low = model(image1_tile, image2_tile)
222
223 padding = (w, IMAGE_SIZE[1]-w-TRAIN_SIZE[1], h, IMAGE_SIZE[0]-h-TRAIN_SIZE[0], 0, 0)
224 flows += F.pad(flow_pre * weights[idx], padding)
225 flow_count += F.pad(weights[idx], padding)
226
227 flow_pre = flows / flow_count
228 flow = padder.unpad(flow_pre[0]).cpu()
229 epe = torch.sum((flow - flow_gt)**2, dim=0).sqrt()
230 mag = torch.sum(flow_gt**2, dim=0).sqrt()
231
232 epe = epe.view(-1)
233 mag = mag.view(-1)
234 val = valid_gt.view(-1) >= 0.5
235
236 out = ((epe > 3.0) & ((epe/mag) > 0.05)).float()
237 epe_list.append(epe[val].mean().item())
238 out_list.append(out[val].cpu().numpy())
239
240 epe_list = np.array(epe_list)
241 out_list = np.concatenate(out_list)
242
243 epe = np.mean(epe_list)
244 f1 = 100 * np.mean(out_list)
245
246 print("Validation KITTI: %f, %f" % (epe, f1))
247 return {'kitti-epe': epe, 'kitti-f1': f1}
248
249@torch.no_grad()

Callers

nothing calls this directly

Calls 5

padMethod · 0.95
unpadMethod · 0.95
InputPadderClass · 0.90
compute_grid_indicesFunction · 0.70
compute_weightFunction · 0.70

Tested by

no test coverage detected