我想根据它们在张量中的位置来剪辑特定的值。所以我试图得到它们的位置,当它们等于张量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}$
该方法称为^{} ,这就是第二个示例起作用的原因:
第一个没有:
^{pr2}$相关问题 更多 >
编程相关推荐