You are not logged in.

#1 2024-05-14 01:01:17

tac
Member
Registered: 2023-10-21
Posts: 2

can't fix error with python-tensorflow (or python-keras) package

Hello, i'm having trouble with tensorflow, I mean "python-tensorflow"; I'm currently without the opt version of the package since I though that would fix my issue but turns out it wasn't fixed.

First attempt:

import tensorflow as tf
import keras
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, Dense, Flatten, Dropout
from keras.preprocessing import image_dataset_from_directory

Output:

2024-05-13 21:43:44.018842: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
Traceback (most recent call last):
  File "/datos/python/pdf2pgn/construir_modelo.py", line 5, in <module>
    import keras
  File "/usr/lib/python3.12/site-packages/keras/__init__.py", line 3, in <module>
    from keras import __internal__
  File "/usr/lib/python3.12/site-packages/keras/__internal__/__init__.py", line 6, in <module>
    from keras.__internal__ import models
  File "/usr/lib/python3.12/site-packages/keras/__internal__/models/__init__.py", line 3, in <module>
    from keras.src.models.cloning import clone_and_build_model
  File "/usr/lib/python3.12/site-packages/keras/src/__init__.py", line 21, in <module>
    from keras.src import applications
  File "/usr/lib/python3.12/site-packages/keras/src/applications/__init__.py", line 18, in <module>
    from keras.src.applications.convnext import ConvNeXtBase
  File "/usr/lib/python3.12/site-packages/keras/src/applications/convnext.py", line 33, in <module>
    from keras.src.engine import sequential
  File "/usr/lib/python3.12/site-packages/keras/src/engine/sequential.py", line 24, in <module>
    from keras.src.engine import functional
  File "/usr/lib/python3.12/site-packages/keras/src/engine/functional.py", line 33, in <module>
    from keras.src.engine import training as training_lib
  File "/usr/lib/python3.12/site-packages/keras/src/engine/training.py", line 48, in <module>
    from keras.src.saving import saving_api
  File "/usr/lib/python3.12/site-packages/keras/src/saving/saving_api.py", line 25, in <module>
    from keras.src.saving.legacy import save as legacy_sm_saving_lib
  File "/usr/lib/python3.12/site-packages/keras/src/saving/legacy/save.py", line 27, in <module>
    from keras.src.saving.legacy.saved_model import load_context
  File "/usr/lib/python3.12/site-packages/keras/src/saving/legacy/saved_model/load_context.py", line 68, in <module>
    tf.__internal__.register_load_context_function(in_load_context)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'tensorflow._api.v2.compat.v2.__internal__' has no attribute 'register_load_context_function'. Did you mean: 'register_call_context_function'?

Second attempt:

import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Dense, Flatten, Dropout
from tensorflow.keras.preprocessing import image_dataset_from_directory

Output (same as before):

2024-05-13 21:46:10.811620: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
Traceback (most recent call last):
  File "/datos/python/pdf2pgn/construir_modelo.py", line 5, in <module>
    from tensorflow.keras.models import Sequential
  File "/usr/lib/python3.12/site-packages/keras/api/_v2/keras/__init__.py", line 3, in <module>
    from keras.api._v2.keras import __internal__
  File "/usr/lib/python3.12/site-packages/keras/__init__.py", line 3, in <module>
    from keras import __internal__
  File "/usr/lib/python3.12/site-packages/keras/__internal__/__init__.py", line 6, in <module>
    from keras.__internal__ import models
  File "/usr/lib/python3.12/site-packages/keras/__internal__/models/__init__.py", line 3, in <module>
    from keras.src.models.cloning import clone_and_build_model
  File "/usr/lib/python3.12/site-packages/keras/src/__init__.py", line 21, in <module>
    from keras.src import applications
  File "/usr/lib/python3.12/site-packages/keras/src/applications/__init__.py", line 18, in <module>
    from keras.src.applications.convnext import ConvNeXtBase
  File "/usr/lib/python3.12/site-packages/keras/src/applications/convnext.py", line 33, in <module>
    from keras.src.engine import sequential
  File "/usr/lib/python3.12/site-packages/keras/src/engine/sequential.py", line 24, in <module>
    from keras.src.engine import functional
  File "/usr/lib/python3.12/site-packages/keras/src/engine/functional.py", line 33, in <module>
    from keras.src.engine import training as training_lib
  File "/usr/lib/python3.12/site-packages/keras/src/engine/training.py", line 48, in <module>
    from keras.src.saving import saving_api
  File "/usr/lib/python3.12/site-packages/keras/src/saving/saving_api.py", line 25, in <module>
    from keras.src.saving.legacy import save as legacy_sm_saving_lib
  File "/usr/lib/python3.12/site-packages/keras/src/saving/legacy/save.py", line 27, in <module>
    from keras.src.saving.legacy.saved_model import load_context
  File "/usr/lib/python3.12/site-packages/keras/src/saving/legacy/saved_model/load_context.py", line 68, in <module>
    tf.__internal__.register_load_context_function(in_load_context)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'tensorflow._api.v2.compat.v2.__internal__' has no attribute 'register_load_context_function'. Did you mean: 'register_call_context_function'?

