[英]Cannot import name "BatchNormalization" from "keras.layers.normalization" after trying to install imageai 2.1.5
I've tried to install pytorch but it failed.我尝试安装 pytorch 但失败了。 I've also downloaded all the libraries needed for it to run (opencv-python, numpy, scipy, among others) still, nothing... How can I solve this issue?
我还下载了它运行所需的所有库(opencv-python、numpy、scipy 等),仍然没有......我该如何解决这个问题?
Error:错误:
File "C:\Users\Home\PycharmProjects\XG -I programming(trial part 2)\Mask_detection(trial 6).py", line 1, in <module>
from imageai.Detection import VideoObjectDetection
File "C:\Users\Home\PycharmProjects\XG -I programming(trial part 2)\venv\lib\site-packages\imageai\Detection\__init__.py", line 17, in <module>
from imageai.Detection.YOLOv3.models import yolo_main, tiny_yolo_main
File "C:\Users\Home\PycharmProjects\XG -I programming(trial part 2)\venv\lib\site-packages\imageai\Detection\YOLOv3\models.py", line 8, in <module>
from keras.layers.normalization import BatchNormalization
ImportError: cannot import name 'BatchNormalization' from 'keras.layers.normalization' (C:\Users\Home\PycharmProjects\XG -I programming(trial part 2)\venv\lib\site-packages\keras\layers\normalization\__init__.py)
Code:代码:
from imageai.Detection import VideoObjectDetection
import cv2
camera = cv2.VideoCapture(0)
detector = VideoObjectDetection()
model_path = "./Models/yolo.h5"
detector.setModelTypeAsYOLOv3()
detector.setModelPath(model_path)
detector.loadModel()
while True:
ret, frame = camera.read()
rgb_frame = frame[:, :, ::-1]
video_detection = detector.detectObjectsFromVideo(camera_input=camera, output_file_path ="./camera_detected_video", frames_per_second=28, log_progress=True, minimum_percentage_probability=40)
cv2.imshow('frame', frame)
print(video_detection)
if cv2.waitKey(1) & 0xff == ord('q'):
break
camera.release()
cv2.destroyAllWindows()
The problem is with the keras version, try installing older keras version问题出在 keras 版本上,尝试安装较旧的 keras 版本
pip3 install keras==2.4.3 pip3 安装 keras==2.4.3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.