提问人:tg7 提问时间:7/24/2023 最后编辑:John Gordontg7 更新时间:7/24/2023 访问量:86
我收到“ModuleNotFoundError:没有名为”tensorflow.compat“的模块
I get 'ModuleNotFoundError: No module named 'tensorflow.compat'
问:
这是代码,
from keras.preprocessing import image
from keras.applications.vgg16 import VGG16
from keras.applications.vgg16 import preprocess_input
from keras.models import Model import numpy as np
class FeatureExtractor: def init(self): base_model = VGG16(weights="imagenet") self.model = Model(inputs=base_model.input, outputs=base_model.get_layer("fc1").output)
def extract(self, img):
img = img.resize((224, 224)).convert("RGB")
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
feature = self.model.predict(x)[0]
return feature / np.linalg.norm(feature)
我期待numpy.ndarray,但我得到ModuleNotFoundError:没有名为“tensorflow.compat”的模块
以下是错误堆栈
Traceback (most recent call last):
File "C:\Users\Ronte\OneDrive\Documents\Image Search Platfoem\static\offline.py", line 4, in <module>
from featureextractor import FeatureExtractor
File "C:\Users\Ronte\OneDrive\Documents\Image Search Platfoem\static\featureextractor.py", line 1, in <module>
from keras.preprocessing import image
File "C:\Users\Ronte\AppData\Local\Programs\Python\Python310\lib\site-packages\keras\__init__.py", line 3, in <module>
from keras import __internal__
File "C:\Users\Ronte\AppData\Local\Programs\Python\Python310\lib\site-packages\keras\__internal__\__init__.py", line 3, in <module>
from keras.__internal__ import backend
File "C:\Users\Ronte\AppData\Local\Programs\Python\Python310\lib\site-packages\keras\__internal__\backend\__init__.py", line 3, in <module>
from keras.src.backend import _initialize_variables as initialize_variables
File "C:\Users\Ronte\AppData\Local\Programs\Python\Python310\lib\site-packages\keras\src\__init__.py", line 21, in <module>
from keras.src import models
File "C:\Users\Ronte\AppData\Local\Programs\Python\Python310\lib\site-packages\keras\src\models\__init__.py", line 18, in <module>
from keras.src.engine.functional import Functional
File "C:\Users\Ronte\AppData\Local\Programs\Python\Python310\lib\site-packages\keras\src\engine\functional.py", line 23, in <module>
import tensorflow.compat.v2 as tf
ModuleNotFoundError: No module named 'tensorflow.compat'
答: 暂无答案
评论
tensorflow.compat