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

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?

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']

the outputs variable returns the outputs for the entire dataset(i.e no.of samples X no of classes 50k X10), while I want to access them on a per batch basis(batch size x no. of classes 500x10 in my case) so that I can perform a matrix operation to propagate the resulting value as loss in that particular batch. how do i achieve the same?