我有一個在訓練和推理過程中不同的模型。更準確地說,它是一個 SSD(Single Shot Detector),需要在其訓練對應層的頂部添加額外的 DetectionOutput 層。在 Caffe 中,可以使用層定義中的“include”參數來打開/關閉層。但是,如果我希望在每個 epoch 之后(在回調中)運行驗證,那么在定義和編譯模型之后我應該怎么做?我無法在訓練期間添加 DetectionOutput,因為它與損失的輸入不兼容。我還想避免在回調或自定義指標中的某處創(chuàng)建 DetectionOutput 層,因為它需要合理的超參數,并且我想將模型創(chuàng)建邏輯保留在專用模塊中。在以下示例代碼模型中,為推理創(chuàng)建了檢測輸出層。所以評估運行得很好: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 等)方法是什么,但對更改后的模型執(zhí)行驗證步驟,權重相同?也許,有一個單獨的模型來驗證共享權重?
1 回答

小唯快跑啊
TA貢獻1863條經驗 獲得超2個贊
您應該使用 headless (without DetectionOutput) 模型進行訓練,但提供一個帶有頂層的模型進行評估:
def add_detection_output(model):
# make validation/inference model here
...
evaluation = SSDEvaluation(model=add_detection_output(model),
evaluator=PascalDetectionEvaluator(categories),
data_files=[args.eval_data])
避免在回調中使用訓練模型,讓評估對象持有對驗證模型的引用:
class SSDTensorboard(Callback):
def __init__(self, evaluation):
self.evaluation = evaluation
def on_epoch_end(self, epoch, logs={}):
metrics = self.evaluation.evaluate()
添加回答
舉報
0/150
提交
取消