Home > Enterprise >  Import Error: Deploying custom Pytorch Model on streamlit
Import Error: Deploying custom Pytorch Model on streamlit

Time:08-19

Please, so trying to deploy a custom Pytorch based web-app on streamlit, everything works locally, however when deployed, I find the following Error in the Logs:

Downloading: "https://github.com/ultralytics/yolov5/archive/master.zip" to /home/appuser/.cache/torch/hub/master.zip
2022-08-14 12:23:17.584 Uncaught app exception
Traceback (most recent call last):
  File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/scriptrunner/script_runner.py", line 557, in _run_script
    exec(code, module.__dict__)
  File "app.py", line 28, in <module>
    model = torch.hub.load('ultralytics/yolov5', 'custom', path=run_model_path)
  File "/home/appuser/venv/lib/python3.9/site-packages/torch/hub.py", line 339, in load
    model = _load_local(repo_or_dir, model, *args, **kwargs)
  File "/home/appuser/venv/lib/python3.9/site-packages/torch/hub.py", line 368, in _load_local
    model = entry(*args, **kwargs)
  File "/home/appuser/.cache/torch/hub/ultralytics_yolov5_master/hubconf.py", line 74, in custom
    return _create(path, autoshape=autoshape, verbose=_verbose, device=device)
  File "/home/appuser/.cache/torch/hub/ultralytics_yolov5_master/hubconf.py", line 31, in _create
    from models.common import AutoShape, DetectMultiBackend
  File "/home/appuser/.cache/torch/hub/ultralytics_yolov5_master/models/common.py", line 14, in <module>
    import cv2
  File "/home/appuser/venv/lib/python3.9/site-packages/cv2/__init__.py", line 5, in <module>
    from .cv2 import *
ImportError: libGL.so.1: cannot open shared object file: No such file or directory

Here's what the requrements.txt contains:

pillow<=9.2.0
numpy<=1.21.0
streamlit==1.11.0
torch<=1.8.2 cu111
opencv<=4.5.1

Would love your assistance.

CodePudding user response:

If you're deploying the app, opencv-python-headless would be the appropriate package rather than opencv

  • Related