How to get the output of last layer after every batch as ndarray?

gluon
how-to

#1

I’m using the Mxnet implementation of Resnet by https://github.com/khetan2/mbem and https://github.com/tornadomeet/ResNet/
I’m using the resnet for a 10 way image classification.
I use a batch size of 500 and I want to perform a matrix operation on the output obtained after the last gully connected layer. I want to access the output as NDArray(batch X no of classes i.e. 500 x 10). Till now I’m getting it as mxnet symbol and am not able to extract the data referenced with the symbol. How do I achieve this?


#2

Hi,

If you want to perform a matrix operation on the output of after the last layer, you can write the matrix operation using the symbol api and perform your matrix multiplication symbolically.

If you do want to access the values of the output though, the following lines from the code you’re using has the values:

https://github.com/khetan2/MBEM/blob/master/resnet.py#L131 and https://github.com/tornadomeet/ResNet/blob/master/predict/predict.py#L29

Alternatively, you can get the values from output symbol using

args_params, aux_params = mod.get_params()
output_ndarray = args_params['output_label']