Python:神经网络中的并行矩阵乘法美国运输部或者np.马特姆

2024-09-25 08:35:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我想建立一个代码,可以计算矩阵乘法在神经网络没有张量流或美国运输部或者np.材料. 在

以下是我感兴趣的代码片段:

class Affine:
def __init__(self, W, b):
    self.W = W
    self.b = b
    self.x = None
    self.original_x_shape = None
    self.dW = None
    self.db = None

def forward(self, x):
    self.original_x_shape = x.shape
    x = x.reshape(x.shape[0], -1)
    self.x = x
    out = np.dot(self.x, self.W) + self.b
    return out

该代码是神经网络(X*W+b)正向计算的一部分。而且效果很好。在

我想修改out = np.dot(self.x, self.W) + self.b行。它应该以同样的方式工作美国运输部或者np.材料. 在

以下是我的代码:

^{pr2}$

修改部分只是并行矩阵乘法。但是,发生了以下错误:AttributeError: Can't pickle local object 'Affine2.forward.<locals>.matmult'

我怎么解决这个问题?在


Tags: 代码selfnonedefnp矩阵神经网络out