How can I obtain the output of an intermediate layer

12 views
Skip to first unread message

msabda...@gmail.com

unread,
Sep 29, 2019, 3:27:20 PM9/29/19
to Chainer User Group
Good day all,

In keras/tensorflow, it is possible to access or otain the output of any layer from the model as in the code below

from keras import backend as K


get_3rd_layer_output
= K.function([model.layers[0].input, K.learning_phase()],
 
[model.layers[3].output])

# output in test mode = 0
layer_output
= get_3rd_layer_output([x, 0])[0]

# output in train mode = 1
layer_output
= get_3rd_layer_output([x, 1])[0]

My question is there a way of acheiving the same in chainer?

Your kind help is highly appreciated. Thank you.

Abdullahi Mohammad

Kenichi Maehashi

unread,
Sep 30, 2019, 1:24:30 AM9/30/19
to Chainer User Group
Hi Abdullahi,

If you are using Sequential model, you can create another Sequential instance by indexing, e.g.,

>>> sub_sequential = chainer.Sequential(*original_sequential[0:2])


Thanks,

Kenichi
Reply all
Reply to author
Forward
0 new messages