Neural network 如何将整数标签的无符号向量转换为二进制符号矩阵标签?
我是Theano的新手,尝试将Theano向量的标签转换为Theano矩阵。其中一个NN应用程序需要MxN二进制矩阵形式的标签,其中M是样本数,N是类数。e、 例如,labels=[0,1,2,1,2,3],banary_标签应为 [1,0,0,0];[0,1,0,0];[0,0,1,0];[0,1,0,0];[0,0,1,0];[0,0,0,1]] 我已经写了下面的代码,但无法找出问题所在Neural network 如何将整数标签的无符号向量转换为二进制符号矩阵标签?,neural-network,deep-learning,theano,Neural Network,Deep Learning,Theano,我是Theano的新手,尝试将Theano向量的标签转换为Theano矩阵。其中一个NN应用程序需要MxN二进制矩阵形式的标签,其中M是样本数,N是类数。e、 例如,labels=[0,1,2,1,2,3],banary_标签应为 [1,0,0,0];[0,1,0,0];[0,0,1,0];[0,1,0,0];[0,0,1,0];[0,0,0,1]] 我已经写了下面的代码,但无法找出问题所在 这称为一个热编码。看一下Keras的实现(到_分类) def encode_labels(y,batch
这称为一个热编码。看一下Keras的实现(到_分类)
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