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


Python cntk.classification_error方法代码示例

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


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

示例1: _create_model_and_execute_test

# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import classification_error [as 别名]
def _create_model_and_execute_test(params):
    # Create CNTK model
    input_var = C.input_variable(params['input_dim'], np.float32)
    params['input_var'] = input_var
    params['act_fun'] = C.layers.blocks.identity
    params['init_fun'] = C.glorot_uniform()

    model = params['create_model'](params)

    label_var = C.input_variable((params['label_dim']), np.float32)
    loss = C.cross_entropy_with_softmax(model, label_var)
    eval_error = C.classification_error(model, label_var)

    lr_schedule = C.learning_rate_schedule(0.05, C.UnitType.minibatch)
    learner = C.sgd(model.parameters, lr_schedule)
    trainer = C.Trainer(model, (loss, eval_error), [learner])

    input_value, label_value = _generate_random_sample(
        params['batch_size'],
        params['input_dim'],
        params['label_dim']
    )

    # Import to ngraph
    ng_loss, placeholders = CNTKImporter(batch_size=params['batch_size']).import_model(loss)
    parallel_update = CommonSGDOptimizer(0.05).minimize(ng_loss, ng_loss.variables())

    transformer = ng.transformers.make_transformer()
    update_fun = transformer.computation([ng_loss, parallel_update], *placeholders)

    # Execute on CNTK
    trainer.train_minibatch({input_var: input_value, label_var: label_value})
    cntk_ret = trainer.previous_minibatch_loss_average

    # Execute on ngraph
    input_value = np.moveaxis(input_value, 0, -1)
    label_value = np.moveaxis(label_value, 0, -1)
    ng_ret = update_fun(input_value, label_value)[0]

    return cntk_ret, ng_ret 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:42,代码来源:test_ops_compoud.py

示例2: classification_error

# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import classification_error [as 别名]
def classification_error(target, output, axis=-1):
    return C.ops.reduce_mean(
        C.equal(
            argmax(
                output,
                axis=-1),
            argmax(
                target,
                axis=-1)),
        axis=C.Axis.all_axes()) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:12,代码来源:cntk_backend.py

示例3: in_top_k

# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import classification_error [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

示例4: create_criterion_function_preferred

# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import classification_error [as 别名]
def create_criterion_function_preferred(model, labels):
        ce = C.cross_entropy_with_softmax(model, labels)
        errs = C.classification_error(model, labels)
        return ce, errs  # (model, labels) -> (loss, error metric) 
开发者ID:singnet,项目名称:nlp-services,代码行数:6,代码来源:language_understanding.py

示例5: create_criterion_function

# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import classification_error [as 别名]
def create_criterion_function(model):
        labels = C.placeholder(name='labels')
        ce = C.cross_entropy_with_softmax(model, labels)
        errs = C.classification_error(model, labels)
        return C.combine([ce, errs])  # (features, labels) -> (loss, metric) 
开发者ID:singnet,项目名称:nlp-services,代码行数:7,代码来源:language_understanding.py

示例6: classification_error

# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import classification_error [as 别名]
def classification_error(output, target, axis=-1):
    return C.ops.reduce_mean(
        C.equal(
            argmax(
                output,
                axis=-1),
            argmax(
                target,
                axis=-1)),
        axis=C.Axis.all_axes()) 
开发者ID:sunilmallya,项目名称:keras-lambda,代码行数:12,代码来源:cntk_backend.py


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