From 40e90ac7c2de1a4bf7cab3bfc504ec01210a13c3 Mon Sep 17 00:00:00 2001 From: zhangpu <1250681871@qq.com> Date: Wed, 3 Dec 2025 13:43:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=82=E6=95=B0=E4=BF=AE=E6=94=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- classifier/embedding_food_classifier_app.py | 2 +- faiss_vector_db/build_faiss_index.py | 12 ++++++------ faiss_vector_db/visualize_embeddings.py | 8 ++++---- toAndroid/toAndroidEmbedding.py | 8 ++++---- train/grid_search_cosface.py | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/classifier/embedding_food_classifier_app.py b/classifier/embedding_food_classifier_app.py index 06c4396..7731879 100644 --- a/classifier/embedding_food_classifier_app.py +++ b/classifier/embedding_food_classifier_app.py @@ -67,7 +67,7 @@ class EmbeddingFoodClassifierApp: # model_path = os.path.join(BASE_DIR, "../model/embedding_20251011_133653/best_embedding_model.pth") # model_path = os.path.join(BASE_DIR, "../model/ProcessedIngredientRecognition/embedding_20251029_170904/best_embedding_model.pth") # model_path = os.path.join(BASE_DIR, "../model/WholeIngredientRecognition/cosface_20251106_134718/best_cosface_model.pth") - model_path = os.path.join(BASE_DIR, "../model/WholeIngredientRecognition/grid_search_20251120_205839/model_s68.0_m0.38.pth") + model_path = os.path.join(BASE_DIR, "../model/WholeIngredientRecognition/grid_search_20251127_180944/model_s72.0_m0.35.pth") # model_path = os.path.join(BASE_DIR, "../model/DishClassification/cosface_20251111_153649/best_cosface_model.pth") # FAISS索引目录 diff --git a/faiss_vector_db/build_faiss_index.py b/faiss_vector_db/build_faiss_index.py index 7c2ba7f..a99393c 100644 --- a/faiss_vector_db/build_faiss_index.py +++ b/faiss_vector_db/build_faiss_index.py @@ -498,16 +498,16 @@ def main(): # MODEL_PATH = "../model/embedding_20251011_133653/best_embedding_model.pth" # MODEL_PATH = "../model/ProcessedIngredientRecognition/embedding_20251103_172012/best_embedding_model.pth" # MODEL_PATH = "../model/WholeIngredientRecognition/cosface_20251113_160103/best_cosface_model.pth" - # MODEL_PATH = "../model/WholeIngredientRecognition/grid_search_20251120_205839/model_s68.0_m0.38.pth" - MODEL_PATH = "../model/DishClassification/grid_search_20251121_102723/model_s56.0_m0.4.pth" + MODEL_PATH = "../model/WholeIngredientRecognition/grid_search_20251127_180944/model_s72.0_m0.35.pth" + # MODEL_PATH = "../model/DishClassification/grid_search_20251121_102723/model_s56.0_m0.4.pth" # MODEL_PATH = "../model/DishClassification/cosface_20251111_153649/best_cosface_model.pth" # TRAIN_DIR = "../dataset/ProcessedIngredientRecognition/train" - # TRAIN_DIR = "../dataset/WholeIngredientRecognition/train" - TRAIN_DIR = "../dataset/DishClassification/train" + TRAIN_DIR = "../dataset/WholeIngredientRecognition/train" + # TRAIN_DIR = "../dataset/DishClassification/train" # OUTPUT_DIR = "ProcessedIngredientRecognition/faiss_index" - # OUTPUT_DIR = "WholeIngredientRecognition/faiss_index" - OUTPUT_DIR = "DishClassification/faiss_index" + OUTPUT_DIR = "WholeIngredientRecognition/faiss_index" + # OUTPUT_DIR = "DishClassification/faiss_index" BATCH_SIZE = 16 INDEX_TYPE = 'flat' # 'flat', 'ivf', 'hnsw' EMBEDDING_DIM = 512 diff --git a/faiss_vector_db/visualize_embeddings.py b/faiss_vector_db/visualize_embeddings.py index aacfecc..ae6eb9a 100644 --- a/faiss_vector_db/visualize_embeddings.py +++ b/faiss_vector_db/visualize_embeddings.py @@ -162,11 +162,11 @@ def plot_2d(Z: np.ndarray, y: np.ndarray, title: str, out_path: Optional[str] = def main(): parser = argparse.ArgumentParser(description="可视化高维 embedding 并进行坍塌诊断") - parser.add_argument("--embeddings", type=str, default=os.path.join("DishClassification/faiss_index", "embeddings.json"), help="embeddings.json 路径") - # parser.add_argument("--embeddings", type=str, default=os.path.join("WholeIngredientRecognition/faiss_index", "embeddings.json"), help="embeddings.json 路径") + # parser.add_argument("--embeddings", type=str, default=os.path.join("DishClassification/faiss_index", "embeddings.json"), help="embeddings.json 路径") + parser.add_argument("--embeddings", type=str, default=os.path.join("WholeIngredientRecognition/faiss_index", "embeddings.json"), help="embeddings.json 路径") # parser.add_argument("--embeddings", type=str, default=os.path.join("ProcessedIngredientRecognition/faiss_index", "embeddings.json"), help="embeddings.json 路径") - parser.add_argument("--labels", type=str, default=os.path.join("DishClassification/faiss_index", "labels.json"), help="labels.json 路径") - # parser.add_argument("--labels", type=str, default=os.path.join("WholeIngredientRecognition/faiss_index", "labels.json"), help="labels.json 路径") + # parser.add_argument("--labels", type=str, default=os.path.join("DishClassification/faiss_index", "labels.json"), help="labels.json 路径") + parser.add_argument("--labels", type=str, default=os.path.join("WholeIngredientRecognition/faiss_index", "labels.json"), help="labels.json 路径") # parser.add_argument("--labels", type=str, default=os.path.join("ProcessedIngredientRecognition/faiss_index", "labels.json"), help="labels.json 路径") parser.add_argument("--method", type=str, default="pca", choices=["pca", "tsne", "umap"], help="降维方法") parser.add_argument("--seed", type=int, default=42) diff --git a/toAndroid/toAndroidEmbedding.py b/toAndroid/toAndroidEmbedding.py index fc7db4f..a5c72d8 100644 --- a/toAndroid/toAndroidEmbedding.py +++ b/toAndroid/toAndroidEmbedding.py @@ -17,9 +17,9 @@ 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/DishClassification/grid_search_20251121_102723/model_s56.0_m0.4.pth" + # model_path = "../model/DishClassification/grid_search_20251121_102723/model_s56.0_m0.4.pth" # model_path = "../model/WholeIngredientRecognition/cosface_20251106_134718/best_cosface_model.pth" - # model_path = "../model/WholeIngredientRecognition/grid_search_20251120_205839/model_s68.0_m0.38.pth" + model_path = "../model/WholeIngredientRecognition/grid_search_20251127_180944/model_s72.0_m0.35.pth" # model_path = "../model/ProcessedIngredientRecognition/embedding_20251029_173607/best_embedding_model.pth" if not os.path.exists(model_path): @@ -93,8 +93,8 @@ def main(): traced_model = torch.jit.trace(mobile_wrapper, single_input) # 保存模型,一定不要乱改,防止模型覆盖!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - output_path = "../model/DishClassification/grid_search_20251121_102723/best_embedding_model_mobile.pt" - # output_path = "../model/WholeIngredientRecognition/grid_search_20251120_205839/best_embedding_model_mobile.pt" + # output_path = "../model/DishClassification/grid_search_20251121_102723/best_embedding_model_mobile.pt" + output_path = "../model/WholeIngredientRecognition/grid_search_20251127_180944/best_embedding_model_mobile.pt" # output_path = "../model/WholeIngredientRecognition/cosface_20251106_134718/best_embedding_model_mobile.pt" # output_path = "../model/ProcessedIngredientRecognition/embedding_20251029_173607/best_embedding_model_mobile.pt" traced_model.save(output_path) diff --git a/train/grid_search_cosface.py b/train/grid_search_cosface.py index 2ab75c8..6df8493 100644 --- a/train/grid_search_cosface.py +++ b/train/grid_search_cosface.py @@ -53,8 +53,8 @@ GRID_PARAMS = { 'm': [0.32, 0.35, 0.38, 0.40,0.45,0.50], # margin参数 }, 'whole_ingredient': { - 's': [56.0, 60.0, 64.0, 68.0], - 'm': [0.32, 0.35, 0.38, 0.40], + 's': [56.0, 60.0, 64.0, 68.0, 72.0], + 'm': [0.32, 0.35, 0.38, 0.40, 0.45], }, 'processed_ingredient': { 's': [56.0, 60.0, 64.0, 68.0],