mit-han-lab / gan-compression

[CVPR 2020] GAN Compression: Efficient Architectures for Interactive Conditional GANs
Other
1.1k stars 148 forks source link

Can you provide the code to calculate MACs? #9

Closed Ha0Tang closed 4 years ago

lmxyy commented 4 years ago

Our MACs computation depends on torchprofile. You could check the profile function in models/test_model.py.

def profile(self, config=None, verbose=True):
    netG = self.netG
    if isinstance(netG, nn.DataParallel):
        netG = netG.module
    if config is not None:
        netG.configs = config
    with torch.no_grad():
        macs = profile_macs(netG, (self.real_A[:1],))
    params = 0
    for p in netG.parameters():
        params += p.numel()
    if verbose:
        print('MACs: %.3fG\tParams: %.3fM' % (macs / 1e9, params / 1e6), flush=True)
    return macs, params
Ha0Tang commented 4 years ago

Many thanks.