建立FAISS索引。
This commit is contained in:
@@ -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模型加载成功!")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user