阿三先生 2018-10-23 13:36 采纳率: 0%
浏览 3714
已结题

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

通过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条回答 默认 最新

  • devmiao 2018-10-24 04:57
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