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