File size: 767 Bytes
51b2bf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import copy
from calflops import calculate_flops
from typing import Tuple

def stats(
    model, args,
    input_shape: Tuple=(1, 3, 640, 640), ) -> Tuple[int, dict]:

    base_size = args.eval_spatial_size[0]
    input_shape = (1, 3, base_size, base_size)

    model_for_info = copy.deepcopy(model).deploy()

    flops, macs, _ = calculate_flops(model=model_for_info,
                                        input_shape=input_shape,
                                        output_as_string=True,
                                        output_precision=4,
                                        print_detailed=False)
    params = sum(p.numel() for p in model_for_info.parameters())
    del model_for_info
    return {'flops': flops, 'macs': macs, 'params': params}