- python性能分析:
python性能分析–cProfile
# 性能分析装饰器定义
def do_cprofile(filename):
"""
Decorator for function profiling.
"""
def wrapper(func):
def profiled_func(*args, **kwargs):
# Flag for do profiling or not.
DO_PROF = True # os.getenv("PROFILING")
if DO_PROF:
profile = cProfile.Profile()
profile.enable()
result = func(*args, **kwargs)
profile.disable()
# Sort stat by internal time.
sortby = "tottime"
ps = pstats.Stats(profile).sort_stats(sortby)
ps.dump_stats(filename)
else:
result = func(*args, **kwargs)
return result
return profiled_func
return wrapper
- 深度模型性能分析
模型参数与计算量
一个公式搞定深度学习模型中的参数数量计算
CNN 模型所需的计算力(flops)和参数(parameters)数量是怎么计算的?