Teichlab / celltypist

A tool for semi-automatic cell type classification
https://www.celltypist.org/
MIT License
260 stars 40 forks source link

Loading custom model #60

Closed auesro closed 2 months ago

auesro commented 1 year ago

Dear celltypist team,

I have created my own model through training using celltypist.train, saved it to a local folder with model.write but now, I don't seem to be able to load it with models.Model.load even if I pass the full path to it...

models.Model.load('/home/auesro/Desktop/Atlas/For_Celltypist_Training/Celltypist_model_AllCells_v1.pkl')
Traceback (most recent call last):

  File "/tmp/ipykernel_149219/1064720094.py", line 1, in <module>
    models.Model.load('/home/auesro/Desktop/ Atlas/For_Celltypist_Training/Celltypist_model_AllCells_v1.pkl')

  File "/home/auesro/mambaforge/envs/Scanpy_R/lib/python3.7/site-packages/celltypist/models.py", line 90, in load
    if model in get_all_models():

  File "/home/auesro/mambaforge/envs/Scanpy_R/lib/python3.7/site-packages/celltypist/models.py", line 359, in get_all_models
    download_if_required()

  File "/home/auesro/mambaforge/envs/Scanpy_R/lib/python3.7/site-packages/celltypist/models.py", line 370, in download_if_required
    if len([m for m in os.listdir(models_path) if m.endswith(".pkl")]) == 0:

FileNotFoundError: [Errno 2] No such file or directory: '/home/auesro/.celltypist/data/models'

What is going on? I dont understand why is it not looking for it in the correct path I provided...

Thanks,

A

auesro commented 1 year ago

Solved it by changing: models.models_path to my local folder

dstueckm commented 7 months ago

Just wanted to re-raise this issue since I had the same problem and it took me quite a while to figure it out. I am running CellTypist on a cluster, and my default model path is "/cluster/home/user/.celltypist/data/models" My output (including models) are stored in a project directory, under "/cluster/projects/projectname/CellTypist/models" When I specify the full filepath to a pre-trained model (e.g., with celltypist.models.Model.load()), I get the message "No available models, Downloading..." and celltypist attempts to download models. This is only resolved by changing models.models_path to my project folder. A possible solution might be inferring the appropriate models.models_path from the filename?

Thank you, Daniel

ChuanXu1 commented 3 months ago

@dstueckm, do you mind pasting your complete error message here?

ChuanXu1 commented 2 months ago

This should have been solved now.