A
A
Asya2021-09-14 20:59:19
Python
Asya, 2021-09-14 20:59:19

How to save a model in Pytorch similar to saving a model in Tensorflow?

I need to save the pytorch model for subsequent prediction on new data, in order to load the model and use it in the same way as it is in tensorflow:

model = keras.models.load_model('path/to/location')
prediction = model.predict(my_new_record)

but when i do the same in python:

model = torch.load('model.pt')
prediction = model(my_new_record)

then I get:
TypeError: 'collections.OrderedDict' object is not callable

or
model.eval()
that
AttributeError: 'collections.OrderedDict' object has no attribute 'eval'


How to save the model on the python in such a way that later you don’t need to initialize TheModelClass again , but you can save any model like in tensorflow and then just load it and start using it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question