What is the CNTK way to convert a vector that contains labels as indices to a one hot-representation?

馋奶兔 提交于 2019-12-13 16:40:44

问题


In CNTK I need a way to convert a vector that contains labels as indices (just a regular vector, not a sparse representation) to a one hot-representation.

Here is an example for 5 classes:

Input

[2, 0, 1, 1]

Desired output:

[[0,0,1,0,0],
[1,0,0,0,0],
[0,1,0,0,0],
[0,1,0,0,0]]

Is there a way without going through Python/numpy?


回答1:


The ‘Value.one_hot’ method does this (converts to a sparseCSC matrix representation internally).

https://www.cntk.ai/pythondocs/cntk.html?highlight=one_hot#cntk.core.Value.one_hot




回答2:


If you're going to use these labels as tags for output layer then probably you'll have to use a numpy array. You should look at this answer.



来源:https://stackoverflow.com/questions/42896773/what-is-the-cntk-way-to-convert-a-vector-that-contains-labels-as-indices-to-a-on

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!