当前位置: 首页>>代码示例>>Python>>正文


Python cntk.one_hot方法代码示例

本文整理汇总了Python中cntk.one_hot方法的典型用法代码示例。如果您正苦于以下问题:Python cntk.one_hot方法的具体用法?Python cntk.one_hot怎么用?Python cntk.one_hot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cntk的用法示例。


在下文中一共展示了cntk.one_hot方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: gather

# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import one_hot [as 别名]
def gather(reference, indices):
    # There is a bug in cntk gather op which may cause crash.
    # We have made a fix but not catched in CNTK 2.1 release.
    # Will update with gather op in next release
    if _get_cntk_version() >= 2.2:
        return C.ops.gather(reference, indices)
    else:
        num_classes = reference.shape[0]
        one_hot_matrix = C.ops.one_hot(indices, num_classes)
        return C.times(one_hot_matrix, reference, output_rank=len(reference.shape) - 1) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:12,代码来源:cntk_backend.py

示例2: sparse_categorical_crossentropy

# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import one_hot [as 别名]
def sparse_categorical_crossentropy(target, output, from_logits=False, axis=-1):
    # Here, unlike other backends, the tensors lack a batch dimension:
    axis_without_batch = -1 if axis == -1 else axis - 1
    output_dimensions = list(range(len(output.shape)))
    if axis_without_batch != -1 and axis_without_batch not in output_dimensions:
        raise ValueError(
            '{}{}{}'.format(
                'Unexpected channels axis {}. '.format(axis_without_batch),
                'Expected to be -1 or one of the axes of `output`, ',
                'which has {} dimensions.'.format(len(output.shape))))
    target = C.one_hot(target, output.shape[axis_without_batch],
                       axis=axis_without_batch)
    target = C.reshape(target, output.shape)
    return categorical_crossentropy(target, output, from_logits, axis=axis) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:16,代码来源:cntk_backend.py

示例3: one_hot

# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import one_hot [as 别名]
def one_hot(indices, num_classes):
    return C.one_hot(indices, num_classes) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:4,代码来源:cntk_backend.py

示例4: in_top_k

# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import one_hot [as 别名]
def in_top_k(predictions, targets, k):
    _targets = C.one_hot(targets, predictions.shape[-1])
    result = C.classification_error(predictions, _targets, topN=k)
    return 1 - C.reshape(result, shape=()) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:6,代码来源:cntk_backend.py

示例5: emit_Embedding

# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import one_hot [as 别名]
def emit_Embedding(self, IR_node):
        
        codes = list()
        codes.append("{}_P = cntk.one_hot({}, __weights_dict['{}']['weights'].shape[0])".format(
            IR_node.variable_name,
            self.parent_variable_name(IR_node),
            IR_node.name))
        
        codes.append("{:<15} = layers.Embedding(weights=__weights_dict['{}']['weights'])({}_P)".format(
            IR_node.variable_name,
            # IR_node.get_attr('output_dim'),
            IR_node.name,
            IR_node.variable_name))

        return codes 
开发者ID:microsoft,项目名称:MMdnn,代码行数:17,代码来源:cntk_emitter.py

示例6: sparse_categorical_crossentropy

# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import one_hot [as 别名]
def sparse_categorical_crossentropy(target, output, from_logits=False):
    target = C.one_hot(target, output.shape[-1])
    target = C.reshape(target, output.shape)
    return categorical_crossentropy(target, output, from_logits) 
开发者ID:hello-sea,项目名称:DeepLearning_Wavelet-LSTM,代码行数:6,代码来源:cntk_backend.py


注:本文中的cntk.one_hot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。