本文整理匯總了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))