Open w5688414 opened 4 years ago
Could you please show the error trace information?
I change the code like this, and it works, thanks for your response, sorry to interrupt you ` if(args.train): trainer.train() saver = ModelSaver("./cache/model_ckpt_100.pkl") saver.save_pytorch(model,param_only=False)
if(args.predict): model=ModelLoader.load_pytorch_model("./cache/model_ckpt_100.pkl")
# tester = Tester(datasets['test'], model, metrics=AccuracyMetric())
# tester.test()
from fastNLP import Tester
tester = Tester(datasets['test'], model, batch_size=args.test_batch, metrics=metrics)
tester.test()
`
congratulations! And if you use fitlog, you can run 'fitlog log logs' in the project dictionary to scan the experiment result.
Dear w5688414 or LeeSureman: i used the code if(args.train): trainer.train() saver = ModelSaver("./cache/model_ckpt_100.pkl") saver.save_pytorch(model,param_only=False)
if(args.predict): model=ModelLoader.load_pytorch_model("./cache/model_ckpt_100.pkl") tester = Tester(datasets['test'], model, batch_size=args.test_batch, metrics=metrics) tester.test()
But it has error, which said TypeError: The type of model must be 'torch.nn.Module', got '<class'collections.OrderedDict'>' i donot the reason. Who can help me?
I want to save the trained model, and load it for prediction, here is my code: ` saver = ModelSaver("./cache/model_ckpt_100.pkl")
model=ModelLoader.load_pytorch_model("./cache/model_ckpt_100.pkl")
ModelLoader.load_pytorch(model,"./cache/model_ckpt_100.pkl") tester = Tester(datasets['test'], model, metrics=AccuracyMetric()) tester.test() ` but it doesn't work, Can the author provide a way for prediction after saving the model