通过ModelTraining 训练的生成模型
from imageai.Prediction.Custom import ModelTraining
model_trainer = ModelTraining()
model_trainer.setModelTypeAsResNet()
model_trainer.setDataDirectory("datasets")
# batch_size 训练类别的整除数
model_trainer.trainModel(num_objects=4, num_experiments=10, enhance_data=True, batch_size=2, show_network_summary=True)
当与imageai的模型世界时报错
# 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 , "model_weights.h5"))
# detector.loadModel('fastest')
#
# #将检测后的结果保存为新图片
# detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , "./img/one.jpg"), output_image_path=os.path.join(execution_path , "./img/image3new.jpg"))
#
# #结束计时
# end = time.time()
#
# for eachObject in detections:
# print(eachObject["name"] + " : " + eachObject["percentage_probability"] )
# print("--------------------------------")
#
# print ("\ncost time:",end-start)
#!/usr/bin/env python3
from imageai.Detection import ObjectDetection
import os
execution_path = os.getcwd()
detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath(os.path.join(execution_path , "./models/model_ex-010_acc-0.250000.h5"))
detector.loadModel()
detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , "img/one.jpg"), output_image_path=os.path.join(execution_path , "image3new.jpg"), minimum_percentage_probability=30)
for eachObject in detections:
print(eachObject["name"] , " : ", eachObject["percentage_probability"])
print("--------------------------------")
运行时报错:
ValueError: You are trying to load a weight file containing 107 layers into a model with 116 layers.
应该怎么修改让他们可以进行识别