microsoft / CNTK

Microsoft Cognitive Toolkit (CNTK), an open source deep-learning toolkit
https://docs.microsoft.com/cognitive-toolkit/
Other
17.51k stars 4.28k forks source link

How to access representation of the hidden layers in CNTK 2.2? #2688

Open bzigon opened 6 years ago

bzigon commented 6 years ago

Assume I have a simple model.

def create_model(out_classes): f1 = Dense(16, activation=C.relu,bias=True,init_bias=0,name='FLayer') l1 = Dense(16, activation=C.relu, bias=True, init_bias=0, name='LLayer')(f1) c1 = Dense(out_classes,name='CLayer')(l1) return c1

model = create_model(nClasses) z = model(feature)

How do I access the representation of the FLayer and LLayer during the testing of my trained model?

frankibem commented 6 years ago

See here for an full example.

You can obtain a named node using: flayer = cntk.combine([z.find_by_name('FLayer').owner])

Then you can evaluate to obtain outputs using eval: output = flayer.eval(mb[...])