【问题标题】:CNTK convert label indices to one-hot vector representationCNTK 将标签索引转换为 one-hot 向量表示
【发布时间】:2017-03-20 08:58:41
【问题描述】:

将包含标签作为索引的向量(只是常规向量,而不是稀疏表示)转换为 one-hot 表示的 CNTK 方法是什么?以下是 5 个类的示例:

输入

[2, 0, 1, 1]

期望的输出:

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

有没有不经过 Python/numpy 的方法?

【问题讨论】:

标签: python cntk


【解决方案1】:

下面是如何处理one_hot(假设您有一批 4 个标签):

>>> x0 = np.array([2, 0, 1, 1]).reshape(4,1)
>>> x = C.input_variable(1)
>>> y = C.one_hot(x, 5, sparse_output=False)
>>> y(x0)
array([[[ 0.,  0.,  1.,  0.,  0.]],

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

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

       [[ 0.,  1.,  0.,  0.,  0.]]], dtype=float32)

【讨论】:

    猜你喜欢
    • 2021-04-02
    • 1970-01-01
    • 2017-09-22
    • 2020-10-10
    • 2017-07-27
    • 2019-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多