本文整理汇总了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"]
示例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()))
示例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))
示例4: softmax
# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import softmax [as 别名]
def softmax(x, axis=-1):
return C.softmax(x, axis=axis)
示例5: softmax
# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import softmax [as 别名]
def softmax(x):
return C.softmax(x)
示例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
示例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