属性错误:'TensorVariable'对象没有'nonzeros'属性

2024-10-02 08:22:43 发布

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

我想根据它们在张量中的位置来剪辑特定的值。所以我试图得到它们的位置,当它们等于张量y中的1时,但是我收到了这个错误消息 AttributeError:“TensorVariable”对象没有属性“nonezeros”

我不能发布所有的代码,但它类似于CNN网站上的教程。在

def MSE2(self, y):
    loc = T.eq(y,1).nonezeros()[0]
    # loc = np.where(y == 1)[0]
    S = T.clip(self.input1[loc],0,1)
    self.input1 = T.set_subtensor(self.input1[loc], S)
    return T.mean((y - self.input1) ** 2)

classifier.predictor.MSE2(y)

train_model = theano.function(
        inputs=[index],
        outputs=cost,
        updates=updates,
        givens={
            x: train_set_x[index * batch_size: (index + 1) * batch_size],
            y: train_set_y[index * batch_size: (index + 1) * batch_size]
        },
        on_unused_input='ignore'
    )

我用CNN的代码测试了非零,它起到了测试的作用

^{pr2}$

Tags: 代码selfsizeindex剪辑错误batchtrain

热门问题