From 5f62c6e2e01c0f5573668810950e1c71a68c0361 Mon Sep 17 00:00:00 2001 From: zhanghuan <1262329256@qq.com> Date: Wed, 10 Sep 2025 15:05:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E4=BF=9D=E5=AD=98=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B9=8B=E5=89=8D=EF=BC=8C=E5=85=88=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E8=B7=AF=E5=BE=84=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- train/train_food_classifier.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/train/train_food_classifier.py b/train/train_food_classifier.py index e736e8e..968eaf3 100644 --- a/train/train_food_classifier.py +++ b/train/train_food_classifier.py @@ -199,6 +199,13 @@ if __name__ == '__main__': if val_acc > best_val_acc: best_val_acc = val_acc best_model_path = settings.BEST_MODEL_PATH + + # 检查并创建模型保存目录 + model_dir = os.path.dirname(best_model_path) + if not os.path.exists(model_dir): + os.makedirs(model_dir) + print(f"创建模型保存目录: {model_dir}") + torch.save(model.state_dict(), settings.BEST_MODEL_PATH) print(f'保存最佳模型,验证准确率: {best_val_acc:.2f}%')