From ae8bdb3a8151fa01903f52f7fb3529b2d42ff753 Mon Sep 17 00:00:00 2001 From: hzwer <598460606@163.com> Date: Wed, 20 Jan 2021 17:27:06 +0800 Subject: [PATCH] Add time testing script --- benchmark/testtime.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 benchmark/testtime.py diff --git a/benchmark/testtime.py b/benchmark/testtime.py new file mode 100644 index 0000000..c695d5f --- /dev/null +++ b/benchmark/testtime.py @@ -0,0 +1,29 @@ +import cv2 +import sys +sys.path.append('.') +import time +import torch +import torch.nn as nn +from model.RIFE import Model + +model = Model() +model.eval() +device = torch.device("cuda" if torch.cuda.is_available() else "cpu") +torch.set_grad_enabled(False) +if torch.cuda.is_available(): + torch.backends.cudnn.enabled = True + torch.backends.cudnn.benchmark = True + +I0 = torch.rand(1, 3, 480, 640).to(device) +I1 = torch.rand(1, 3, 480, 640).to(device) +with torch.no_grad(): + for i in range(100): + pred = model.inference(I0, I1) + if torch.cuda.is_available(): + torch.cuda.synchronize() + time_stamp = time.time() + for i in range(100): + pred = model.inference(I0, I1) + if torch.cuda.is_available(): + torch.cuda.synchronize() + print((time.time() - time_stamp) / 100)