VITA-Group / AGD

[ICML2020] "AutoGAN-Distiller: Searching to Compress Generative Adversarial Networks" by Yonggan Fu, Wuyang Chen, Haotao Wang, Haoran Li, Yingyan Lin, Zhangyang Wang
MIT License
104 stars 19 forks source link

ModuleNotFoundError: No module named 'thop.count_hooks' #1

Closed eps696 closed 4 years ago

eps696 commented 4 years ago

UPD: in new thop versions thop.count_hooks should be replaced by thop.vision.basic_hooks

Name: thop Version: 0.0.31.post2005241907 installed via pip

eps696 commented 4 years ago

it appeared (during 3rd phase of training), that new thop versions don't work with this code at all, issuing the error:

Traceback (most recent call last):
  File "lib/search/train.py", line 224, in <module>
    main()
  File "lib/search/train.py", line 157, in main
    train(train_loader_model, model, teacher_model, optimizer, lr_policy, logger, epoch)
  File "lib/search/train.py", line 197, in train
    loss = model.module._loss(input, target)
  File "F:\_neuro\_a\util\SR\AGD\lib\search\model_infer.py", line 272, in _loss
    loss = self._criterion(logit, target)
  File "F:\_neuro\_a\util\SR\AGD\lib\search\model_infer.py", line 257, in _criterion
    y_c_features = self.vgg(x)
  File "C:\Users\eps\AppData\Local\Programs\Python\Python35\lib\site-packages\torch\nn\modules\module.py", line 547, in __call__
    result = self.forward(*input, **kwargs)
  File "C:\Users\eps\AppData\Local\Programs\Python\Python35\lib\site-packages\torch\nn\parallel\data_parallel.py", line 150, in forward
    return self.module(*inputs[0], **kwargs[0])
  File "F:\_neuro\_a\util\SR\AGD\lib\search\util_gan\vgg_feature.py", line 26, in __call__
    x_vgg = self.features(x)
  File "C:\Users\eps\AppData\Local\Programs\Python\Python35\lib\site-packages\torch\nn\modules\module.py", line 547, in __call__
    result = self.forward(*input, **kwargs)
  File "C:\Users\eps\AppData\Local\Programs\Python\Python35\lib\site-packages\torch\nn\modules\container.py", line 92, in forward
    input = module(input)
  File "C:\Users\eps\AppData\Local\Programs\Python\Python35\lib\site-packages\torch\nn\modules\module.py", line 549, in __call__
    hook_result = hook(self, input, result)
  File "C:\Users\eps\AppData\Local\Programs\Python\Python35\lib\site-packages\thop\vision\basic_hooks.py", line 31, in count_convNd
    m.total_ops += torch.DoubleTensor([int(total_ops)])
  File "C:\Users\eps\AppData\Local\Programs\Python\Python35\lib\site-packages\torch\nn\modules\module.py", line 591, in __getattr__
    type(self).__name__, name))
AttributeError: 'Conv2d' object has no attribute 'total_ops'

downgrading to thop==0.0.31.post1912272122 made it work with thop.count_hooks, and without this error. later versions have introduced some fatal breaking changes (tested on pytorch 1.2 and 1.6). would be nice to mention this in pip requirements for the repo.

ghost commented 4 years ago

@chenwydj

tilmto commented 4 years ago

Hi, you can install another thop version:

pip install thop==0.0.31.post1912272122
eps696 commented 4 years ago

@tilmto yes it's mentioned in the post above. thanks for confirming this.