代码如下
from imageai.Detection import ObjectDetection
import os
import time
#计时
start = time.time()
execution_path = os.getcwd()
detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
#载入已训练好的文件
detector.setModelPath( os.path.join(execution_path , "resnet50_coco_best_v2.0.1.h5"))
detector.loadModel()
#将检测后的结果保存为新图片
detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , "people.jpg"), output_image_path=os.path.join(execution_path , "image3new.jpg"))
#结束计时
end = time.time()
for eachObject in detections:
print(eachObject["name"] ," : " ,eachObject["percentage_probability"] , " : ", eachObject["box_points"] ) ##预测物体名:预测概率:物体两点坐标(左上,右下)
print("--------------------------------")
print ("\ncost time:",end-start)
报错如下
TypeError Traceback (most recent call last)
TypeError: in user code:
D:\anaconda3\envs\br1\lib\site-packages\imageai\Detection\keras_resnet\layers\_batch_normalization.py:17 call *
return super(BatchNormalization, self).call(training=(not self.freeze), *args, **kwargs)
TypeError: type object got multiple values for keyword argument 'training'