Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

np.object deprecation issue in tensorflowjs_converter #8434

Open
ayushsharma-1 opened this issue Nov 12, 2024 · 3 comments
Open

np.object deprecation issue in tensorflowjs_converter #8434

ayushsharma-1 opened this issue Nov 12, 2024 · 3 comments
Assignees
Labels
type:feature New feature or request

Comments

@ayushsharma-1
Copy link

ayushsharma-1 commented Nov 12, 2024

1. URL of the file using:
https://github.com/tensorflow/tfjs

2. Issue:
I am encountering an issue when attempting to convert a Keras model (.h5) to TensorFlow.js format using the tensorflowjs_converter command. The issue arises due to the deprecated usage of np.object in the TensorFlow.js code.

Starting from NumPy 1.20, the np.object alias has been removed, causing compatibility issues with newer versions of NumPy. When I try running the tensorflowjs_converter tool, I receive the following error:

AttributeError: module 'numpy' has no attribute 'object'

This error occurs because np.object was removed as part of the NumPy 1.20 update, and is now considered a deprecated alias for the built-in object. The solution to this issue would be to replace the usage of np.object in TensorFlow.js with the standard object type, which is the correct usage in newer versions of NumPy.

Steps to Reproduce:

  1. Install the latest version of NumPy (1.20 or higher).
  2. Try to convert a Keras .h5 model to TensorFlow.js format using the command:
    tensorflowjs_converter --input_format keras my_dogs_vs_cats_model.h5 model
    
  3. Observe the error message:
    AttributeError: module 'numpy' has no attribute 'object'
    

3. Additional context:

  • This error occurs because np.object is no longer supported in NumPy versions 1.20 and later. The official NumPy documentation notes that np.object was deprecated and removed in version 1.20.
  • I have tried downgrading NumPy to an earlier version (e.g., 1.19) to work around the issue, but this is not an ideal solution as I need the latest versions of other libraries in my environment.
  • This issue affects users who rely on newer versions of NumPy, which are often part of many modern Python environments.

4. Are you willing to contribute it? (Yes or No):
No

@ayushsharma-1 ayushsharma-1 added the type:feature New feature or request label Nov 12, 2024
@laxmareddyp laxmareddyp transferred this issue from tensorflow/models Nov 12, 2024
@shmishra99 shmishra99 self-assigned this Nov 13, 2024
@shmishra99
Copy link
Contributor

shmishra99 commented Nov 14, 2024

Hi @ayushsharma-1 ,

Thank you for reporting the issue. As far as I know, the tfjs-converter doesn't require NumPy to convert .h5 models. However, it's possible that your model was created with a Keras that used NumPy 1.20 or higher. To investigate further, please share your .h5 model file.

Thank You!!

@Satge96
Copy link

Satge96 commented Nov 21, 2024

tensorflowjs_wizard
2024-11-21 08:48:25.489059: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable TF_ENABLE_ONEDNN_OPTS=0.
2024-11-21 08:48:25.501613: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:477] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
E0000 00:00:1732175305.516847 4053563 cuda_dnn.cc:8310] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
E0000 00:00:1732175305.521461 4053563 cuda_blas.cc:1418] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
2024-11-21 08:48:25.536675: 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: AVX2 AVX512F AVX512_VNNI AVX512_BF16 AVX512_FP16 AVX_VNNI AMX_TILE AMX_INT8 AMX_BF16 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
/site-packages/tensorflowjs/read_weights.py:28: FutureWarning: In the future np.object will be defined as the corresponding NumPy scalar.
np.uint8, np.uint16, np.object, np.bool]
Traceback (most recent call last):
File "/bin/tensorflowjs_wizard", line 5, in
from tensorflowjs.converters.wizard import pip_main
File "/lib/python3.12/site-packages/tensorflowjs/init.py", line 21, in
from tensorflowjs import converters
File "/lib/python3.12/site-packages/tensorflowjs/converters/init.py", line 21, in
from tensorflowjs.converters.converter import convert
File "/lib/python3.12/site-packages/tensorflowjs/converters/converter.py", line 35, in
from tensorflowjs.converters import keras_h5_conversion as conversion
File "/lib/python3.12/site-packages/tensorflowjs/converters/keras_h5_conversion.py", line 33, in
from tensorflowjs import write_weights # pylint: disable=import-error
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.12/site-packages/tensorflowjs/write_weights.py", line 25, in
from tensorflowjs import read_weights
File "/lib/python3.12/site-packages/tensorflowjs/read_weights.py", line 28, in
np.uint8, np.uint16, np.object, np.bool]
^^^^^^^^^
File "/lib/python3.12/site-packages/numpy/init.py", line 394, in getattr
raise AttributeError(former_attrs[attr])
AttributeError: module 'numpy' has no attribute 'object'.
np.object was a deprecated alias for the builtin object. To avoid this error in existing code, use object by itself. Doing this will not modify any behavior and is safe.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations. Did you mean: 'object_'?

For me, it happens directly when I invoke the wizard.

@Satge96
Copy link

Satge96 commented Nov 22, 2024

For me, changing to the newest tfjs already resolved the problem. As they already fixed it in the source. They replaced np.object with object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants