首页 文章

将TensorType(float32,matrix)转换为TensorType(int32,matrix)时出错

提问于
浏览
0

我编写了深度学习算法的代码 . 但是我只是处于加载数据的最后阶段 .

self.x = T.imatrix("x")
self.y = T.ivector("y")

被定义为保存数据的变量

那我呢

train_x, train_y, train_lengths = dataUtils.read_and_sort_matlab_data(path+"train.txt",path+"train_lbl.txt")
validate_x, validate_y, validate_lengths = dataUtils.read_and_sort_matlab_data(path+"valid.txt",path+"valid_lbl.txt")
tested_x, tested_y, tested_lengths = dataUtils.read_and_sort_matlab_data(path+"test.txt",path+"test_lbl.txt")

这里我检查了变量的类型,train_y的类型为numpy.ndarray,其形状为(2000,),train_y [0]的类型为'int32' .

然后我将数据放入theano共享变量

training_x,training_y = shared(train_x,train_y)
validation_x,validation_y = shared(validate_x,validate_y)
test_x,test_y = shared(tested_x,tested_y)

共享功能的定义如下

def shared(data_x,data_y):

    shared_x = theano.shared(np.asarray(data_x, dtype=theano.config.floatX), borrow=True)
    shared_y = theano.shared(np.asarray(data_y, dtype=theano.config.floatX), borrow=True)
    return shared_x, T.cast(shared_y, "int32")

我在以下代码中收到错误

train_mb = theano.function(
            [i], cost, updates=updates,
            givens={
                self.x:
                training_x[i*self.document_length: (i+1)*self.document_length],
                self.y:
                training_y[i: (i+1)]
            })

在线

training_y[i: (i+1)]

错误是

TypeError:无法将Type TensorType(float32,matrix)(Variable Subtensor {int64:int64:} . 0)转换为Type TensorType(int32,matrix) . 您可以尝试手动将Subtensor {int64:int64:} . 0转换为TensorType(int32,矩阵) .

当我已经转换了shared_y变量时,有人可以告诉我们引入了float32的位置吗?以及如何纠正此错误 . 另外,为什么在train_y是一个向量的错误语句中有矩阵,因为它的形状是什么?

1 回答

  • 0

    我找到了答案 . 它实际上是training_x位,它给出的错误不是training_y .

相关问题