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

tensorflowjs_converter: NotImplementedError: numpy() is only available when eager execution is enabled #8265

Closed
smidm opened this issue May 1, 2024 · 9 comments
Assignees
Labels
comp:converter type:bug Something isn't working

Comments

@smidm
Copy link

smidm commented May 1, 2024

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js): yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Fedora 39
  • TensorFlow.js installed from (npm or script link): pypi
  • TensorFlow.js version (use command below): 4.18.0
  • keras 2.15.1
  • tensorflow 2.15.1
  • tf_keras 2.15.1

Describe the current behavior

create model, train and save:

import keras
from tensorflow.keras import layers, models

dummy_model = models.Sequential([
        layers.Input(shape=(None, 3)),
        layers.GlobalMaxPooling1D(),
        layers.Dense(4, activation='softmax')
    ])
dummy_model.compile(optimizer=keras.optimizers.Adam(learning_rate=0.0001), 
              loss='sparse_categorical_crossentropy', 
              metrics=['accuracy'],              
)
# dummy_model.fit(np.random.rand(10, 33, 3), np.random.randint(0, 4, 10), epochs=1)
dummy_model.save('model.h5')

convert to tfjs:

tensorflowjs_converter --input_format=keras_saved_model model.h5 out/

tensorflowjs_converter output:

2024-05-01 16:14:22.358335: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
2024-05-01 16:14:22.358433: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered
2024-05-01 16:14:22.361103: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
2024-05-01 16:14:24.368550: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
WARNING:root:TensorFlow Decision Forests 1.8.1 is compatible with the following TensorFlow Versions: ['2.15.0']. However, TensorFlow 2.15.1 was detected. This can cause issues with the TF API and symbols in the custom C++ ops. See the TF and TF-DF compatibility table at https://github.com/tensorflow/decision-forests/blob/main/documentation/known_issues.md#compatibility-table.
2024-05-01 16:14:27.733185: W tensorflow/c/c_api.cc:305] Operation '{name:'dense_25/bias/Assign' id:22 op device:{requested: '', assigned: ''} def:{{{node dense_25/bias/Assign}} = AssignVariableOp[_has_manual_control_dependencies=true, dtype=DT_FLOAT, validate_shape=false](dense_25/bias, dense_25/bias/Initializer/zeros)}}' was changed by setting attribute after it was run by a session. This mutation will have no effect, and will trigger an error in the future. Either don't modify nodes after running them or create a new session.
[/home/matej/local/conda/envs/pose_service/lib/python3.9/site-packages/tf_keras/src/engine/training.py:3098](https://file+.vscode-resource.vscode-cdn.net/home/matej/local/conda/envs/pose_service/lib/python3.9/site-packages/tf_keras/src/engine/training.py:3098): UserWarning: You are saving your model as an HDF5 file via `model.save()`. This file format is considered legacy. We recommend using instead the native TF-Keras format, e.g. `model.save('my_model.keras')`.
  saving_api.save_model(
Traceback (most recent call last):
  File "/home/matej/local/conda/envs/pose_service/bin/tensorflowjs_converter", line 8, in <module>
    sys.exit(pip_main())
  File "/home/matej/local/conda/envs/pose_service/lib/python3.9/site-packages/tensorflowjs/converters/converter.py", line 959, in pip_main
    main([' '.join(sys.argv[1:])])
  File "/home/matej/local/conda/envs/pose_service/lib/python3.9/site-packages/tensorflowjs/converters/converter.py", line 963, in main
    convert(argv[0].split(' '))
  File "/home/matej/local/conda/envs/pose_service/lib/python3.9/site-packages/tensorflowjs/converters/converter.py", line 949, in convert
    _dispatch_converter(input_format, output_format, args, quantization_dtype_map,
  File "/home/matej/local/conda/envs/pose_service/lib/python3.9/site-packages/tensorflowjs/converters/converter.py", line 647, in _dispatch_converter
    dispatch_keras_saved_model_to_tensorflowjs_conversion(
  File "/home/matej/local/conda/envs/pose_service/lib/python3.9/site-packages/tensorflowjs/converters/converter.py", line 282, in dispatch_keras_saved_model_to_tensorflowjs_conversion
    model.save(temp_h5_path, save_format='h5')
  File "/home/matej/local/conda/envs/pose_service/lib/python3.9/site-packages/tf_keras/src/utils/traceback_utils.py", line 70, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/home/matej/local/conda/envs/pose_service/lib/python3.9/site-packages/tensorflow/python/ops/resource_variable_ops.py", line 690, in numpy
    raise NotImplementedError(
NotImplementedError: numpy() is only available when eager execution is enabled.

Describe the expected behavior

Model gets successfully converted.

Standalone code to reproduce the issue

see above

The conversion runs successfully when Model.compile is not called.

@smidm smidm added the type:bug Something isn't working label May 1, 2024
@smidm
Copy link
Author

smidm commented May 1, 2024

import tensorflowjs as tfjs
tfjs.converters.save_keras_model(dummy_model, "out/")

works without error

@gaikwadrahul8
Copy link
Contributor

gaikwadrahul8 commented May 8, 2024

Hi, @smidm

I apologize for the delay in responding, I was trying to replicate the same issue from my end and I'm able to reproduce the same behaviour from my end but I see you're saving your model in Keras HDF5 model (.h5) format for that you'll have to use this command !tensorflowjs_converter --input_format=keras model.h5 out/ insead of tensorflowjs_converter --input_format=keras_saved_model model.h5 out/, I tried from my end it seems like working as expected for your reference I have added gist-file here please refer our official documentation of tfjs_conveter

If I have missed something here please let me know. Thank you for your cooperation and patience.

Copy link

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

@smidm
Copy link
Author

smidm commented May 16, 2024

Thanks, the fixed input format works for me also. I was confused by the input format options. There are currently 3 keras related: keras_saved_model, keras_keras, keras. The keras_keras is nowhere documented. This options combined with tfjs not supporting the new default .keras format was hell to navigate. Some consistency checks on the input would be greatly beneficial.

@smidm
Copy link
Author

smidm commented May 16, 2024

What about adding a link to https://github.com/tensorflow/tfjs/tree/master/tfjs-converter to tensorflowjs_converter --help?

@gaikwadrahul8
Copy link
Contributor

Hi, @smidm

Thank you for your suggestion regarding to add a link https://github.com/tensorflow/tfjs/tree/master/tfjs-converter to tensorflowjs_converter --help . I appreciate you bringing this to our attention.

I will be sure to share your feedback during our next internal meeting. The team will discuss it and take appropriate action if necessary.

If your issue has been resolved, please feel free to close this issue.

Thank you for your cooperation and patience.

Copy link

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

@github-actions github-actions bot added the stale label May 24, 2024
@gaikwadrahul8
Copy link
Contributor

Hi, @smidm

We haven't got confirmation from your end so now I'm closing this issue and I'll keep this issue open #8266 for further update regarding to add a link https://github.com/tensorflow/tfjs/tree/master/tfjs-converter to tensorflowjs_converter --help

Thank you for your understanding and patience.

Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:converter type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants