模型训练后,进行识别时,权重不一致,怎么修改? 5C

通过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.

应该怎么修改让他们可以进行识别

3个回答

你是不是保存了模型以后又修改了模型,两个不一致,只能重新训练了。

我也遇到了相同的问题,我们训练的只是图像预测的模型不能用于对象检测

不知道这个问题解决没有,来回答一下吧,下式三选一,与自己选的模型(官方)对应就行了
detector.setModelTypeAsTinyYOLOv3()
detector.setModelTypeAsYOLOv3()#
detector.setModelTypeAsRetinaNet()#

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问