ImportError: cannot import name 'convert_to_constants'
hazily123 opened this issue · 3 comments
在导入tensorflowjs的时候就会报这个错,在执行转换格式脚本的时候也是现实这个包导入有问题。
import tensorflowjs as tfjs
Traceback (most recent call last):
File "", line 1, in
File "F:\anaconda\anaconda3\lib\site-packages\tensorflowjs-1.0.1-py3.6.egg\tensorflowjs_init_.py", line 21, in
from tensorflowjs import converters
File "F:\anaconda\anaconda3\lib\site-packages\tensorflowjs-1.0.1-py3.6.egg\tensorflowjs\converters_init_.py", line 24, in
from tensorflowjs.converters.tf_saved_model_conversion_v2 import convert_tf_saved_model
File "F:\anaconda\anaconda3\lib\site-packages\tensorflowjs-1.0.1-py3.6.egg\tensorflowjs\converters\tf_saved_model_conversion_v2.py", line 29, in
from tensorflow.python.framework import convert_to_constants
ImportError: cannot import name 'convert_to_constants'
I figured out that the problem here, was that convert_to_constants.py was missing from my python tensorflow framework directory.
This problem can easily be solved, by copying the convert_to_constants.py found on the official web-page's framework directory, into your Python36\Lib\site-packages\tensorflow\python\framework folder.
In your case, you would probably have to copy the file to your *anaconda\lib\site-packages\tensorflowjs-1.0.1-py3.6.egg\tensorflowjs* folder.
@hazily123 看起来像是 tensorflowjs 版本问题。对于模型预处理,可以试试最新发布的 TensorSpace 预处理工具 TensorSpace-Converter(使用这个工具来预处理,理论上不会遇到以上提到的 python 包版本问题),可以极大简化预处理过程。
我把文件放进去了文件夹,但是没有任何作用,还是会报那个错误。