pythontensorflowpython-3.6tensorflowjs

Unable to import tensorflowjs successfully


I have tensorflow 1.5 and everything is working fine with tensorflow. Now i want to convert my tensorflow keras model to be used in web app so i installed tensorflowjs successfully but when i import i get the error.

I have tried changing the following versions:
numpy from 1.16.4 to 1.15.1,
tensorflow 1.5.0 to 1.8.0 and 1.12.0,
tensorflowjs 1.1.2 to 1.0.0

tensorflow test:

import tensorflow as tf

print(tf.__version__)
hello = tf.constant("Hello Tensorflow")
with tf.Session() as sesh:
    print(sesh.run(hello))

Output:

1.12.0
2019-06-11 12:02:11.140827: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
b'Hello Tensorflow'

So i guess everything is fine with tensorflow but still i cant import tensorflowjs due to some files missing in my tensorflow installation.

i got this error first:

Traceback (most recent call last):
  File "C:/Users/Uxama/PycharmProjects/untitled1/test.py", line 2, in <module>
    import tensorflowjs as tfjs
  File "C:\Users\Uxama\PycharmProjects\untitled1\venv\lib\site-packages\tensorflowjs\__init__.py", line 21, in <module>
    from tensorflowjs import converters
  File "C:\Users\Uxama\PycharmProjects\untitled1\venv\lib\site-packages\tensorflowjs\converters\__init__.py", line 24, in <module>
    from tensorflowjs.converters.tf_saved_model_conversion_v2 import convert_tf_saved_model
  File "C:\Users\Uxama\PycharmProjects\untitled1\venv\lib\site-packages\tensorflowjs\converters\tf_saved_model_conversion_v2.py", line 29, in <module>
    from tensorflow.python.framework import convert_to_constants
ImportError: cannot import name 'convert_to_constants'

Then i placed the file (convert_to_constants) manually because changing the versions doesn't seems to work and change anything.

Then i got this error:

Traceback (most recent call last):
  File "C:/Users/Uxama/PycharmProjects/untitled1/test.py", line 2, in <module>
    import tensorflowjs as tfjs
  File "C:\Users\Uxama\PycharmProjects\untitled1\venv\lib\site-packages\tensorflowjs\__init__.py", line 21, in <module>
    from tensorflowjs import converters
  File "C:\Users\Uxama\PycharmProjects\untitled1\venv\lib\site-packages\tensorflowjs\converters\__init__.py", line 24, in <module>
    from tensorflowjs.converters.tf_saved_model_conversion_v2 import convert_tf_saved_model
  File "C:\Users\Uxama\PycharmProjects\untitled1\venv\lib\site-packages\tensorflowjs\converters\tf_saved_model_conversion_v2.py", line 29, in <module>
    from tensorflow.python.framework import convert_to_constants
  File "C:\Users\Uxama\PycharmProjects\untitled1\venv\lib\site-packages\tensorflow\python\framework\convert_to_constants.py", line 26, in <module>
    from tensorflow.python.eager import wrap_function
ImportError: cannot import name 'wrap_function'

I did the same thing again and placed the file but the errors seems to kept coming.

I don't know what exactly causing the problem i installed tensorflow with pip and also tried installing it with wheels as well. I just want to successfully install tensorflowjs so that i can convert my keras model to use in web app.


Solution

  • Tensorflow 1.12 doesn't define a function called wrap_function(). Consider upgrading to API r1.13. Here are the functions defined in API r1.12, which you are currently using, and here is the wrap_function() method which is defined in API r1.13.