今天试了一下mmediting的一些功能,由于我的机器上没有gpu,照着文章来复现也碰见了一些问题,我这里把这些问题记录一下,分享出来,
其中ge t_flops.py我做了一点就修改。

    model = build_model(
cfg.model, train_cfg=cfg.train_cfg, test_cfg=cfg.test_cfg).cuda

变成了:

    model = build_model(
cfg.model, train_cfg=cfg.train_cfg, test_cfg=cfg.test_cfg)

然后运行:

python tools/get_flops.py configs/restorers/srresnet_srgan/srgan_x4c64b16_g1_1000k_div2k.py --shape 40 40

输出为:

00k_div2k.py --shape 40 40
2022-08-07 11:12:35,210 - mmedit - INFO - load checkpoint from torchvision path: torchvision://vgg19
Downloading: "https://download.pytorch.org/models/vgg19-dcbb9e9d.pth" to /home/infname112/.cache/torch/hub/checkpoints/vgg19-dcbb9e9d.pth
100%|█████████████████████████████████████████████████████████████████████████████████████████████| 548M/548M [00:32<00:00, 17.9MB/s]
SRGAN(
16.017 M, 100.000% Params, 4.068 GFLOPs, 100.000% FLOPs,
(generator): MSRResNet(
1.518 M, 9.475% Params, 4.068 GFLOPs, 100.000% FLOPs,
(conv_first): Conv2d(0.002 M, 0.011% Params, 0.003 GFLOPs, 0.070% FLOPs, 3, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(trunk_net): Sequential(
1.182 M, 7.378% Params, 1.892 GFLOPs, 46.513% FLOPs,
(0): ResidualBlockNoBN(
0.074 M, 0.461% Params, 0.118 GFLOPs, 2.907% FLOPs,
(conv1): Conv2d(0.037 M, 0.231% Params, 0.059 GFLOPs, 1.452% FLOPs, 64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(conv2): Conv2d(0.037 M, 0.231% Params, 0.059 GFLOPs, 1.452% FLOPs, 64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
(relu): ReLU(0.0 M, 0.000% Params, 0.0 GFLOPs, 0.003% FLOPs, inplace=True)
.......

官方给的用法是:

python tools/get_flops.py configs/resotorer/srresnet.py --shape 40 40

所以照葫芦画瓢写了一个。

参考文献

​获取 FLOP 和参数量(实验性).​