huawei-noah / Efficient-AI-Backbones

Efficient AI Backbones including GhostNet, TNT and MLP, developed by Huawei Noah's Ark Lab.
4.01k stars 703 forks source link

Ghost-ResNet-50 结构flops和parameters #146

Open ChengpengChen opened 2 years ago

ChengpengChen commented 2 years ago

我把ResNet-50 的conv(除了第一个7x7xconv和最后的fc)替换为ghost module,得到的模型(下图是对应的onnx结构):

  1. Ghost-ResNet-50 (s=2), flops=2.15G, params=13.95M
  2. Ghost-ResNet-50 (s=4), flops=1.18G, params=8.15M

其中两个模型的flops跟paper中的对得上,但是params 都对不上,请问可以提供Ghost-ResNet-50的代码吗?

image
iamhankai commented 2 years ago

看起来结构是对的,可能是BN之类的参数统计差异?

ChengpengChen commented 2 years ago

我试过,但BN参数的差别微乎其微。

ChengpengChen commented 2 years ago

看起来结构是对的,可能是BN之类的参数统计差异?

请问可以分享一下Ghost-ResNet-50的代码或者ckpt吗?我想做一些对比实验,谢谢!

iamhankai commented 2 years ago

已上传:https://github.com/huawei-noah/Efficient-AI-Backbones/blob/master/ghostnet_pytorch/ghost_resnet.py

ChengpengChen commented 2 years ago

感谢作者!已经run起来了:) 不过这个模型测出来的params 跟我上面测的差不多。。

abcde-bit commented 1 year ago

感谢作者!已经run起来了:) 不过这个模型测出来的params 跟我上面测的差不多。。

大佬,你是怎么运行的计算flops的代码,我就在iamhankai大佬上传的代码后面加上了 if name == 'main':

img_shape = (3,32,32)

resnet18 = resnet18()
stat(resnet18, img_shape)       # https://github.com/Swall0w/torchstat
print("↑↑↑↑ is resnet18")
print("\n"*10)

这样一段代码但是却报错了

image
JaryDier commented 1 year ago

您好,您用的gost-resnet有预训练模型吗或者利用ghost_module修改后的resnent初始权重怎么设计的呢?

ChengpengChen commented 1 year ago

感谢作者!已经run起来了:) 不过这个模型测出来的params 跟我上面测的差不多。。

大佬,你是怎么运行的计算flops的代码,我就在iamhankai大佬上传的代码后面加上了 if name == 'main':

img_shape = (3,32,32)

resnet18 = resnet18()
stat(resnet18, img_shape)       # https://github.com/Swall0w/torchstat
print("↑↑↑↑ is resnet18")
print("\n"*10)

这样一段代码但是却报错了 image

这个看起来像是Swall0w/torchstat 的问题?

ChengpengChen commented 1 year ago

您好,您用的gost-resnet有预训练模型吗或者利用ghost_module修改后的resnent初始权重怎么设计的呢?

我用的是pytorch自带的初始化,没有用预训练模型