gpt4 book ai didi

python-3.x - AttributeError: 'NoneType'对象没有属性 'image_data_format' keras

转载 作者:行者123 更新时间:2023-12-02 17:16:24 25 4
gpt4 key购买 nike

我正在尝试测试目的,以使用预训练的vgg-19模型对实时对象进行分类,并且我已在代码中启用了多线程。当我运行以下代码时,我检索到错误。我无法弄清楚我尝试了其他解决方案,但无法修复它。

  from keras.applications.vgg19 import decode_predictions
from keras_applications.vgg19 import VGG19, preprocess_input
label = ''
frame = None
class MyThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
global label
print("[INFO] loading network...")
self.model = VGG19(weights="imagenet")
while (~(frame is None)):
(inID, label) = self.predict(frame)
def predict(self, frame):
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB).astype(np.float32)
image = image.transpose((2, 0, 1))
image = image.reshape((1,) + image.shape)
image = preprocess_input(image)
preds = self.model.predict(image)
return decode_predictions(preds)[0]
cap = cv2.VideoCapture(0)
if (cap.isOpened()):
print("Camera OK")
else:
cap.open()
keras_thread = MyThread()
keras_thread.start()
while (True):
ret, original = cap.read()
frame = cv2.resize(original, (224, 224))
cv2.putText(original, "Label: {}".format(label), (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)
cv2.imshow("Classification", original)
if (cv2.waitKey(1) & 0xFF == ord('q')):
break;
cap.release()
frame = None
cv2.destroyAllWindows()
sys.exit()
下面是我的错误,我在运行代码时检索
     File "C:\miniconda3\envs\tensorflow\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:/Users/video_testing.py", line 17, in run
self.model = VGG16(weights=None)
File "C:\miniconda3\envs\tensorflow\lib\site-packages\keras_applications\vgg16.py", line 97, in VGG16
data_format=backend.image_data_format(),
AttributeError: 'NoneType' object has no attribute 'image_data_format'
Process finished with exit code -1
谢谢您的帮助,我们深表感谢。

最佳答案

根据this,您需要更改此行:

from keras_applications.vgg19 import VGG19, preprocess_input
至:
from keras.applications.vgg19 import VGG19, preprocess_input

关于python-3.x - AttributeError: 'NoneType'对象没有属性 'image_data_format' keras,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64592700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com