Search code examples
tensorflowdeep-learningtransfer-learningtensorflow-hub

How to get all layers' activations for a specific input for Tensorflow Hub modules?


I am new to Tensorflow Hub. I want to use I3D module and finetune this network to another dataset and I need to get the last hidden layer as well as some other layers' outputs. I was wondering if there is a way to get the other layers' activations. The only signature provided for I3D is just "default". I think there should be a way to get the output of all layers easily with Tensorflow Hub modules.

import tensorflow_hub as hub
module = hub.Module("https://tfhub.dev/deepmind/i3d-kinetics-600/1", trainable=False)
logits = module(inp)

This will give me the final layer output. How can I get other layer's outputs, for example, the second convolution layer's output?


Solution

  • https://tfhub.dev/deepmind/i3d-kinetics-400/1 (and also the *-600 version) happen to export only the final layer, so there is no properly supported way to get the other layers. (That said, you can always experiment by inspecting the graph and selecting tensors by name, but this has a real risk to stop working with newer module or library versions.)