【发布时间】:2016-03-02 14:02:02
【问题描述】:
调用 test_model 时出现以下错误:
TypeError: slice indices must be integers or None or have an __index__ method
但我使用整数(特定批次)调用 test_model。 Inputtest 是浮点数列表,labeltes 是整数向量。我不确定是什么问题。
def optimize(learning_rate = 0.1,n_epochs = 1000, batch_size = 600):
n_train_batches = len(inputt)//batch_size
n_val_batches = len(inputsdev)//batch_size
n_test_batches = len(inputstest)//batch_size
rng = numpy.random.RandomState(1234)
index = T.lscalar('index')
x = T.ivector('x')
y = T.ivector('y')
classifier = Regression(x, n_in = 150, n_out = 24)
cost = classifier.negative_log_likelihood(labelt)
test_model = theano.function(inputs = [index], outputs = classifier.errors(y),givens = { x: inputstest[index * batch_size:(index + 1) * batch_size], y : labeltes[index * batch_size:(index + 1) * batch_size]})
【问题讨论】:
-
你能发布完整的堆栈跟踪
-
你能把你的问题解释清楚吗?
-
什么是
T.lscalar('index')?奇怪的是,它不是int-like,并且将它乘以int不会产生int-like。 -
是labeltes还是labeltest?确保不是拼写错误。
-
如果没有更多细节,可能无法看到发生了什么。我的猜测是
inputstest和/或labeltes不是共享变量,但它们必须是。如果它们是普通的 numpy 数组,则不能使用 Theano 符号索引对 numpy 数组进行切片,即符号表达式index * batch_size:(index + 1) * batch_size的结果。