Python cntk.softmax() Examples

The following are 15 code examples of cntk.softmax(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module cntk , or try the search function .
Example #1
Source Project: dnn-model-services   Author: singnet   File: image_recon.py    License: MIT License 6 votes vote down vote up
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"] 
Example #2
Source Project: keras-text   Author: raghakot   File: layers.py    License: MIT License 6 votes vote down vote up
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())) 
Example #3
Source Project: ngraph-python   Author: NervanaSystems   File: test_ops_unary.py    License: Apache License 2.0 5 votes vote down vote up
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)) 
Example #4
Source Project: GraphicDesignPatternByPython   Author: Relph1119   File: cntk_backend.py    License: MIT License 5 votes vote down vote up
def softmax(x, axis=-1):
    return C.softmax(x, axis=axis) 
Example #5
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: cntk_backend.py    License: MIT License 5 votes vote down vote up
def softmax(x, axis=-1):
    return C.softmax(x, axis=axis) 
Example #6
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: cntk_backend.py    License: MIT License 5 votes vote down vote up
def softmax(x, axis=-1):
    return C.softmax(x, axis=axis) 
Example #7
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: cntk_backend.py    License: MIT License 5 votes vote down vote up
def softmax(x, axis=-1):
    return C.softmax(x, axis=axis) 
Example #8
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: cntk_backend.py    License: MIT License 5 votes vote down vote up
def softmax(x, axis=-1):
    return C.softmax(x, axis=axis) 
Example #9
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: cntk_backend.py    License: MIT License 5 votes vote down vote up
def softmax(x, axis=-1):
    return C.softmax(x, axis=axis) 
Example #10
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: cntk_backend.py    License: MIT License 5 votes vote down vote up
def softmax(x, axis=-1):
    return C.softmax(x, axis=axis) 
Example #11
Source Project: DeepLearning_Wavelet-LSTM   Author: hello-sea   File: cntk_backend.py    License: MIT License 5 votes vote down vote up
def softmax(x, axis=-1):
    return C.softmax(x, axis=axis) 
Example #12
Source Project: deepQuest   Author: sheffieldnlp   File: cntk_backend.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def softmax(x):
    return C.softmax(x) 
Example #13
Source Project: dnn-model-services   Author: singnet   File: models_setup.py    License: MIT License 5 votes vote down vote up
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 
Example #14
Source Project: dnn-model-services   Author: singnet   File: models_setup.py    License: MIT License 5 votes vote down vote up
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 
Example #15
Source Project: keras-lambda   Author: sunilmallya   File: cntk_backend.py    License: MIT License 5 votes vote down vote up
def softmax(x):
    return C.softmax(x)