-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculate_ops_example.py
47 lines (36 loc) · 1.62 KB
/
calculate_ops_example.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
46
from complexity_metrics import get_gmacs_and_params, get_runtime
import codes.models.modules.adnet as adnet
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-wp", "--write_path", type=str, default="./", help="Path to write the readme.txt file")
args = parser.parse_args()
write_path=args.write_path
# Load a pytorch model
model = adnet.ADNetv2(6, 5, 64, 32)
model.eval()
# Calculate MACs and Parameters
height = 1060
width = 1900
scale = 4 # You can try to modify this to 1 if your GPU allowed.
total_macs, total_params = get_gmacs_and_params(model, input_size=(1, 6, height // scale, width // scale))
mean_runtime = get_runtime(model, input_size=(1, 6, height // scale, width // scale))
total_macs = total_macs * scale * scale
mean_runtime = mean_runtime * scale * scale
print(total_macs)
print(total_params)
print(mean_runtime)
# Print model statistics to txt file
with open(write_path + 'readme.txt', 'w') as f:
f.write("runtime per image [s] : " + str(mean_runtime))
f.write('\n')
f.write("number of operations [GMAcc] : " + str(total_macs))
f.write('\n')
f.write("number of parameters : " + str(total_params))
f.write('\n')
f.write("Other description: Toy Model for demonstrating example code usage.")
# Expected output of the readme.txt for ToyHDRModel should be:
# runtime per image [s] : 0.013018618555068967
# number of operations [GMAcc] : 20.146042
# number of parameters : 8243
# Other description: Toy Model for demonstrating example code usage.
print("You reached the end of the calculate_ops_example.py demo script. Good luck participating in the NTIRE 2022 HDR Challenge!")