建立FAISS索引。

This commit is contained in:
zhanghuan
2025-09-23 15:34:23 +08:00
parent 2d5096a0b2
commit d51853997f
3 changed files with 524 additions and 2 deletions
+3 -1
View File
@@ -69,6 +69,7 @@ class EmbeddingFoodClassifierApp:
if os.path.exists(model_path) and os.path.exists(index_dir):
# 1. 加载embedding模型
print("正在加载embedding模型...")
# 先把网络结构拿过来,传入embedding维度,预训练,除了加载网络结构,还把预训练的网络参数加载过来
self.model = create_resnet50_embedding(
embedding_dim=512,
pretrained=True,
@@ -86,8 +87,9 @@ class EmbeddingFoodClassifierApp:
self.model.load_state_dict(checkpoint)
else:
self.model.load_state_dict(checkpoint)
# 把模型放到设备上(GPU或CPU
self.model.to(self.device)
# 模型在评估模式下运行时,会禁用某些操作,如BN层和Dropout层
self.model.eval()
print("Embedding模型加载成功!")