-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathparameters_flops_estimator.py
More file actions
43 lines (36 loc) · 1.03 KB
/
parameters_flops_estimator.py
File metadata and controls
43 lines (36 loc) · 1.03 KB
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
import torch
from ptflops import get_model_complexity_info
from models.mowe import MoWE
import time
if __name__ == '__main__':
h = 240
w = 240
model = MoWE(task_scale='1+1+1+1',
is_single_task=False,
img_size=(h, w),
patch_size=8,
residual_learning=False,
embed_dim=384,
depth=2,
scale_dim=4,
moe_enable=True,
num_expert=128,
type_expert='ffn',
top_k=4,
gate='film',)
model.eval()
flops, params = get_model_complexity_info(model, (3, h, w), as_strings=True, print_per_layer_stat=True)
print('Flops: ' + flops)
print('Params: ' + params)
t = 0
img = torch.randn(size=(1, 3, h, w)).cuda()
model = model.cuda()
for i in range(220):
if i >= 20:
t1 = time.time()
output = model(img)
# print(output)
if i >= 20:
t2 = time.time()
t += (t2-t1)
print('Times per image: {}'.format(t/200))