无法成功导入tensorflow.js

时间:2019-06-11 08:00:15

标签: python tensorflow python-3.6 tensorflowjs

我有tensorflow 1.5,并且在tensorflow下一切正常。 现在我想将我的tensorflow keras模型转换为可在Web应用程序中使用,因此我成功安装了tensorflowjs,但是在导入时出现错误。

我尝试更改以下版本:
numpy从1.16.4到1.15.1,
tensorflow 1.5.0至1.8.0和1.12.0,
tensorflowjs 1.1.2至1.0.0

tensorflow测试:

import tensorflow as tf

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

输出:

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'

所以我想使用tensorflow一切都很好,但是由于我的tensorflow安装中缺少一些文件,我仍然无法导入tensorflowjs。

我首先遇到此错误:

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'

然后我手动放置了文件(convert_to_constants),因为更改版本似乎行不通,并且更改了所有内容。

然后我得到了这个错误:

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'

我再次做同样的事情,并放置了文件,但错误似乎一直存在。

我不知道到底是什么原因导致我用pip安装了tensorflow,也尝试用轮子安装它。 我只想成功安装tensorflowjs,以便可以将keras模型转换为可在Web应用程序中使用。

1 个答案:

答案 0 :(得分:1)

Tensorflow 1.12没有定义名为wrap_function()的函数。考虑升级到API r1.13Here是您当前正在使用的API r1.12中定义的函数,而herewrap_function()中定义的API r1.13方法。