代码拉取完成,页面将自动刷新
# ------------------------------------------------------------------------
# Copyright (c) 2021 megvii-model. All Rights Reserved.
# ------------------------------------------------------------------------
# Copyright (c) Facebook, Inc. and its affiliates.
import numpy as np
from collections import Counter
import tqdm
from fvcore.nn import flop_count_table # can also try flop_count_str
from detectron2.utils.analysis import FlopCountAnalysis
from main import get_args_parser as get_main_args_parser
from models import build_model
from datasets import build_dataset
def do_flop():
main_args = get_main_args_parser().parse_args()
dataset = build_dataset('val', main_args)
model, _, _ = build_model(main_args)
model.cuda()
model.eval()
counts = Counter()
total_flops = []
for idx, data in zip(tqdm.trange(100), dataset): # noqa
flops = FlopCountAnalysis(model, [data[0].cuda()])
if idx > 0:
flops.unsupported_ops_warnings(False).uncalled_modules_warnings(False)
counts += flops.by_operator()
total_flops.append(flops.total())
print("Flops table computed from only one input sample:\n" + flop_count_table(flops))
print("Average GFlops for each type of operators:\n"+ str([(k, v / (idx + 1) / 1e9) for k, v in counts.items()]))
print("Total GFlops: {:.1f}±{:.1f}".format(np.mean(total_flops) / 1e9, np.std(total_flops) / 1e9))
if __name__ == "__main__":
do_flop()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。