mafda / knee_OA_dl_app

Web app to predict knee osteoarthritis grade using Deep Learning and Streamlit
11 stars 5 forks source link

Getting TypeError with respect to SeparableConv2D #3

Closed chottuthejimmy closed 4 weeks ago

chottuthejimmy commented 4 weeks ago

So when I run the streamlit command I am getting this error :

TypeError: Error when deserializing class 'SeparableConv2D' using config={'name': 'block2_sepconv1', 'trainable': True, 'dtype': 'float32', 'filters': 128, 'kernel_size': [3, 3], 'strides': [1, 1], 'padding': 'same', 'data_format': 'channels_last', 'dilation_rate': [1, 1], 'groups': 1, 'activation': 'linear', 'use_bias': False, 'kernel_initializer': {'class_name': 'GlorotUniform', 'config': {'seed': None}}, 'bias_initializer': {'class_name': 'Zeros', 'config': {}, 'shared_object_id': 21}, 'kernel_regularizer': None, 'bias_regularizer': None, 'activity_regularizer': None, 'kernel_constraint': None, 'bias_constraint': None, 'depth_multiplier': 1, 'depthwise_initializer': {'class_name': 'GlorotUniform', 'config': {'seed': None}}, 'pointwise_initializer': {'class_name': 'GlorotUniform', 'config': {'seed': None}}, 'depthwise_regularizer': None, 'pointwise_regularizer': None, 'depthwise_constraint': None, 'pointwise_constraint': None}. Exception encountered: Unrecognized keyword arguments passed to SeparableConv2D: {'groups': 1, 'kernel_initializer': {'class_name': 'GlorotUniform', 'config': {'seed': None}}, 'kernel_regularizer': None, 'kernel_constraint': None}

Here's the Traceback:

File "/Users/pieces/Desktop/random/knee_OA_dl_app/venv/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling
    result = func()
File "/Users/pieces/Desktop/random/knee_OA_dl_app/venv/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 579, in code_to_exec
    exec(code, module.__dict__)
File "/Users/pieces/Desktop/random/knee_OA_dl_app/app/app.py", line 64, in <module>
    model = load_model_with_custom_objects("./src/models/model_Xception_ft.hdf5")
File "/Users/pieces/Desktop/random/knee_OA_dl_app/app/app.py", line 62, in load_model_with_custom_objects
    return tf.keras.models.load_model(model_path, custom_objects=custom_objects, compile=False)