Third attempt:

import tensorflow as tf
from tensorflow.python.keras import Sequential
from tensorflow.python.keras.layers import Conv2D, MaxPooling2D, Dense, Flatten, Dropout
from tensorflow.python.keras import image_dataset_from_directory

Output:

2024-05-13 21:48:59.847914: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
Traceback (most recent call last):
  File "/datos/python/pdf2pgn/construir_modelo.py", line 7, in <module>
    from tensorflow.python.keras.utils import image_dataset_from_directory
ImportError: cannot import name 'image_dataset_from_directory' from 'tensorflow.python.keras.utils' (/usr/lib/python3.12/site-packages/tensorflow/python/keras/utils/__init__.py)

So, as you can see, I can excecute the first three line sin the third case, when I use "tensorflow.python.keras", but I can't load anything from "tensorflow.keras" or from "keras" package. But isn't supposed that the first one (the one I used in my third attempt) is the legacy mode of loading keras while the second ones (first and second attempt) are the recommended packages? My guess is that there's a mismatch between tensorflow and keras because some months ago I was able to run code with "tensorflow.keras" but then it all broke down after my last system update. How can I fix this? I reinstalled both packages and did an upgrade of the system with sudo pacman -Syu. What else can I do?

Offline

#2 2024-05-17 11:45:51

CallMeIshamel
Member
Registered: 2024-05-17
Posts: 1

Re: can't fix error with python-tensorflow (or python-keras) package

Hi I had the same issue. I uninstalled the python-tensorflow-cuda and python-keras archlinux arch packages

I installed keras through pip.

Then installed again python-tensorflow-cuda from arch.

Obviously not a general solution. There seems to be mismatch between tensorflow and keras arch packages.

Offline

#3 2024-05-28 20:50:04

FuzzySPb
Member
Registered: 2013-01-21
Posts: 68

Re: can't fix error with python-tensorflow (or python-keras) package

Yes, I got the same problem after recent upgrade. But I'm not sure that it is right to resolve it with mixing native python packages with Arch packages.
Version mismatc should be reported... so should it be reported for python-keras?

I see that my system now has tensorflow 2.16 while python-keras is still 2.15 - probably this is the reason. (pip tries to install keras 3.3.3 that doesn't look like a good match either)

Last edited by FuzzySPb (2024-05-28 20:52:49)

Offline

#4 2024-05-28 21:28:19

FuzzySPb
Member
Registered: 2013-01-21
Posts: 68

Re: can't fix error with python-tensorflow (or python-keras) package

I tried to downgrade tensorflow to 2.15 and got problem with pip.
I.e, if I have python-tensorflow-opt-cuda-2.16.1-6-x86_64.pkg.tar.zst installed then my pip list output contains tensorflow 2.16.1.
But if I replace it with python-tensorflow-opt-cuda-2.15.0-6-x86_64.pkg.tar.zst from Arch Archive then pip list doesn't show tensorflow anymore and my script gives an error ModuleNotFoundError: No module named 'tensorflow'.

Offline

#5 2024-06-03 13:28:36

FuzzySPb
Member
Registered: 2013-01-21
Posts: 68

Re: can't fix error with python-tensorflow (or python-keras) package

Ok, it is solved with recent upgrade of python-keras to 3.3.3

Offline

Board footer

Powered by FluxBB