Search code examples
pythoncntk

CNTK Python API: evaluating hidden layers / multiple outputs


What are the recommendations for creating, saving, loading and evaluating models with multiple outputs in CNTK Python APIs? (I'm using CNTK 2.0 RC1)

When I define a network in run-time, I can evaluate any layer of the network easily, by passing a minibatch dictionary to the eval function.

However, after I save the model and load it again, I can evaluate only the output node by providing the inputs (and I don't know how to define multiple outputs in Python API). I can access any layer by using the find_all_by_name method, but when I try to evaluate hidden layers using the eval method, it expects me to provide the layer's immediate input, rather than relevant network's inputs:

ValueError: No value specified for input Variable 'Output('Block1958_Output_0', [#], [1024 x 200])' of Function 'Dense: Output('Block1958_Output_0', [#], [1024
x 200]) -> Output('conversation_vector', [#], [100])'. 

I only found the following documentation on the topic, which applies to Brainscript: https://github.com/Microsoft/CNTK/wiki/CNTK-Evaluate-Hidden-Layers -- I couldn't find anything specific to Python API.


Solution

  • model.outputs[0] is a variable, you can go to its function by model.outputs[0].owner, or as_composite(model.outputs[0].owner) if the owner is a primitive function (which only shows the immediate inputs, vs. composite function that shows the root input variables for mapping)

    So try this:

    as_composite(model.outputs[0].owner).eval(...)