调整模型路径。

This commit is contained in:
2025-10-16 14:41:59 +08:00
parent 3fd23dcc7d
commit e74c42b5d4
3 changed files with 6 additions and 3 deletions
+1
View File
@@ -5,3 +5,4 @@
/faiss_vector_db/faiss_index/
/faiss_vector_db/faiss_index092901/
/faiss_vector_db/faiss_index101001/
/faiss_vector_db/faiss_index*/
@@ -1135,6 +1135,7 @@ class EmbeddingFoodClassifierApp:
# 提取查询图片的特征向量
query_embedding = self.model.extract_embedding(pil_image, normalize=True)
# print('特征向量:', query_embedding)
query_embedding = query_embedding.reshape(1, -1).astype(np.float32)
# 在FAISS索引中搜索最相似的k张图片
+3 -2
View File
@@ -17,7 +17,8 @@ def main():
# 1. 加载训练好的embedding模型权重
# base_model = create_resnet50_embedding(embedding_dim=512, pretrained=True)
base_model = create_mobile_resnet50_embedding(embedding_dim=512, pretrained=True)
model_path = "../model/embedding_20250930_102826/best_embedding_model.pth"
# model_path = "../model/embedding_20250930_102826/best_embedding_model.pth"
model_path = "../model/embedding_20251011_133653/best_embedding_model.pth"
if not os.path.exists(model_path):
print(f"错误:模型文件不存在 {model_path}")
@@ -85,7 +86,7 @@ def main():
traced_model = torch.jit.trace(mobile_wrapper, single_input)
# 保存模型
output_path = "../model/embedding_20250930_102826/best_embedding_model_mobile.pt"
output_path = "../model/embedding_20251011_133653/best_embedding_model_mobile.pt"
traced_model.save(output_path)
print(f"✓ TorchScript模型保存成功: {output_path}")