--------------------------------------------------------------------------- NotImplementedError Traceback (most recent call last) <ipython-input-32-aa392119100c> in <module>() 1 print(image.unsqueeze(0).shape) ----> 2 pred = network(image.unsqueeze(0)) 3 #print(pred.shape) D:\Users\Zhappy\Anaconda3\lib\site-packages\torch\nn\modules\module.py in __call__(self, *input, **kwargs) 530 result = self._slow_forward(*input, **kwargs) 531 else: --> 532 result = self.forward(*input, **kwargs) 533 for hook in self._forward_hooks.values(): 534 hook_result = hook(self, input, result) D:\Users\Zhappy\Anaconda3\lib\site-packages\torch\nn\modules\module.py in forward(self, *input) 94 registered hooks while the latter silently ignores them. 95 """ ---> 96 raise NotImplementedError 97 98 def register_buffer(self, name, tensor): NotImplementedError:
問題所在
這個錯誤其實是個提醒錯誤,在父類中定義一個方法,知道有這個方法,不知道如何實現或者不想實現,等有人繼承他,就得幫他實現,不實現就報錯,提醒你父類里有一個方法你沒實現
1、對齊問題
我的是——def forward多了一個Tap位,它與def __init__並不對齊
解決方案:
刪除def forward多出的Tap位,將其與def __init__對齊即可。
2、拼寫錯誤,繼承原因不能拼錯
解決方案:
檢查拼寫,常見的拼寫錯誤:forward--forword
參考文獻
https://blog.csdn.net/weixin_42630613/article/details/106430063