Good evening,
Is there a way to save and load a model?
I use the following code to save the model:
import os
import tarfile
def save_model(model_path='/content/drive/My Drive/Erklagg/checkpoint-4860-epoch-12',file_name='checkpoint-4860-epoch-12'):
files = [files for root, dirs, files in os.walk(model_path)][0]
with tarfile.open(file_name+ '.tar.gz', 'w:gz') as f:
for file in files:
f.add(f'{model_path}/{file}')
save_model('outputs','checkpoint-4860-epoch-12')
that works so far but when I try to load the model with:
import os
import tarfile
"def unpack_model(model_name='checkpoint-4860-epoch-12'):
tar = tarfile.open(f"{model_name}.tar.gz", "r:gz")
tar.extractall()
tar.close()
unpack_model('checkpoint-4860-epoch-12')
and then try to evaluate the model I get the error:
NameError: name 'model' is not defined
Is there any better way to save and load a model?
@yon606 : The library automatically saves the check points and the best model files if you specify the path. There is a parameter called 'args' for every model which can take a dictionary of several parameters where you can specify output directory path for checkpoints and the best model to be saved.
Here is the explanation provided : https://github.com/ThilinaRajapakse/simpletransformers#args-explained
To load the model, simply specify the path in the model call. Here is the explanation : https://github.com/ThilinaRajapakse/simpletransformers#loading-saved-models
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
@yon606 : The library automatically saves the check points and the best model files if you specify the path. There is a parameter called 'args' for every model which can take a dictionary of several parameters where you can specify output directory path for checkpoints and the best model to be saved.
Here is the explanation provided : https://github.com/ThilinaRajapakse/simpletransformers#args-explained
To load the model, simply specify the path in the model call. Here is the explanation : https://github.com/ThilinaRajapakse/simpletransformers#loading-saved-models