question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Loading the saved model for testing, resets some of the layers.

See original GitHub issue

After training the model and saving it, when the model is loaded again for additional evaluation the accuracy is significantly lower than the one that is reported right after training the model. It seems that the model does not load some layers, possibly the softmax layer, or am I loading it wrong?

save_path = "path to the saved model " reader= "our reader" model = SentenceTransformer(model_name)

train_loss = losses.SoftmaxLoss(model=model, sentence_embedding_dimension=model.get_sentence_embedding_dimension(), num_labels=train_num_labels)

test_data = SentencesDataset(examples=reader.get_examples('test.tsv'), model=model, shorten=True) test_dataloader = DataLoader(test_data, shuffle=False, batch_size=batch_size) evaluator = LabelAccuracyEvaluator(test_dataloader, softmax_model=train_loss)

model.evaluate(evaluator)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
wadhwasahilcommented, Jun 15, 2020

How do I save the Softmax layer and load it while evaluation?

add this to the end of the fit function: example : torch.save(SOFTMAX_LAYER,os.path.join(model_save_path,"2_Softmax/pytorch_model.bin"))

and load before the evaluator train_loss.classifier=torch.load(os.path.join(model_save_path,"2_Softmax/pytorch_model.bin"))

Actually

train_loss.classifier=torch.load(os.path.join(model_save_path,"2_Softmax/pytorch_model.bin")) doesn't work, rather this works

train_loss=torch.load(os.path.join(model_save_path,"2_Softmax/pytorch_model.bin"))

5reactions
satya77commented, Jun 11, 2020

How do I save the Softmax layer and load it while evaluation?

add this to the end of the fit function: example : torch.save(SOFTMAX_LAYER,os.path.join(model_save_path,"2_Softmax/pytorch_model.bin"))

and load before the evaluator train_loss.classifier=torch.load(os.path.join(model_save_path,"2_Softmax/pytorch_model.bin"))

Read more comments on GitHub >

github_iconTop Results From Across the Web

Save and load models | TensorFlow Core
There are different ways to save TensorFlow models depending on the API you're ... To test, reset the model, and load the latest...
Read more >
Loading saved model fails with ValueError You are trying to ...
Loading saved model fails with ValueError You are trying to load a weight file containing 1 layers into a model with 0 layers...
Read more >
How to Save and Load Your Keras Deep Learning Model
The weights are saved directly from the model using the save_weights() function and later loaded using the symmetrical load_weights() function.
Read more >
Loading a saved model in Keras with a custom layer and ...
When I try to load any of these tests now and run it again, it achieves around 50% accuracy. I'm extremely confident I'm...
Read more >
Part I: Saving and Loading of Keras Sequential and Functional ...
Model architecture includes Keras layers used in the model ... Loading the saved weights to newly created model and checking performance.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found