File "/Users/pieces/Desktop/random/knee_OA_dl_app/venv/lib/python3.10/site-packages/keras/src/saving/saving_api.py", line 196, in load_model
    return legacy_h5_format.load_model_from_hdf5(
File "/Users/pieces/Desktop/random/knee_OA_dl_app/venv/lib/python3.10/site-packages/keras/src/legacy/saving/legacy_h5_format.py", line 133, in load_model_from_hdf5
    model = saving_utils.model_from_config(
File "/Users/pieces/Desktop/random/knee_OA_dl_app/venv/lib/python3.10/site-packages/keras/src/legacy/saving/saving_utils.py", line 85, in model_from_config
    return serialization.deserialize_keras_object(
File "/Users/pieces/Desktop/random/knee_OA_dl_app/venv/lib/python3.10/site-packages/keras/src/legacy/saving/serialization.py", line 495, in deserialize_keras_object
    deserialized_obj = cls.from_config(
File "/Users/pieces/Desktop/random/knee_OA_dl_app/venv/lib/python3.10/site-packages/keras/src/models/sequential.py", line 350, in from_config
    layer = saving_utils.model_from_config(
File "/Users/pieces/Desktop/random/knee_OA_dl_app/venv/lib/python3.10/site-packages/keras/src/legacy/saving/saving_utils.py", line 85, in model_from_config
    return serialization.deserialize_keras_object(
File "/Users/pieces/Desktop/random/knee_OA_dl_app/venv/lib/python3.10/site-packages/keras/src/legacy/saving/serialization.py", line 495, in deserialize_keras_object
    deserialized_obj = cls.from_config(
File "/Users/pieces/Desktop/random/knee_OA_dl_app/venv/lib/python3.10/site-packages/keras/src/models/model.py", line 526, in from_config
    return functional_from_config(
File "/Users/pieces/Desktop/random/knee_OA_dl_app/venv/lib/python3.10/site-packages/keras/src/models/functional.py", line 499, in functional_from_config
    process_layer(layer_data)
File "/Users/pieces/Desktop/random/knee_OA_dl_app/venv/lib/python3.10/site-packages/keras/src/models/functional.py", line 479, in process_layer
    layer = saving_utils.model_from_config(
File "/Users/pieces/Desktop/random/knee_OA_dl_app/venv/lib/python3.10/site-packages/keras/src/legacy/saving/saving_utils.py", line 85, in model_from_config
    return serialization.deserialize_keras_object(
File "/Users/pieces/Desktop/random/knee_OA_dl_app/venv/lib/python3.10/site-packages/keras/src/legacy/saving/serialization.py", line 504, in deserialize_keras_object
    deserialized_obj = cls.from_config(cls_config)
File "/Users/pieces/Desktop/random/knee_OA_dl_app/venv/lib/python3.10/site-packages/keras/src/ops/operation.py", line 236, in from_config
    raise TypeError(

It seems to be the issue with correct keras version, could you please mention the keras version that you used while creating the model. Would be helpful if you could provide some metadata around the model as well.

Cheers! :)

chottuthejimmy commented 4 weeks ago

So it seemed to be a package version errors and also the error with the model file itself, so I modified the model which you can find it here

And i used pip instead conda and these were all the installed packages.

absl-py==2.1.0
altair==4.2.0
anyio==4.6.2.post1
appnope==0.1.4
argon2-cffi==23.1.0
argon2-cffi-bindings==21.2.0
arrow==1.3.0
asttokens==2.4.1
astunparse==1.6.3
async-lru==2.0.4
attrs==24.2.0
babel==2.16.0
backcall==0.2.0
beautifulsoup4==4.12.3
bleach==6.1.0
blinker==1.8.2
cachetools==5.5.0
certifi==2024.8.30
cffi==1.17.1
charset-normalizer==3.4.0
click==8.1.7
comm==0.2.2
contourpy==1.3.0
cycler==0.12.1
debugpy==1.8.7
decorator==5.1.1
defusedxml==0.7.1
entrypoints==0.4
exceptiongroup==1.2.2
executing==2.1.0
fastjsonschema==2.20.0
flatbuffers==24.3.25
fonttools==4.54.1
fqdn==1.5.1
gast==0.4.0
gitdb==4.0.11
GitPython==3.1.43
google-auth==2.35.0
google-auth-oauthlib==1.0.0
google-pasta==0.2.0
grpcio==1.67.0
h11==0.14.0
h5py==3.12.1
httpcore==1.0.6
httpx==0.27.2
idna==3.10
ipykernel==6.29.5
ipython==7.34.0
ipywidgets==8.1.5
isoduration==20.11.0
jedi==0.19.1
Jinja2==3.1.4
joblib==1.4.2
json5==0.9.25
jsonpointer==3.0.0
jsonschema==4.23.0
jsonschema-specifications==2024.10.1
jupyter==1.0.0
jupyter-console==6.6.3
jupyter-events==0.10.0
jupyter-lsp==2.2.5
jupyter_client==8.6.3
jupyter_core==5.7.2
jupyter_server==2.14.2
jupyter_server_terminals==0.5.3
jupyterlab==4.2.5
jupyterlab_pygments==0.3.0
jupyterlab_server==2.27.3
jupyterlab_widgets==3.0.13
keras==2.13.1
kiwisolver==1.4.7
libclang==18.1.1
Markdown==3.7
markdown-it-py==3.0.0
MarkupSafe==3.0.2
matplotlib==3.9.2
matplotlib-inline==0.1.7
mdurl==0.1.2
mistune==3.0.2
ml-dtypes==0.4.1
namex==0.0.8
narwhals==1.9.4
nbclient==0.10.0
nbconvert==7.16.4
nbformat==5.10.4
nest-asyncio==1.6.0
notebook==7.2.2
notebook_shim==0.2.4
numpy==1.24.3
oauthlib==3.2.2
opt_einsum==3.4.0
optree==0.13.0
overrides==7.7.0
packaging==24.1
pandas==1.5.0
pandocfilters==1.5.1
parso==0.8.4
pexpect==4.9.0
pickleshare==0.7.5
pillow==10.4.0
platformdirs==4.3.6
prometheus_client==0.21.0
prompt_toolkit==3.0.48
protobuf==4.25.5
psutil==6.1.0
ptyprocess==0.7.0
pure_eval==0.2.3
pyarrow==17.0.0
pyasn1==0.6.1
pyasn1_modules==0.4.1
pycparser==2.22
pydeck==0.9.1
Pygments==2.18.0
pyparsing==3.2.0
python-dateutil==2.9.0.post0
python-json-logger==2.0.7
pytz==2024.2
PyYAML==6.0.2
pyzmq==26.2.0
qtconsole==5.6.0
QtPy==2.4.1
referencing==0.35.1
requests==2.32.3
requests-oauthlib==2.0.0
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rich==13.9.2
rpds-py==0.20.0
rsa==4.9
scikit-learn==1.1.2
scipy==1.14.1
seaborn==0.11.2
Send2Trash==1.8.3
six==1.16.0
smmap==5.0.1
sniffio==1.3.1
soupsieve==2.6
stack-data==0.6.3
streamlit==1.39.0
tenacity==9.0.0
tensorboard==2.13.0
tensorboard-data-server==0.7.2
tensorflow==2.13.0
tensorflow-estimator==2.13.0
tensorflow-io-gcs-filesystem==0.37.1
tensorflow-macos==2.13.0
termcolor==2.5.0
terminado==0.18.1
threadpoolctl==3.5.0
tinycss2==1.3.0
toml==0.10.2
tomli==2.0.2
toolz==1.0.0
tornado==6.4.1
traitlets==5.14.3
types-python-dateutil==2.9.0.20241003
typing_extensions==4.5.0
uri-template==1.3.0
urllib3==2.2.3
wcwidth==0.2.13
webcolors==24.8.0
webencodings==0.5.1
websocket-client==1.8.0
Werkzeug==3.0.4
widgetsnbextension==4.0.13
wrapt==1.16.0

Note : If you are on windows you might want to remove tensorflow-macos==2.13.0 and update tensorflow-io-gcs-filesystem==0.37.1 with the compatible version. And this should make the project work.

Cheers! and happy coding!

mafda commented 4 weeks ago

Hi,

I used conda to install the dependencies from the environment.yml file on my Mac M1 Pro, but I haven’t tested it on a Windows machine. Thank you very much for the update on the versions! I’ll go ahead and test the updated version on my machine, and I’ll also work on providing a version for Windows users.

Thanks again for your contributions to the project!

chottuthejimmy commented 3 weeks ago

Try to first run it purely by cloning afresh. If that doesn't work, use the above package details and install them. If it still doesn't work, I modified the model which you can find it here. Replace your model file with this and try it out and that should work, or atleast this is what worked for me (on Macbook Pro M1) and for my friend of Windows 11