计算Theano中两个热图之间的交叉熵损失

时间:2016-02-01 07:39:51

标签: python-2.7 theano

我在计算Theano中的交叉熵损失方面存在问题。

具体来说,对于我的网:

Input: (20,14,90,60) (batchsize,channels,h,w)
filter: (14,14,9,9)
output: (20,1,90,60)
groundtruth: (20,1,90,60)

我想计算每个输出的交叉熵:

for i in xrange(20):
    sum(category_crossentropy(output[i,:,:,:],groundtruth[i,:,:,:]))

在Theano中,category_crossentropy(coding_dist,true_dist),输入必须是矩阵。 但是,当程序调用费用时,self.output[20,1,90,60],地面实体为tensor.matrix

def crossEntropy(self,groundtruth):
    error = crossentropy(self.output,groundtruth)
    return error

y = T.matrix('y')
cost = refine_Net.crossEntropy(y)
    train_model = theano.function(
            inputs=[index],
            outputs=cost,
            updates=updates,
            given={
                x: train_Data[index*batch_size:(index+1)*batch_size],
                y: train_Target[index*batch_size:(index+1)*batch_size]
                })

TypeError: matrix required for argument: coding_dist

0 个答案:

没有答案