1

After choosing and downloading a model from TensorFlow 2 Detection Model Zoo, it can be loaded as followed:

import tensorflow as tf
model = tf.saved_model.load(f'./efficientdet_d0_coco17_tpu-32/saved_model/')

However, it looks like one cannot extract the number of trainable variables directly/indirectly from the model variable, according to this investigation.

Nevertheless, the model training can continue, with new data, as this is a typical use-case of a pre-trained model. There must be a way to get the number of trainable variables. But I don't know how.

I tried:

tf.trainable_variables
# AttributeError: module 'tensorflow' has no attribute 'trainable_variables'

Environment:

  • Tensorflow 2.7.0 (implying CUDA 11.2, cuDNN 8.1).
  • Windows 10 x64
  • Python 3.9.7
  • NVIDIA GeForce MX150, Compute capability: 6.1
JoyfulPanda
  • 867
  • 6
  • 14
  • Hi! It should be model.trainable_variables() when you are trying to extract trainable variables from model. Thanks! –  Feb 21 '22 at 10:33
  • @Tensorflow Support: When I typed `model.trainable_variables()`, I got `AttributeError: '_UserObject' object has no attribute 'trainable_variables'`. – JoyfulPanda Feb 22 '22 at 14:54
  • Sorry ! It was model.trainable_variables with out open brackets. Attaching a thread for reference. https://www.tensorflow.org/guide/intro_to_modules . –  Feb 23 '22 at 04:42
  • @Tensorflow Support: I tried again with `model.trainable_variables`, but still got `AttributeError: '_UserObject' object has no attribute 'trainable_variables'`. – JoyfulPanda Feb 23 '22 at 22:48

1 Answers1

0

It should be tf.compat.v1.trainable_variables()

Minhaj Ansari
  • 81
  • 1
  • 4