'How to print the layers of the tensorflow 2 saved_model

I am using tensorflow 2.6.2 and I downloaded the model from the Tensorflow 2 Model zoo I am able to load the model using this

import tensorflow as tf

if __name__ == "__main__":
    try:
        model = tf.saved_model.load("/home/user/git/models_zoo/ssd_mobilenet_v2_320x320_coco17_tpu-8/saved_model/")

But unfortunately I am not able to see all the layers of the model using the below

for v in model.trainable_variables:
  print(v.name)

which should ideally print all the layers in the network, but I am getting the following error

    print(model.trainable_variables)
AttributeError: '_UserObject' object has no attribute 'trainable_variables'

Can someone please tell, what I am doing wrong here.



Solution 1:[1]

I was able to print using this

        loaded = tf.saved_model.load("/home/user/git/models_zoo/ssd_mobilenet_v2_320x320_coco17_tpu-8/saved_model/")
        infer = loaded.signatures["serving_default"]
        for v in infer.trainable_variables:
            print(v.name)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sachin Mohan