qurator-spk / eynollah

Document Layout Analysis
Apache License 2.0
328 stars 26 forks source link

ImportError: cannot import name 'set_session' from 'keras.backend' #121

Closed WYBupup closed 4 months ago

WYBupup commented 4 months ago

Meet problem when install eynollah, information of environment is as follows: Package Version


absl-py 2.1.0 anyio 3.7.1 astunparse 1.6.3 atomicwrites 1.4.1 attrs 23.2.0 bcrypt 4.1.2 beanie 1.20.0 beautifulsoup4 4.12.3 blinker 1.7.0 cachetools 5.3.3 certifi 2024.2.2 cffi 1.16.0 charset-normalizer 3.3.2 click 8.1.7 contourpy 1.1.1 cryptography 42.0.5 cycler 0.12.1 Deprecated 1.2.0 dnspython 2.6.1 docker 7.0.0 exceptiongroup 1.2.0 eynollah 0.3.0 fastapi 0.103.2 filelock 3.13.1 filetype 1.2.0 Flask 3.0.2 flatbuffers 24.3.7 fonttools 4.50.0 frozendict 2.4.0 gast 0.4.0 gdown 5.1.0 google-auth 2.28.2 google-auth-oauthlib 1.0.0 google-pasta 0.2.0 grpcio 1.62.1 h11 0.14.0 h5py 3.10.0 httpcore 1.0.4 httpx 0.27.0 idna 3.6 importlib_metadata 7.0.2 importlib_resources 6.3.1 imutils 0.5.4 itsdangerous 2.1.2 Jinja2 3.1.3 joblib 1.3.2 jsonschema 4.21.1 jsonschema-specifications 2023.12.1 keras 2.13.1 kiwisolver 1.4.5 lazy-model 0.2.0 libclang 18.1.1 lxml 5.1.0 Markdown 3.6 MarkupSafe 2.1.5 matplotlib 3.7.5 memory-profiler 0.61.0 motor 3.3.2 numpy 1.23.5 oauthlib 3.2.2 ocrd 2.63.3 ocrd-fork-bagit 1.8.1.post2 ocrd-fork-bagit-profile 1.3.0.post1 opencv-python-headless 4.9.0.80 opt-einsum 3.3.0 packaging 24.0 paramiko 3.4.0 pika 1.3.2 pillow 10.2.0 pip 23.3.1 pkgutil_resolve_name 1.3.10 protobuf 4.25.3 psutil 5.9.8 pyasn1 0.5.1 pyasn1-modules 0.3.0 pycparser 2.21 pydantic 1.10.14 pymongo 4.6.2 PyNaCl 1.5.0 pyparsing 3.1.2 PySocks 1.7.1 python-dateutil 2.9.0.post0 python-magic 0.4.27 python-multipart 0.0.9 PyYAML 6.0.1 referencing 0.34.0 requests 2.29.0 requests-oauthlib 1.4.0 requests-unixsocket 0.3.0 rpds-py 0.18.0 rsa 4.9 scikit-learn 1.3.2 scipy 1.10.1 setuptools 68.2.2 shapely 2.0.3 six 1.16.0 sniffio 1.3.1 soupsieve 2.5 starlette 0.27.0 tensorboard 2.13.0 tensorboard-data-server 0.7.2 tensorflow 2.13.1 tensorflow-estimator 2.13.0 tensorflow-io-gcs-filesystem 0.34.0 termcolor 2.4.0 threadpoolctl 3.3.0 toml 0.10.2 tqdm 4.66.2 typing_extensions 4.5.0 urllib3 1.26.18 uvicorn 0.28.0 Werkzeug 3.0.1 wheel 0.41.2 wrapt 1.16.0 zipp 3.18.1

After finishing installing eynollah, I tried to rum the command line eynollah -i xx.jpg -o xx -m xx but get following error: Traceback (most recent call last): File "anaconda3/envs/eynollah/bin/eynollah", line 5, in from qurator.eynollah.cli import main File "anaconda3/envs/eynollah/lib/python3.8/site-packages/qurator/eynollah/cli.py", line 4, in from qurator.eynollah.eynollah import Eynollah File "anaconda3/envs/eynollah/lib/python3.8/site-packages/qurator/eynollah/eynollah.py", line 32, in from keras.backend import set_session ImportError: cannot import name 'set_session' from 'keras.backend'

I doubt there maybe some version problem?

LucPol98 commented 4 months ago

You have to manually traceback to the library installation within your anaconda (in your case the path to the file that goes wrong is made explicit). Inside eynollah.py at line 32 you need to change:

from keras.backend import set_session

to:

import tensorflow
from tensorflow.compat.v1.keras.backend import set_session

It only needs to be done once after the first installation and will stay that way for as long as you don't reinstall or update the library

cneud commented 4 months ago

@LucPol98 Thanks! I will change this in main and the other branch we are currently working on and make a new release with this fix on PyPI asap.

cneud commented 4 months ago

The fix suggested above is now applied in main. We still need to fix some other issues before I can make a new release on PyPI though, so please install from git for now to resolve this.

@WYBupup please let us know if this makes it work for you and if we can close here.