How to extracting layers last from SSD resnet Object Detection model after fine -tunning?

How to extract last layers from SSD resnet Object Detection model after fine -tunning?

1 Like

@Emilio_Chambouleyron Welcome to Tensorflow Forum!

Extracting the last layers from an SSD ResNet Object Detection model after fine-tuning involves identifying the specific layers of interest and then using TensorFlow APIs to extract their weights and activations. Here’s a step-by-step guide:

  1. Import necessary libraries:

    Pythonimport tensorflow as tf

  2. Load the fine-tuned SSD ResNet Object Detection model:

    Pythonmodel = tf.saved_model.load('path/to/model')

  3. Identify the last layers:

    The last layers in an SSD ResNet Object Detection model are typically the feature maps that are used for object detection. These layers are typically named something like 'block5_2_out' or 'block12_3_out' .

  4. Extract the weights of the last layers:

    Pythonfor layer in model.layers: if layer.name.endswith('_out'): weights = layer.weights print(layer.name, weights)

  5. Extract the activations of the last layers:

    You can extract the activations of the last layers by passing a batch of input data through the model and then accessing the output of the desired layers:

    Pythoninput_data = ... # Load your input data output = model(input_data) activations = output['block5_2_out']

    This will give you a tensor containing the activations of the 'block5_2_out' layer for each input sample.

  6. Save the extracted weights and activations:

    You can save the extracted weights and activations to a file for later use:

    Pythontf.io.write_file('weights.h5', weights) tf.io.write_file('activations.npy', activations)

This will save the weights in HDF5 format and the activations in NumPy array format.

Let us know if this helps!