我有一个在训练和推理过程中不同的模型。更准确地说,它是一个 SSD(Single Shot Detector),需要在其训练对应层的顶部添加额外的 DetectionOutput 层。在 Caffe 中,可以使用层定义中的“include”参数来打开/关闭层。
但是,如果我希望在每个 epoch 之后(在回调中)运行验证,那么在定义和编译模型之后我应该怎么做?
我无法在训练期间添加 DetectionOutput,因为它与损失的输入不兼容。
我还想避免在回调或自定义指标中的某处创建 DetectionOutput 层,因为它需要合理的超参数,并且我想将模型创建逻辑保留在专用模块中。
在以下示例代码模型中,为推理创建了检测输出层。所以评估运行得很好:
model, _, _ = build_model(input_shape=(args.input_height, args.input_width, 3),
n_classes=num_classes,
mode='inference')
model.load_weights(args.model, by_name=True)
evaluation = SSDEvaluation(model=model,
evaluator=PascalDetectionEvaluator(categories),
data_files=[args.eval_data])
metrics = evaluation.evaluate()
但是这个回调不能正常工作,因为在训练模型期间没有 DetectionOutput:
class SSDTensorboard(Callback):
def __init__(self, evaluator, eval_data):
self.evaluator = evaluator
self.eval_data = eval_data
def on_train_begin(self, logs={}):
self.metrics = []
def on_epoch_end(self, epoch, logs={}):
evaluation = SSDEvaluation(self.model, self.evaluator, self.eval_data)
metrics = evaluation.evaluate()
self.metrics.append(metrics)
像往常一样运行训练的正确(pythonic、keratonic 等)方法是什么,但对更改后的模型执行验证步骤,权重相同?也许,有一个单独的模型来验证共享权重?
小唯快跑啊
相关分类