2017-03-03 61 views
0

我是Theano的新手,并试图将theano矢量标签转换为theano矩阵。 NN应用程序中的一个需要以MxN的二进制矩阵形式的标签,其中M是样本的数量,N是类的数量。例如标签= [0,1,2,1,2,3],banary_labels应该是 [[1,0,0,0]; [0,1,0,0]; [0,0,1,0]; [0,1,0,0]; [0,0,1,0]; [0,0,0,1]如何将整数符号向量的整数标签转换为二进制符号矩阵标签?

我写了下面的代码,但无法弄清楚它是什么问题

def encode_labels(y,batch_size,max_label): 
    y=T.ivector('y') 
    b_y=T.zeros(shape=(batch_size,max_label+1),dtype=theano.config.floatX) 
    enc,update=theano.scan(lambda i,j:1, 
    sequences=[T.arange(batch_size),y], 
    outputs_info=b_y) 

    encode_l=theano.function(inputs=y,outputs=enc) 
    return encode_l 

y=[0,1,2,1,2,3] 
b_y=encode_labels(y,6,3) 
print b_y 

回答

0

这就是所谓的一个热编码。看看Keras的实现(to_categorical)here.

相关问题