添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
print(out)

运行程序时会出现报错:

runfile('C:/Users/Administrator/.spyder-py3/temp.py', wdir='C:/Users/Administrator/.spyder-py3')
Traceback (most recent call last):
  File "C:\Users\Administrator\.spyder-py3\temp.py", line 22, in <module>
    out = ReLU.forward(a)
TypeError: forward() missing 1 required positional argument: 'x'

原因分析:

看22行,前面已经将类赋给了relu,在下一行调用内部函数的时候,要用relu,不应该用原来类的名称ReLU.

解决方案:

import numpy as np
class ReLU():
    def __init__(self):
        self.mask = None
    def forward(self, x):
        self.mask = (x <= 0)
        out = x.copy()
        out[self.mask] = 0
        return out
    def backward(self, dout):
        dout[self.mask] = 0
        dx = dout
        return dx
a = np.array([[1.0, -0.5], [-2.0, 3.0]])
relu = ReLU()
out = relu.forward(a)
print(out)
[[1. 0.]
 [0. 3.]]

在运用类的时候,要先实例化类,然后用实例化之后的名称进一步调用类内部的函数。

TypeError: Caught TypeError in replica 1 on device 1. TypeError: forward() missing 1 required positional argument: 'x' 百度了一下发现是因为我使用了多个显卡,导致在inference阶段,模型和数据不在同一个显卡上,所以后面同时报了: TypeError: forward() missing 1 re...
File ".\seg_v2\framework.py", line 13, in __init__ self.net = net().cuda() File "C:\Users\Administrator\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 722, in _call_impl result = self.forward(*input, **kwargs) TypeError: forward()
pytorch报错(4)forward() missing 1 required positional argument: ‘x‘或者‘NoneType‘ object is not callable
TypeError: forward() missing 1 required positional argument: ‘x’ #1074 在yolov4 pytorch训练时遇到此错误 解决方法: 测试集的数据量要能被BatchSize整除,简单方法是直接删除valid.txt里的标签路径。 转载请注明出处,谢谢 i = int(input('净利润:')) I = [1000000,600000,400000,200000,100000,0] r = [0.01,0.015,0.03,0.05,0.075,0.1] for j in range(len(I)): if i > I[j]: b = [0,0,0,0,0,0] b[j] = i -I[j] for k in range(j+1,len