當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。