index = T.iscalar() train_function = theano.function(inputs = [index], outputs = [cost_function], updates = updates, givens = { x: train_set[0][index * batch_size: (index + 1) * batch_size], y: train_set[1][index * batch_size: (index + 1) * batch_size] })
我在尝试按照Theano教程进行学习,并尝试实现我自己的逻辑回归版本。我已经创建了一个函数,该函数接受一个整数输入并训练模型。train_set[0]是整个矩阵数据,train_set[1]是整个标签数据
X和Y分别是矩阵和标签数据的子集
由于我是批量训练的,我需要从数据中移除批量样本,我使用index变量来完成这个操作。
然而,在这段代码中我遇到了以下错误
TypeError: slice indices must be integers or None or have an __index__ method
我也尝试过
index = lscalar()
有什么建议吗?
回答:
已经解决了问题。需要将train_set[0]和test_set[0]转换为Theano数组变量