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


Python cntk.softmax方法代码示例

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


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

示例1: eval_single_image

# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import softmax [as 别名]
def eval_single_image(loaded_model, image_path, image_dims):
    # Load and format image (resize, RGB -> BGR, CHW -> HWC)
    try:
        img = Image.open(image_path)

        if image_path.endswith("png"):
            temp = Image.new("RGB", img.size, (255, 255, 255))
            temp.paste(img, img)
            img = temp
        resized = img.resize((image_dims[2], image_dims[1]), Image.ANTIALIAS)
        bgr_image = np.asarray(resized, dtype=np.float32)[..., [2, 1, 0]]
        hwc_format = np.ascontiguousarray(np.rollaxis(bgr_image, 2))

        # Compute model output
        arguments = {loaded_model.arguments[0]: [hwc_format]}
        output = loaded_model.eval(arguments)

        # Return softmax probabilities
        sm = cntk.softmax(output[0])
        return sm.eval()

    except FileNotFoundError:
        log.error("Could not open (skipping file): ", image_path)
        return ["None"] 
开发者ID:singnet,项目名称:dnn-model-services,代码行数:26,代码来源:image_recon.py

示例2: _softmax

# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import softmax [as 别名]
def _softmax(x, dim):
    """Computes softmax along a specified dim. Keras currently lacks this feature.
    """

    if K.backend() == 'tensorflow':
        import tensorflow as tf
        return tf.nn.softmax(x, dim)
    elif K.backend() is 'cntk':
        import cntk
        return cntk.softmax(x, dim)
    elif K.backend() == 'theano':
        # Theano cannot softmax along an arbitrary dim.
        # So, we will shuffle `dim` to -1 and un-shuffle after softmax.
        perm = np.arange(K.ndim(x))
        perm[dim], perm[-1] = perm[-1], perm[dim]
        x_perm = K.permute_dimensions(x, perm)
        output = K.softmax(x_perm)

        # Permute back
        perm[dim], perm[-1] = perm[-1], perm[dim]
        output = K.permute_dimensions(x, output)
        return output
    else:
        raise ValueError("Backend '{}' not supported".format(K.backend())) 
开发者ID:raghakot,项目名称:keras-text,代码行数:26,代码来源:layers.py

示例3: test_softmax

# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import softmax [as 别名]
def test_softmax():
    assert_cntk_ngraph_isclose(C.softmax([[1, 1, 2, 3]]))
    assert_cntk_ngraph_isclose(C.softmax([1, 1]))
    assert_cntk_ngraph_isclose(C.softmax([[[1, 1], [3, 5]]], axis=-1))
    # This test is failing, bug must be fixed:
    # assert_cntk_ngraph_isclose(C.softmax([[[1, 1], [3, 5]]], axis=1)) 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:8,代码来源:test_ops_unary.py

示例4: softmax

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

示例5: softmax

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

示例6: eval_single_image

# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import softmax [as 别名]
def eval_single_image(loaded_model, image_path, image_dims):
    # Load and format image (resize, RGB -> BGR, CHW -> HWC)
    try:
        img = Image.open(image_path)

        if image_path.endswith("png"):
            temp = Image.new("RGB", img.size, (255, 255, 255))
            temp.paste(img, img)
            img = temp
        resized = img.resize((image_dims[2], image_dims[1]), Image.ANTIALIAS)
        bgr_image = np.asarray(resized, dtype=np.float32)[..., [2, 1, 0]]
        hwc_format = np.ascontiguousarray(np.rollaxis(bgr_image, 2))

        # compute model output
        arguments = {loaded_model.arguments[0]: [hwc_format]}
        output = loaded_model.eval(arguments)

        # return softmax probabilities
        sm = cntk.softmax(output[0])

        return sm.eval()

    except FileNotFoundError:
        print("Could not open (skipping file): ", image_path)
        return ["None"]


# Evaluates an image set using the provided model 
开发者ID:singnet,项目名称:dnn-model-services,代码行数:30,代码来源:models_setup.py

示例7: eval_single_image_imagenet

# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import softmax [as 别名]
def eval_single_image_imagenet(opt_model, loaded_model, image_path, image_dims):
    img = Image.open(image_path)

    if image_path.endswith("png"):
        temp = Image.new("RGB", img.size, (255, 255, 255))
        temp.paste(img, img)
        img = temp
    resized = img.resize((image_dims[2], image_dims[1]), Image.ANTIALIAS)
    bgr_image = np.asarray(resized, dtype=np.float32)[..., [2, 1, 0]]
    hwc_format = np.ascontiguousarray(np.rollaxis(bgr_image, 2))

    if "VGG" in opt_model:
        arguments = {loaded_model.arguments[0]: [hwc_format]}
        output = loaded_model.eval(arguments)
        sm = cntk.softmax(output[0])
        return sm.eval()

    elif "InceptionV3" in opt_model:
        z = cntk.as_composite(loaded_model[0].owner)
        output = z.eval({z.arguments[0]: [hwc_format]})

    else:
        z = cntk.as_composite(loaded_model[3].owner)
        output = z.eval({z.arguments[0]: [hwc_format]})

    predictions = np.squeeze(output)
    return predictions 
开发者ID:singnet,项目名称:dnn-model-services,代码行数:29,代码来源:models_setup.py


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