AI Ants

迈向通用人工智能之路

0%

神经网络常用计算模块总结

1、Flops、MACs、Params计算

https://github.com/he-y/soft-filter-pruning/blob/master/utils/cifar_resnet_flop.py

https://github.com/warmspringwinds/pytorch-segmentation-detection/blob/master/pytorch_segmentation_detection/utils/flops_benchmark.py

https://github.com/Lyken17/pytorch-OpCounter

crnn中:

1
2
3
4
5
6
7
8
9
10
统计模型参数量等信息
def model_info(model): # Plots a line-by-line description of a PyTorch model
n_p = sum(x.numel() for x in model.parameters()) # number parameters
n_g = sum(x.numel() for x in model.parameters() if x.requires_grad) # number gradients
print('\n%5s %50s %9s %12s %20s %12s %12s' % ('layer', 'name', 'gradient', 'parameters', 'shape', 'mu', 'sigma'))
for i, (name, p) in enumerate(model.named_parameters()):
name = name.replace('module_list.', '')
print('%5g %50s %9s %12g %20s %12.3g %12.3g' % (
i, name, p.requires_grad, p.numel(), list(p.shape), p.mean(), p.std()))
print('Model Summary: %g layers, %g parameters, %g gradients\n' % (i + 1, n_p, n_g))

2、模型初始化

1
2
3
4
5
6
7
8
9
10
11
12
def weights_init(model):
# Official init from torch repo.
for m in model.modules():
if isinstance(m, nn.Conv2d):
nn.init.kaiming_normal_(m.weight)
elif isinstance(m, nn.BatchNorm2d):
nn.init.constant_(m.weight, 1)
nn.init.constant_(m.bias, 0)
elif isinstance(m, nn.Linear):
nn.init.constant_(m.bias, 0)
encoder = crnn.CNN(opt.imgH, nc, opt.nh, cfg, mode='2D',dim_in=512)
encoder.apply(weights_init)

3、导入模型(单机单卡到分布式)

4、自定义学习率(如warmup)和优化器

-------------本文结束感谢您的阅读-------------

本文标题:神经网络常用计算模块总结

文章作者:

发布时间:2021年01月08日 - 11:07

最后更新:2021年01月09日 - 17:57

原始链接:https://yangsuhui.github.io/p/6fb7.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

如果您觉得内容不错,可以对我打赏哦!