MCPcopy Index your code
hub / github.com/drinkingcoder/FlowFormer-Official / validate_sintel

Function validate_sintel

evaluate_FlowFormer_tile.py:250–301  ·  view source on GitHub ↗

Peform validation using the Sintel (train) split

(model, sigma=0.05)

Source from the content-addressed store, hash-verified

248
249@torch.no_grad()
250def validate_sintel(model, sigma=0.05):
251 """ Peform validation using the Sintel (train) split """
252
253 IMAGE_SIZE = [436, 1024]
254
255 hws = compute_grid_indices(IMAGE_SIZE)
256 weights = compute_weight(hws, IMAGE_SIZE, TRAIN_SIZE, sigma)
257
258 model.eval()
259 results = {}
260 for dstype in ['final', "clean"]:
261 val_dataset = datasets.MpiSintel(split='training', dstype=dstype)
262
263 epe_list = []
264
265 for val_id in range(len(val_dataset)):
266 if val_id % 50 == 0:
267 print(val_id)
268
269 image1, image2, flow_gt, _ = val_dataset[val_id]
270 image1 = image1[None].cuda()
271 image2 = image2[None].cuda()
272
273 flows = 0
274 flow_count = 0
275
276 for idx, (h, w) in enumerate(hws):
277 image1_tile = image1[:, :, h:h+TRAIN_SIZE[0], w:w+TRAIN_SIZE[1]]
278 image2_tile = image2[:, :, h:h+TRAIN_SIZE[0], w:w+TRAIN_SIZE[1]]
279
280 flow_pre, _ = model(image1_tile, image2_tile, flow_init=None)
281
282 padding = (w, IMAGE_SIZE[1]-w-TRAIN_SIZE[1], h, IMAGE_SIZE[0]-h-TRAIN_SIZE[0], 0, 0)
283 flows += F.pad(flow_pre * weights[idx], padding)
284 flow_count += F.pad(weights[idx], padding)
285
286 flow_pre = flows / flow_count
287 flow_pre = flow_pre[0].cpu()
288
289 epe = torch.sum((flow_pre - flow_gt)**2, dim=0).sqrt()
290 epe_list.append(epe.view(-1).numpy())
291
292 epe_all = np.concatenate(epe_list)
293 epe = np.mean(epe_all)
294 px1 = np.mean(epe_all<1)
295 px3 = np.mean(epe_all<3)
296 px5 = np.mean(epe_all<5)
297
298 print("Validation (%s) EPE: %f, 1px: %f, 3px: %f, 5px: %f" % (dstype, epe, px1, px3, px5))
299 results[f"{dstype}_tile"] = np.mean(epe_list)
300
301 return results
302
303if __name__ == '__main__':
304 parser = argparse.ArgumentParser()

Callers

nothing calls this directly

Calls 3

compute_grid_indicesFunction · 0.70
compute_weightFunction · 0.70
padMethod · 0.45

Tested by

no test coverage detected