Access intermediate layer

I would like to access intermediate layer of a model for prediction (using feature maps). I can use tf.keras directly to achieve this:

model = <MobilenetV2 transfer learning model>
inter_model  = tf.keras.Model([model.input], model.get_layer("Conv_1").output)
inter_model.predict([img])

How can it be possible using EdgeIpulse eim Linux Python SDK or C++ inferencing SDK?

Hi @naveen I’d do this by downloading the savedmodel file from dashboard and then doing it from python.

Hi @janjongboom, I am already using the Keras H5 model (dowloaded from the dashboard) which allows me to select any layers but I wanted to use the existing EI SDK to use all preprocessing and inferencing api with quantized model. The target device is RPi so running full model would be slow. I am thinking to retrain a new model up to the layer I wanted to select. I hope running two eim in a python script would not be an issue.

Hi @naveen Would this work?

with the quantized int8 tflite model?

We don’t have any plans to add intermediate layer support to the SDK anytime soon (we’ll probably build out parts over the next months to do some new anomaly detection approach, but I wouldn’t hold my breath :slight_smile: ).

1 Like

Thanks @janjongboom, I wanted to avoid using TFLite interpreter directly but I will try the solution mentioned in the link.