imfing / keras-flask-deploy-webapp

:smiley_cat: Pretty & simple image classifier app template. Deploy your own trained model or pre-trained model (VGG, ResNet, Densenet) to a web app using Flask in 10 minutes.
Apache License 2.0
1.18k stars 472 forks source link

Problems with running in Docker #60

Closed gitknu closed 1 year ago

gitknu commented 1 year ago

Hello, thank you for your great job! The problem I have is I can't run this project. I use Docker but each time get this error:

Traceback (most recent call last):
  File "app.py", line 7, in <module>
    from gevent.pywsgi import WSGIServer
  File "/usr/local/lib/python3.6/dist-packages/gevent/__init__.py", line 87, in <module>
    from gevent._hub_local import get_hub
  File "/usr/local/lib/python3.6/dist-packages/gevent/_hub_local.py", line 101, in <module>
    import_c_accel(globals(), 'gevent.__hub_local')
  File "/usr/local/lib/python3.6/dist-packages/gevent/_util.py", line 105, in import_c_accel
    mod = importlib.import_module(cname)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "src/gevent/__greenlet_primitives.pxd", line 12, in init gevent.__hub_local
ValueError: greenlet.greenlet size changed, may indicate binary incompatibility. Expected 128 from C header, got 40 from PyObject

I was trying to update gevent, I have the latest version of greenlet. I also tried local installm but seem to get the same problems at first, that's why switched to Docker as usually it is much easier to run.

What do I have to do? Thank you!

imfing commented 1 year ago

Thanks, I'll look into it. I guess it may be caused by the Python dependencies versions.

May I ask which OS were you trying to run it? and can you provide more info on how to reproduce the problem?

gitknu commented 1 year ago

Debian-based Linux. AS for Python - 3.10 As for tensorflow - https://github.com/yaroslavvb/tensorflow-community-wheels/issues/209 (while the CPU is quite old, but I don't think this is the problem, just no AVX2 support and no GPU, but, for example, Stable diffusion (CPU-only) runs pretty well. Slowly, but well)

So this is an algorithm: 0) apt install docker && apt install docker-compose 1) https://github.com/yaroslavvb/tensorflow-community-wheels/issues/209 (download) 2) pip install --ignore-installed --upgrade tensorflow-2.8.0-cp37-cp37m-linux_x86_64.whl 3) git clone https://github.com/mtobeiyf/keras-flask-deploy-webapp.git 4) cd keras-flask-deploy-webapp 5) docker build -t keras_flask_app . 6) docker run -it --rm -p 5000:5000 keras_flask_app 7) (here goes the issue) 8) I google the issue, see that it may be caused by gevent or greenlet (but they are there, the latest versions, 2.0.1 or something like that)

imfing commented 1 year ago

I haven't updated the dependencies for a long time so there might be some incompatibility from the newer versions of the library.

Can you try pinning the gevent to the old version in the requirements.txt? (it is 1.4 in the requirements.txt)

I'll look into it further once I get chance.

gitknu commented 1 year ago

uninstalled previous version, now

pip install gevent==1.4

and so i get

  ERROR: Failed building wheel for gevent
  Running setup.py clean for gevent
Failed to build gevent
ERROR: Could not build wheels for gevent, which is required to install pyproject.toml-based projects

I have read that this is may be caused by python, which is incompatible (need 3.8, not 3.10, so trying to downgrade - I'll edit this comment as soon as will now the result)

imfing commented 1 year ago

I see, will try bumping the Tensorflow wheel version in this repository.

imfing commented 1 year ago

Should be fixed by https://github.com/imfing/keras-flask-deploy-webapp/pull/61, see the root cause here: https://github.com/gevent/gevent/issues/1260

Also if you want to use a different tensorflow version, please only change the dockerfile accordingly, and remove the tensorflow entry in requirements.txt. The updated tensorflow version will be reflected in docker build -t keras_flask_app .