diff --git a/classifier/embedding_food_classifier_app.py b/classifier/embedding_food_classifier_app.py index 81a8fad..af7e8eb 100644 --- a/classifier/embedding_food_classifier_app.py +++ b/classifier/embedding_food_classifier_app.py @@ -61,10 +61,14 @@ class EmbeddingFoodClassifierApp: """加载训练好的embedding模型和FAISS索引""" try: # 模型路径 - model_path = "../model/embedding_20251010_111257/best_embedding_model.pth" + # 获取当前脚本所在目录 + BASE_DIR = os.path.dirname(os.path.abspath(__file__)) + # model_path = "../model/embedding_20251011_133653/best_embedding_model.pth" + model_path = os.path.join(BASE_DIR, "../model/embedding_20251011_133653/best_embedding_model.pth") # FAISS索引目录 - index_dir = "../faiss_vector_db/faiss_index" + # index_dir = "../faiss_vector_db/faiss_index" + index_dir = os.path.join(BASE_DIR, "../faiss_vector_db/faiss_index") if os.path.exists(model_path) and os.path.exists(index_dir): # 1. 加载embedding模型 diff --git a/classifier/embedding_food_classifier_search_app.py b/classifier/embedding_food_classifier_search_app.py index 82c764f..6239ed2 100644 --- a/classifier/embedding_food_classifier_search_app.py +++ b/classifier/embedding_food_classifier_search_app.py @@ -62,10 +62,13 @@ class EmbeddingFoodClassifierApp: """加载训练好的embedding模型和FAISS索引""" try: # 模型路径 - model_path = "../model/embedding_20251010_111257/best_embedding_model.pth" - + # 获取当前脚本所在目录 + BASE_DIR = os.path.dirname(os.path.abspath(__file__)) + # model_path = "../model/embedding_20251011_133653/best_embedding_model.pth" + model_path = os.path.join(BASE_DIR, "../model/embedding_20251011_133653/best_embedding_model.pth") # FAISS索引目录 - index_dir = "../faiss_vector_db/faiss_index" + # index_dir = "../faiss_vector_db/faiss_index" + index_dir = os.path.join(BASE_DIR, "../faiss_vector_db/faiss_index") if os.path.exists(model_path) and os.path.exists(index_dir): # 1. 加载embedding模型 diff --git a/data_expansion/data_expansion.py b/data_expansion/data_expansion.py index 03e879e..6f578dc 100644 --- a/data_expansion/data_expansion.py +++ b/data_expansion/data_expansion.py @@ -27,7 +27,7 @@ for class_name in os.listdir(input_root): input_dir = os.path.join(input_root, class_name) output_dir = os.path.join(output_root, class_name) os.makedirs(output_dir, exist_ok=True) - if class_name == "手撕包菜": + if class_name == "红烧肉": # 读取类别下所有图片路径 img_files = [f for f in os.listdir(input_dir) if f.lower().endswith(('.jpg', '.png', '.jpeg'))] img_paths = [os.path.join(input_dir, f) for f in img_files] diff --git a/faiss_vector_db/build_faiss_index.py b/faiss_vector_db/build_faiss_index.py index 7335be1..291ba02 100644 --- a/faiss_vector_db/build_faiss_index.py +++ b/faiss_vector_db/build_faiss_index.py @@ -477,7 +477,7 @@ class FAISSSearcher: def main(): """主函数""" # 配置参数 - MODEL_PATH = "../model/embedding_20251010_111257/best_embedding_model.pth" + MODEL_PATH = "../model/embedding_20251011_133653/best_embedding_model.pth" TRAIN_DIR = "../dataset/train" OUTPUT_DIR = "faiss_index" BATCH_SIZE = 16