Home > Software design >  what is equivalent to torch.load() in tensorflow?
what is equivalent to torch.load() in tensorflow?

Time:11-05

I want to know if there is any way to see the parameters of models in tensorflow. there is a command in pytorch i.e. torch.load('/filepath').

CodePudding user response:

Providing you have already have a model saved on file this should do the trick:

model = tf.keras.models.load_model(MODEL_PATH)
model.summary()

Check out this for more info on saving and loading models: https://www.tensorflow.org/guide/keras/save_and_serialize#how_to_save_and_load_a_model

CodePudding user response:

For a prediction context, you can do a

model = tf.keras.models.load_model(PATH, compile=True)

That works with both .h5 keras models and models on SavedModel format. Otherwise you might have to provide custom metrics and training code you may not have on the prediction context.

For references, check it here: https://www.tensorflow.org/api_docs/python/tf/keras/models/load_model

  • Related