通过跟踪https://imageai.readthedocs.io/en/latest/customdetection/index.html
链接,我训练了自己的YOLOv3模型以进行对象检测。我使用的代码是:
from imageai.Detection.Custom import DetectionModelTrainer
trainer = DetectionModelTrainer()
trainer.setModelTypeAsYOLOv3()
trainer.setDataDirectory(data_directory="Category 2")
trainer.setTrainConfig(object_names_array=["Category 2"], batch_size=2, num_experiments=9)
trainer.trainModel()
我使用tensorflow 1.13.1(cpu),keras 2.2.4创建了模型,损失值为7.562。当我使用以下代码在图像上运行此模型时:
detector = CustomObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath("detection_model-ex-009--loss-0007.562.h5")
detector.setJsonPath("detection_config.json")
detector.loadModel()
detections = detector.detectObjectsFromImage(input_image="image.jpg", output_image_path="detected.jpg")
for detection in detections:
print(detection["name"], " : ", detection["percentage_probability"], " : ", detection["box_points"])
即使我在训练或测试图像上运行代码,代码也可以正常运行,但什么也检测不到。