from inceptionV4 import *
我正在使用tensorflow InceptionV4,但收到此错误消息。 张量流-inceptionV4
ImportError
cannot import name 'tensor' from 'tensorflow.python.framework' (C:\Users\zxc\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\__init__.py)
File "C:\Labbb\inception\model_tensorflow_official.py", line 28, in <module>
import tf_slim as slim
File "C:\Labbb\inception\main.py", line 14, in <module>
from model_tensorflow_official import *
ImportError: cannot import name 'tensor' from 'tensorflow.python.framework' (C:\Users\zxc\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\__init__.py)
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import tensorflow.compat.v1 as tf
import tf_slim as slim
from nets import inception_utils
我尝试了tensorflow2.5 + keras2.5和tensorflow2.2 +keras2.3.1,它们不起作用
在之前的错误消息检测中,我在 tf_slim 中没有“inception_utils”文件 等
在 tf-slim 中,也没有 inception_utils
因此,当安装 tf-models-official 或 slim 时,也会安装 tf_slim 软件包(https://github.com/google-research/tf-slim/tree/master)。此处,tf_slim.layers.utils 模块已更新为从“tensorflow.python.framework”导入“tensor”。然而,“tensor”模块仅从tensorflow==2.13开始出现。您可以通过比较此处的不同分支来看到这一点:https://github.com/tensorflow/tensorflow/tree/r2.13/tensorflow/python/framework
我通过安装tensorflow==2.13使其工作:
pip install tensorflow==2.13
tf-models-official==2.13
(可能没有必要)
cd /path/to/clone/repo
git clone https://github.com/tensorflow/models/
(如此处所述https://github.com/tensorflow/models/tree/master/research/slim)
在我的Python脚本中:
import sys
sys.path.append("/path/to/clone/repo/models/research/slim")
from nets.inception_v4 import *