sidhomj / DeepTCR

Deep Learning Methods for Parsing T-Cell Receptor Sequencing (TCRSeq) Data
https://sidhomj.github.io/DeepTCR/
MIT License
110 stars 40 forks source link

load previous-trained model #66

Closed hereagain-Y closed 2 years ago

hereagain-Y commented 2 years ago

Hi Dr. John William Sidhom:

Sorry to disturb you, while I have a question about deepTCR. This is an amazing package, and I would like to use it to do sequence-level prediction. So here let us say that I train a model named 'model', and store the middle file at: /user. Then the program will generate a subfolder 'model' and store model checkpoint information there.

My question is, how to load this pre-trained model and do prediction using new data. I saw from website that 'sequence_inference' can 'load previous trained model', but I did not see an example at tutorial. So it will be extremely helpful if you may briefly tell me how to load a model from a pre-generated folder and thus utilize it to do prediction instead of train the model again.

Thanks in advance for your patience and have a great day!

sidhomj commented 2 years ago

You can see an example of how to do inference in the tutorial under VAE inference. It should work in the same way. You instantiate a DeepTCR object with the name of the model and then run Sequence_Inference method on your data.

https://github.com/sidhomj/DeepTCR/blob/master/tutorials/unsupervised/8%20-%20VAE%20Inference.ipynb

https://sidhomj.github.io/DeepTCR/api/#DeepTCR.DeepTCR.DeepTCR_base.Sequence_Inference

Hope this helps!

hereagain-Y commented 2 years ago

Hi Dr. John William Sidhom:

Thanks for your quick response! I am sorry that I may not explain my question clearly. I went through the tutorial, and I feel like the model training and sequence inference is in the same script. In the previous step I trained a model, and in the second step I do inference using previouslt trained model.

Now suppose I want to write two scripts. In the first script, I trained a model called 'modelA', and store all middle-model-checkpoint files it at /user. Then I quit this script, and initialize another program. Now the previous modelA does not exists in the python interface, but the middle-model-checkpoint files are still there under /user. So instead of train this model again, and call the model to do inference, is there anyway to load the middle-model-checkpoint files from /user, git it a name and use it to do sequence inference?

sidhomj commented 2 years ago

You simply instantiate the object with the name of the model and then run the inference method you want.

DTCR = DeepTCR_SS('modelA')
DTCR.Sequence_Inference(*args)