I am using celery to load Neural Network models and would like to store the loaded model in settings for fast prediction.
so in django.conf.settings
I have:
MODELS = {}
and in celery task, I have the following snippet:
@app.task
def load_nn_models(model_name):
from django.conf import settings
...
settings.MODELS[model_name] = {'model': net, 'graph': sess}
However, I noticed that the tasks are running in another thread that launches different Django Environment and any changes in the settings will not be reflected back to the main thread.
Is there a workaround for this?
EDIT
The parameters I am storing in settings are:
- net: keras Model
- sess: Tensorflow Session