Search code examples
deep-learningcntk

Convert cntk model v1 to cntk model v2


I have trained a model using cntk brain script. I then needed to use my model in python. The problem is that models saved using brainscript are v1 models and have input nodes and output nodes saved. On the other hand, the models used in cntk python api are v2 models.

Is there a way to convert v1 models to v2 models format?

If there isn't, is there a way to remove the input and output nodes from version one format so that I can directly pass the features to the first layer in the model as follows:

mode= load_model("cntk_v1.model")
model = mode.clone(method = 'freeze' )
f = cntk.ops.sequence((input_dim))
z = model(f)

Solution

  • Yes, there is a way to replace your input output nodes will something else.

    Sample code below:

    new_input = C.input_variable(...)
    model = C.load_model(...)
    nodes_replacement = {model.arguments[0]: new_input, ANY_NODE_YOU_WANT_REPLACED: NEW_NODE}
    new_model = model.clone(C.CloneMethod.clone, nodes_replacement)  # done!