-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathbenchmark.py
45 lines (31 loc) · 1007 Bytes
/
benchmark.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import time
import torch
import torchvision.models as models
import torch.nn as nn
from torch.autograd import Variable
from model import darknet53
def speed(model, name):
with torch.no_grad():
model.eval()
input = torch.rand(1,3,224, 224).cuda()
model(input)
avg_time = 0
for i in range(0, 10):
torch.cuda.synchronize()
t2 = time.time()
model(input)
torch.cuda.synchronize()
t3 = time.time()
avg_time += t3 - t2
avg_time /= 10.0
print('%10s : %f' % (name, avg_time))
if __name__ == '__main__':
# cudnn.benchmark = True # This will make network slow ??
resnet101 = models.resnet101().cuda()
resnet152 = models.resnet152().cuda()
densenet121 = models.densenet121().cuda()
darknet = darknet53(1000).cuda()
speed(resnet101, 'resnet101')
speed(resnet152, 'resnet152')
speed(densenet121, 'densenet121')
speed(darknet, 'darknet53')