0

I read several discussions about this and still cannot make it work for my case Have a classification model trained using Google Tables. Exported the model and download the directory with cli.

My goal is to get a better understanding of the model trained by google, study it, understand its decisions. And later try to prune it to improve performance.

I'm using this code, just to start:

import tensorflow as tf
from tensorflow import keras
import struct2tensor

location = "model_dir"
model = tf.saved_model.load(location)

model.summary()

I get this error: AttributeError: 'AutoTrackable' object has no attribute 'summary'

the variable model is of type: <tensorflow.python.training.tracking.tracking.AutoTrackable at 0x7fa8eaa7ed30>

And I stuck there, don't know how to continue. Using Python 3.8 and the last version of those libraries. Any idea of how can I proceed?

Thanks!

Alejandro
  • 519
  • 1
  • 6
  • 32

1 Answers1

0

The proper method to load your model depends on your file formatting.

You can see in the Tensorflow documentation that "The object returned by tf.saved_model.load is not a Keras object (i.e. doesn't have .fit, .predict, etc. methods)" and "Use tf.keras.models.load_model to restore the Keras model".

I'm not sure if you want to use the keras module or not, but since you have imported it I assume you do. In that case I would recommend checking this other Stackoverflow thread where it is explained how to use the tf.keras.models.load_model method depending if your model is saved as .pb or .h5.

If the model is saved as .pb you should use it with the string pointing to the directory where the model is saved, as you did in your code snippet but in this case using the keras method:

model = tf.keras.models.load_model('model_dir')

If instead it's saved as .h5 you should use it specifying it:

model = tf.keras.models.load_model('my_model_in_h5.h5')
bernatj
  • 97
  • 5