Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to change where models will be downloaded? #313

Closed
VasylVaskivskyi opened this issue Aug 16, 2021 · 14 comments
Closed

Is there a way to change where models will be downloaded? #313

VasylVaskivskyi opened this issue Aug 16, 2021 · 14 comments

Comments

@VasylVaskivskyi
Copy link

I have a problem with running Cellpose in a pipeline inside a container. The problem is that at each run of the pipeline Cellpose redownloads models, although they are already present in the container in the proper location. This happens because Cellpose looks for models in the $HOME directory, and $HOME directory is changed during the pipeline runtime.

So is there a way to change the directory in which Cellpose will look for model files?

@tibuch
Copy link

tibuch commented Aug 19, 2021

I have a similar issue. My home is very small since all my files are stored in another file-system. It would be great if we could provide a location for the downloaded models.

I guess this would be the place: https://github.com/MouseLand/cellpose/blob/master/cellpose/models.py#L45

@Prehani
Copy link

Prehani commented Sep 30, 2021

I also had this issue when trying to run cellpose on a distributed compute system. The workaround I found is to create a miniconda environment with the relevant packages that you need installed, run a basic script to have cellpose import models, pack with conda-pack, and pass that tarred conda environment into your container. This is far from optimal, but it gets around downloading models every time. There's a bug with the system environment variable export where it doesn't actually take that into account for the model paths.

@chrisroat
Copy link
Contributor

If you are using a recent version (the released version on pypi does not have this), you can set this environmental variable:
CELLPOSE_LOCAL_MODELS_PATH

@Prehani
Copy link

Prehani commented Oct 1, 2021

Hi Chris--I saw your PR on this and looked through it: everything made sense, but I opened another issue on the Cellpose Github where I can't get that to work properly for me on distributed systems/containers. Not sure if that was tested for/considered, but just what I've seen.

@chrisroat
Copy link
Contributor

Was it working prior to the PR?

For reference, the issue is at #334

@Prehani
Copy link

Prehani commented Oct 4, 2021

No, I don't think I've gotten it to work at all either pre or post PR.

@chrisroat
Copy link
Contributor

This may not be a cellpose problem. It sounds like its likely an issue understanding how your HPC environment gives you access to a home directory (default place for models) or to the directory you specify with CELLPOSE_LOCAL_MODELS_PATH.

@Prehani
Copy link

Prehani commented Oct 4, 2021

Hmm, not 100% sure: did you see my latest comment on #334? There is no home directory on the execute side, and the directory I specify for the CELLPOSE_LOCAL_MODELS_PATH should allow for full permissions as I'm able to set the environment variable successfully and then extract everything I'd need from there. What additional permissions would I need? I will verify with our Condor group on the environment variable and permissions.

@Prehani
Copy link

Prehani commented Oct 4, 2021

Alright, I think I figured out (at least in part) where my issue came from: I believe the way I was setting whatever path I happened to be on was incorrect. For anybody else who happens to have this issue, here's what I ended up helping me: https://stackoverflow.com/questions/4774054/reliable-way-for-a-bash-script-to-get-the-full-path-to-itself

@chrisroat
Copy link
Contributor

OK. This can be closed then, I believe.

@VasylVaskivskyi
Copy link
Author

Hi @chrisroat , so if I want to use CELLPOSE_LOCAL_MODELS_PATH to which directory it should point /.../.cellpose or /.../.cellpose/models ?

@chrisroat
Copy link
Contributor

It should point to the exact directory you want the models downloaded into. It does not add ".cellpose" or ".cellpose/models". This code snippet shows the logic -- either the value of CELLPOSE_LOCAL_MODELS_PATH is used, or it defaults to {home}/.cellpose/models

_MODEL_DIR_ENV = os.environ.get("CELLPOSE_LOCAL_MODELS_PATH")
_MODEL_DIR_DEFAULT = pathlib.Path.home().joinpath('.cellpose', 'models')
MODEL_DIR = pathlib.Path(_MODEL_DIR_ENV) if _MODEL_DIR_ENV else _MODEL_DIR_DEFAULT

@VasylVaskivskyi
Copy link
Author

I checked, this solution works for me. Thank you very much. The issue can be closed.

@VasylVaskivskyi
Copy link
Author

Fixed in bddabe8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants