修改参数。
This commit is contained in:
@@ -65,7 +65,7 @@ class EmbeddingFoodClassifierApp:
|
|||||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
# model_path = "../model/embedding_20251011_133653/best_embedding_model.pth"
|
# 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")
|
# 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_100204/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/embedding_20251024_091151/best_embedding_model.pth")
|
# model_path = os.path.join(BASE_DIR, "../model/WholeIngredientRecognition/embedding_20251024_091151/best_embedding_model.pth")
|
||||||
# model_path = os.path.join(BASE_DIR, "../model/DishClassification/embedding_20251022_093635/best_embedding_model.pth")
|
# model_path = os.path.join(BASE_DIR, "../model/DishClassification/embedding_20251022_093635/best_embedding_model.pth")
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ class EmbeddingFoodClassifierApp:
|
|||||||
# 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")
|
# index_dir = os.path.join(BASE_DIR, "../faiss_vector_db/faiss_index")
|
||||||
index_dir = os.path.join(BASE_DIR, "../faiss_vector_db/ProcessedIngredientRecognition/faiss_index")
|
index_dir = os.path.join(BASE_DIR, "../faiss_vector_db/ProcessedIngredientRecognition/faiss_index")
|
||||||
index_dir = os.path.join(BASE_DIR, "../faiss_vector_db/WholeIngredientRecognition/faiss_index")
|
# index_dir = os.path.join(BASE_DIR, "../faiss_vector_db/WholeIngredientRecognition/faiss_index")
|
||||||
# index_dir = os.path.join(BASE_DIR, "../faiss_vector_db/DishClassification/faiss_index")
|
# index_dir = os.path.join(BASE_DIR, "../faiss_vector_db/DishClassification/faiss_index")
|
||||||
|
|
||||||
if os.path.exists(model_path) and os.path.exists(index_dir):
|
if os.path.exists(model_path) and os.path.exists(index_dir):
|
||||||
|
|||||||
@@ -480,14 +480,14 @@ def main():
|
|||||||
"""主函数"""
|
"""主函数"""
|
||||||
# 配置参数
|
# 配置参数
|
||||||
# MODEL_PATH = "../model/embedding_20251011_133653/best_embedding_model.pth"
|
# MODEL_PATH = "../model/embedding_20251011_133653/best_embedding_model.pth"
|
||||||
MODEL_PATH = "../model/ProcessedIngredientRecognition/embedding_20251029_100204/best_embedding_model.pth"
|
# MODEL_PATH = "../model/ProcessedIngredientRecognition/embedding_20251029_170904/best_embedding_model.pth"
|
||||||
# MODEL_PATH = "../model/WholeIngredientRecognition/embedding_20251024_091151/best_embedding_model.pth"
|
MODEL_PATH = "../model/WholeIngredientRecognition/embedding_20251030_135024/best_embedding_model.pth"
|
||||||
# MODEL_PATH = "../model/DishClassification/embedding_20251022_093635/best_embedding_model.pth"
|
# MODEL_PATH = "../model/DishClassification/embedding_20251022_093635/best_embedding_model.pth"
|
||||||
TRAIN_DIR = "../dataset/ProcessedIngredientRecognition/train"
|
# TRAIN_DIR = "../dataset/ProcessedIngredientRecognition/train"
|
||||||
# TRAIN_DIR = "../dataset/WholeIngredientRecognition/train"
|
TRAIN_DIR = "../dataset/WholeIngredientRecognition/train"
|
||||||
# TRAIN_DIR = "../dataset/DishClassification/train"
|
# TRAIN_DIR = "../dataset/DishClassification/train"
|
||||||
OUTPUT_DIR = "ProcessedIngredientRecognition/faiss_index"
|
# OUTPUT_DIR = "ProcessedIngredientRecognition/faiss_index"
|
||||||
# OUTPUT_DIR = "WholeIngredientRecognition/faiss_index"
|
OUTPUT_DIR = "WholeIngredientRecognition/faiss_index"
|
||||||
# OUTPUT_DIR = "DishClassification/faiss_index"
|
# OUTPUT_DIR = "DishClassification/faiss_index"
|
||||||
BATCH_SIZE = 16
|
BATCH_SIZE = 16
|
||||||
INDEX_TYPE = 'flat' # 'flat', 'ivf', 'hnsw'
|
INDEX_TYPE = 'flat' # 'flat', 'ivf', 'hnsw'
|
||||||
|
|||||||
@@ -163,11 +163,11 @@ def plot_2d(Z: np.ndarray, y: np.ndarray, title: str, out_path: Optional[str] =
|
|||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="可视化高维 embedding 并进行坍塌诊断")
|
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("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("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("--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("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("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("--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("--method", type=str, default="pca", choices=["pca", "tsne", "umap"], help="降维方法")
|
||||||
parser.add_argument("--seed", type=int, default=42)
|
parser.add_argument("--seed", type=int, default=42)
|
||||||
parser.add_argument("--max_points", type=int, default=None, help="抽样上限,避免t-SNE/UMAP过慢;None为全量")
|
parser.add_argument("--max_points", type=int, default=None, help="抽样上限,避免t-SNE/UMAP过慢;None为全量")
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ def main():
|
|||||||
# base_model = create_resnet50_embedding(embedding_dim=512, pretrained=True)
|
# base_model = create_resnet50_embedding(embedding_dim=512, pretrained=True)
|
||||||
base_model = create_mobile_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/WholeIngredientRecognition/embedding_20251021_085915/best_embedding_model.pth"
|
model_path = "../model/WholeIngredientRecognition/embedding_20251030_135024/best_embedding_model.pth"
|
||||||
|
# model_path = "../model/ProcessedIngredientRecognition/embedding_20251029_173607/best_embedding_model.pth"
|
||||||
|
|
||||||
if not os.path.exists(model_path):
|
if not os.path.exists(model_path):
|
||||||
print(f"错误:模型文件不存在 {model_path}")
|
print(f"错误:模型文件不存在 {model_path}")
|
||||||
@@ -86,7 +87,8 @@ def main():
|
|||||||
traced_model = torch.jit.trace(mobile_wrapper, single_input)
|
traced_model = torch.jit.trace(mobile_wrapper, single_input)
|
||||||
|
|
||||||
# 保存模型
|
# 保存模型
|
||||||
output_path = "../model/WholeIngredientRecognition/embedding_20251021_085915/best_embedding_model_mobile.pt"
|
output_path = "../model/WholeIngredientRecognition/embedding_20251030_135024/best_embedding_model_mobile.pt"
|
||||||
|
# output_path = "../model/ProcessedIngredientRecognition/embedding_20251029_173607/best_embedding_model_mobile.pt"
|
||||||
traced_model.save(output_path)
|
traced_model.save(output_path)
|
||||||
print(f"✓ TorchScript模型保存成功: {output_path}")
|
print(f"✓ TorchScript模型保存成功: {output_path}")
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,8 @@ TASKS = {
|
|||||||
lr=8e-4,
|
lr=8e-4,
|
||||||
# triplet_margin=0.35,
|
# triplet_margin=0.35,
|
||||||
triplet_margin=0.5,
|
triplet_margin=0.5,
|
||||||
center_loss_weight=0.1,
|
# center_loss_weight=0.1,
|
||||||
|
center_loss_weight=0.7,
|
||||||
aug_strength="medium",
|
aug_strength="medium",
|
||||||
),
|
),
|
||||||
"processed_ingredient": TaskConfig(
|
"processed_ingredient": TaskConfig(
|
||||||
@@ -820,6 +821,6 @@ if __name__ == "__main__":
|
|||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("task", choices=list(TASKS.keys()), nargs="?", default="dish")
|
parser.add_argument("task", choices=list(TASKS.keys()), nargs="?", default="dish")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
main("processed_ingredient")
|
# main("processed_ingredient")
|
||||||
# main("whole_ingredient")
|
main("whole_ingredient")
|
||||||
# main("dish")
|
# main("dish")
|
||||||
Reference in New Issue
Block a user