當前位置: 首頁>>代碼示例>>Python>>正文


Python cntk.placeholder方法代碼示例

本文整理匯總了Python中cntk.placeholder方法的典型用法代碼示例。如果您正苦於以下問題:Python cntk.placeholder方法的具體用法?Python cntk.placeholder怎麽用?Python cntk.placeholder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cntk的用法示例。


在下文中一共展示了cntk.placeholder方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_model

# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import placeholder [as 別名]
def create_model(base_model_file, input_features, num_classes,  dropout_rate = 0.5, freeze_weights = False):
    # Load the pretrained classification net and find nodes
    base_model   = load_model(base_model_file)
    feature_node = find_by_name(base_model, 'features')
    beforePooling_node = find_by_name(base_model, "z.x.x.r")
    #graph.plot(base_model, filename="base_model.pdf") # Write graph visualization

    # Clone model until right before the pooling layer, ie. until including z.x.x.r
    modelCloned = combine([beforePooling_node.owner]).clone(
        CloneMethod.freeze if freeze_weights else CloneMethod.clone,
        {feature_node: placeholder(name='features')})

    # Center the input around zero and set model input.
    # Do this early, to avoid CNTK bug with wrongly estimated layer shapes
    feat_norm = input_features - constant(114)
    model = modelCloned(feat_norm)

    # Pool over all spatial dimensions and add dropout layer
    avgPool = GlobalAveragePooling(name = "poolingLayer")(model)
    if dropout_rate > 0:
        avgPoolDrop = Dropout(dropout_rate)(avgPool)
    else:
        avgPoolDrop = avgPool

    # Add new dense layer for class prediction
    finalModel = Dense(num_classes, activation=None, name="prediction") (avgPoolDrop)
    return finalModel


# Trains a transfer learning model 
開發者ID:Azure-Samples,項目名稱:MachineLearningSamples-ImageClassificationUsingCntk,代碼行數:32,代碼來源:helpers_cntk.py

示例2: placeholder

# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import placeholder [as 別名]
def placeholder(
        shape=None,
        ndim=None,
        dtype=None,
        sparse=False,
        name=None,
        dynamic_axis_num=1):
    if dtype is None:
        dtype = floatx()
    if not shape:
        if ndim:
            shape = tuple([None for _ in range(ndim)])

    dynamic_dimension = C.FreeDimension if _get_cntk_version() >= 2.2 else C.InferredDimension
    cntk_shape = [dynamic_dimension if s is None else s for s in shape]
    cntk_shape = tuple(cntk_shape)

    if dynamic_axis_num > len(cntk_shape):
        raise ValueError('CNTK backend: creating placeholder with '
                         '%d dimension is not supported, at least '
                         '%d dimensions are needed.'
                         % (len(cntk_shape), dynamic_axis_num))

    if name is None:
        name = ''

    cntk_shape = cntk_shape[dynamic_axis_num:]

    x = C.input(
        shape=cntk_shape,
        dtype=_convert_string_dtype(dtype),
        is_sparse=sparse,
        name=name)
    x._keras_shape = shape
    x._uses_learning_phase = False
    x._cntk_placeholder = True
    return x 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:39,代碼來源:cntk_backend.py

示例3: is_placeholder

# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import placeholder [as 別名]
def is_placeholder(x):
    """Returns whether `x` is a placeholder.

    # Arguments
        x: A candidate placeholder.

    # Returns
        Boolean.
    """
    return hasattr(x, '_cntk_placeholder') and x._cntk_placeholder 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:12,代碼來源:cntk_backend.py

示例4: _is_input_shape_compatible

# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import placeholder [as 別名]
def _is_input_shape_compatible(input, placeholder):
        if hasattr(input, 'shape') and hasattr(placeholder, 'shape'):
            num_dynamic = get_num_dynamic_axis(placeholder)
            input_shape = input.shape[num_dynamic:]
            placeholder_shape = placeholder.shape
            for i, p in zip(input_shape, placeholder_shape):
                if i != p and p != C.InferredDimension and p != C.FreeDimension:
                    return False
        return True 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:11,代碼來源:cntk_backend.py

示例5: placeholder

# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import placeholder [as 別名]
def placeholder(
        shape=None,
        ndim=None,
        dtype=None,
        sparse=False,
        name=None,
        dynamic_axis_num=1):
    if dtype is None:
        dtype = floatx()
    if not shape:
        if ndim:
            shape = tuple([None for _ in range(ndim)])

    dynamic_dimension = C.FreeDimension if _get_cntk_version() >= 2.2 else C.InferredDimension
    cntk_shape = [dynamic_dimension if s is None else s for s in shape]
    cntk_shape = tuple(cntk_shape)

    if dynamic_axis_num > len(cntk_shape):
        raise ValueError('CNTK backend: creating placeholder with '
                         '%d dimension is not supported, at least '
                         '%d dimensions are needed.'
                         % (len(cntk_shape, dynamic_axis_num)))

    if name is None:
        name = ''

    cntk_shape = cntk_shape[dynamic_axis_num:]

    x = C.input(
        shape=cntk_shape,
        dtype=_convert_string_dtype(dtype),
        is_sparse=sparse,
        name=name)
    x._keras_shape = shape
    x._uses_learning_phase = False
    x._cntk_placeholder = True
    return x 
開發者ID:hello-sea,項目名稱:DeepLearning_Wavelet-LSTM,代碼行數:39,代碼來源:cntk_backend.py

示例6: create_criterion_function

# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import placeholder [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) 
開發者ID:singnet,項目名稱:nlp-services,代碼行數:7,代碼來源:language_understanding.py

示例7: create_model

# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import placeholder [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 
開發者ID:singnet,項目名稱:dnn-model-services,代碼行數:31,代碼來源:models_setup.py

示例8: placeholder

# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import placeholder [as 別名]
def placeholder(
        shape=None,
        ndim=None,
        dtype=_FLOATX,
        sparse=False,
        name=None,
        dynamic_axis_num=1):
    if not shape:
        if ndim:
            shape = tuple([None for _ in range(ndim)])

    cntk_shape = [C.InferredDimension if s is None else s for s in shape]
    cntk_shape = tuple(cntk_shape)

    if dynamic_axis_num > len(cntk_shape):
        raise ValueError('CNTK backend: creating placeholder with '
                         '%d dimension is not supported, at least '
                         '%d dimensions are needed.'
                         % (len(cntk_shape, dynamic_axis_num)))

    if name is None:
        name = ''

    cntk_shape = cntk_shape[dynamic_axis_num:]

    x = C.input(
        shape=cntk_shape,
        dtype=_convert_string_dtype(dtype),
        is_sparse=sparse,
        name=name)
    x._keras_shape = shape
    x._uses_learning_phase = False
    return x 
開發者ID:sunilmallya,項目名稱:keras-lambda,代碼行數:35,代碼來源:cntk_backend.py


注:本文中的cntk.placeholder方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。