Agree, this is very helpful, got what I needed to work for Segmenting some cells. Did anyone try and deploy a serving of this? I can get it working locally on my Flask application but just including the above:
class SegLabelListCustom(SegmentationLabelList):
def open(self, fn): return open_mask(fn, div=True)
class SegItemListCustom(SegmentationItemList):
_label_cls = SegLabelListCustom
In my Flask app prior to loading the .pkl:
learn = load_learner(path, 'cell_export.pkl')
But when I try and deploy on Render (using Gunicorn), the same Flask app gives the following error:
File "/opt/render/project/src/.venv/bin/gunicorn", line 10, in <module>
sys.exit(run())
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 61, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/app/base.py", line 223, in run
super(Application, self).run()
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/app/base.py", line 72, in run
Arbiter(self).run()
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/arbiter.py", line 60, in __init__
self.setup(app)
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/arbiter.py", line 120, in setup
self.app.wsgi()
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
return self.load_wsgiapp()
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
return util.import_app(self.app_uri)
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
__import__(module)
File "/opt/render/project/src/app.py", line 49, in <module>
learn = load_learner(path, export_file_name)
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/fastai/basic_train.py", line 598, in load_learner
state = torch.load(source, map_location='cpu') if defaults.device == torch.device('cpu') else torch.load(source)
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/torch/serialization.py", line 387, in load
return _load(f, map_location, pickle_module, **pickle_load_args)
File "/opt/render/project/src/.venv/lib/python3.7/site-packages/torch/serialization.py", line 574, in _load
result = unpickler.load()
AttributeError: Can't get attribute 'SegItemListCustom' on <module '__main__' from '/opt/render/project/src/.venv/bin/gunicorn'>
It seems like Gunicorn is not reading the custom classes. I have been searching StackOverflow but have not found an answer.