zoukankan      html  css  js  c++  java
  • Pytorch出现 raise NotImplementedError

    ---------------------------------------------------------------------------
    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:UsershappyAnaconda3libsite-packages	orch
    nmodulesmodule.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:UsershappyAnaconda3libsite-packages	orch
    nmodulesmodule.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

    https://www.cnblogs.com/jiangkejie/p/13039999.html

  • 相关阅读:
    除法
    01.python对象
    00.基础入门
    00.斐波那契数列第n项
    16.分治排序
    15.快速排序
    14.插入排序--希尔排序(缩小增量排序)
    13.插入排序--直接插入排序(简单插入排序)
    12.选择排序
    11.冒泡排序
  • 原文地址:https://www.cnblogs.com/z-712/p/13568171.html
Copyright © 2011-2022 走看看