Theano TensorVariable对象没有属性get_value

时间:2017-02-08 16:45:30

标签: python theano

我有以下theano对象:

train_set_x = cPickle.load(f)
print (train_set_x.type, train_set_x.get_value().shape)
>>TensorType(float64, matrix) (1000000L, 64L)

然而,当我尝试切片时,再次获得形状

train_set_x = train_set_x[:100]
print (train_set_x.type)
>>TensorType(float64, matrix)
n_train_batches = train_set_x.get_value(borrow=True).shape[0]
>>AttributeError: 'TensorVariable' object has no attribute 'get_value'

有人可以解释为什么切片之后我会收到这个错误吗?

由于

1 个答案:

答案 0 :(得分:0)

train_set_x是theano共享变量,因此您无法将其设置为train_set_x = train_set_x[:100]

您应该尝试使用set_value():

train_set_x.set_value(train_set_x.get_value()[:100])