3

My goal is to visualize a model classifying an image. For the visualization I need the raw activations / outputs of each layer. Is there a way to access these when predicting? Furthermore, it would be very helpful if there is a way to access the weights. However, this is only optional.

The models to visualize are built dynamically and will be used to classify images of the MNIST and EMNIST data sets.

model.summary() of an exemplary model:

=======================================================================
LayerName (LayerType)   nIn,nOut   TotalParams   ParamsShape           
=======================================================================
layer0 (DenseLayer)     784,200    157.000       W:{784,200}, b:{1,200}
layer1 (DenseLayer)     200,100    20.100        W:{200,100}, b:{1,100}
layer2 (OutputLayer)    100,10     1.010         W:{100,10}, b:{1,10}  
-----------------------------------------------------------------------
            Total Parameters:  178.110
        Trainable Parameters:  178.110
           Frozen Parameters:  0
=======================================================================

The code for image classification:

INDArray reshaped = reshapeImage(image);
int predictedIndex = model.predict(reshaped)[0];
double conf = model.output(reshaped).getDouble(predictedIndex);

If you need more information / code snippets, please let me know.

Leyens
  • 81
  • 1
  • 6

0 Answers0