Skip to content

Commit

Permalink
show std in flop counting
Browse files Browse the repository at this point in the history
Reviewed By: rbgirshick

Differential Revision: D21470339

fbshipit-source-id: b4308c204c450477c3e28209e86ffe9e6bfdf586
  • Loading branch information
ppwwyyxx authored and facebook-github-bot committed May 8, 2020
1 parent 11409af commit b6fe828
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions detectron2/utils/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"aten::batch_norm",
"aten::div",
"aten::div_",
"aten::meshgrid",
"aten::rsub",
"aten::sub",
"aten::relu_",
Expand Down
17 changes: 15 additions & 2 deletions tools/analyze_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# noqa: B950

import logging
import numpy as np
from collections import Counter
import tqdm

Expand Down Expand Up @@ -37,11 +38,15 @@ def do_flop(cfg):
model.eval()

counts = Counter()
total_flops = []
for idx, data in zip(tqdm.trange(args.num_inputs), data_loader): # noqa
counts += flop_count_operators(model, data)
count = flop_count_operators(model, data)
counts += count
total_flops.append(sum(count.values()))
logger.info(
"(G)Flops for Each Type of Operators:\n" + str([(k, v / idx) for k, v in counts.items()])
)
logger.info("Total (G)Flops: {}±{}".format(np.mean(total_flops), np.std(total_flops)))


def do_activation(cfg):
Expand All @@ -51,12 +56,20 @@ def do_activation(cfg):
model.eval()

counts = Counter()
total_activations = []
for idx, data in zip(tqdm.trange(args.num_inputs), data_loader): # noqa
counts += activation_count_operators(model, data)
count = activation_count_operators(model, data)
counts += count
total_activations.append(sum(count.values()))
logger.info(
"(Million) Activations for Each Type of Operators:\n"
+ str([(k, v / idx) for k, v in counts.items()])
)
logger.info(
"Total (Million) Activations: {}±{}".format(
np.mean(total_activations), np.std(total_activations)
)
)


def do_parameter(cfg):
Expand Down

0 comments on commit b6fe828

Please sign in to comment.