本文整理汇总了Python中cntk.combine方法的典型用法代码示例。如果您正苦于以下问题:Python cntk.combine方法的具体用法?Python cntk.combine怎么用?Python cntk.combine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cntk
的用法示例。
在下文中一共展示了cntk.combine方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init
# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import combine [as 别名]
def init():
""" Initialise ResNet 152 model
"""
global trainedModel, labelLookup, mem_after_init
start = t.default_timer()
# Load the model and labels from disk
with open(LABEL_FILE, 'r') as f:
labelLookup = [l.rstrip() for l in f]
# Load model and load the model from brainscript (3rd index)
trainedModel = load_model(MODEL_FILE)
trainedModel = combine([trainedModel.outputs[3].owner])
end = t.default_timer()
loadTimeMsg = "Model loading time: {0} ms".format(round((end - start) * 1000, 2))
logger.info(loadTimeMsg)
示例2: audio_encoder_3
# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import combine [as 别名]
def audio_encoder_3(input, model_file, cloning=False):
# Load and freeze pre-trained encoder
last_layer_name = "t_conv3"
model = C.load_model(model_file)
input_node = model.find_by_name("input")
last_conv = model.find_by_name(last_layer_name)
if not last_conv:
raise ValueError("the layer does not exist")
h = C.combine([last_conv.owner]).clone(C.CloneMethod.clone if cloning else C.CloneMethod.freeze, {input_node: input})
return h
示例3: create_criterion_function
# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import combine [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)
示例4: create_model
# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import combine [as 别名]
def create_model(model_details, num_classes, input_features, new_prediction_node_name="prediction", freeze=False):
# Load the pre-trained classification net and find nodes
base_model = cntk.load_model(model_details["model_file"])
feature_node = cntk.logging.find_by_name(base_model, model_details["feature_node_name"])
last_node = cntk.logging.find_by_name(base_model, model_details["last_hidden_node_name"])
if model_details["inception"]:
node_outputs = cntk.logging.get_node_outputs(base_model)
last_node = node_outputs[5]
feature_node = cntk.logging.find_all_with_name(base_model, "")[-5]
if model_details["vgg"]:
last_node = cntk.logging.find_by_name(base_model, "prob")
feature_node = cntk.logging.find_by_name(base_model, "data")
# Clone the desired layers with fixed weights
cloned_layers = cntk.combine([last_node.owner]).clone(
cntk.CloneMethod.freeze if freeze else cntk.CloneMethod.clone,
{feature_node: cntk.placeholder(name="features")},
)
# Add new dense layer for class prediction
feat_norm = input_features - cntk.Constant(114)
cloned_out = cloned_layers(feat_norm)
z = cntk.layers.Dense(num_classes, activation=None, name=new_prediction_node_name)(cloned_out)
return z
# Trains a transfer learning model
示例5: stop_gradient
# 需要导入模块: import cntk [as 别名]
# 或者: from cntk import combine [as 别名]
def stop_gradient(variables):
return C.stop_gradient(C.combine(variables))