Spaces:
Sleeping
Sleeping
Update clip.py
Browse files
clip.py
CHANGED
@@ -11,7 +11,9 @@ def clip_result(image_path):
|
|
11 |
script_dir = os.path.dirname(os.path.abspath(__file__))
|
12 |
|
13 |
# Construct the full path to the file in the subfolder
|
14 |
-
model_path = os.path.join(script_dir, '
|
|
|
|
|
15 |
|
16 |
# 載入訓練好的模型和處理器
|
17 |
model = ChineseCLIPModel.from_pretrained("OFA-Sys/chinese-clip-vit-base-patch16")
|
@@ -26,7 +28,7 @@ def clip_result(image_path):
|
|
26 |
image = Image.open(image_path)
|
27 |
|
28 |
# 2. 加載中文詞彙表
|
29 |
-
with open('
|
30 |
vocab = [line.strip() for line in f.readlines()]
|
31 |
|
32 |
# 3. 圖像和文本處理
|
@@ -63,8 +65,8 @@ def clip_result(image_path):
|
|
63 |
|
64 |
# 6. 輸出最接近的前3名中文詞彙
|
65 |
|
66 |
-
print("最接近的前3名中文詞彙是:")
|
67 |
-
for rank, word in enumerate(top_k_words, 1):
|
68 |
-
|
69 |
|
70 |
return top_k_words
|
|
|
11 |
script_dir = os.path.dirname(os.path.abspath(__file__))
|
12 |
|
13 |
# Construct the full path to the file in the subfolder
|
14 |
+
model_path = os.path.join(script_dir, 'artifacts/models', 'best_clip_model.pth')
|
15 |
+
|
16 |
+
print("model_path:", model_path)
|
17 |
|
18 |
# 載入訓練好的模型和處理器
|
19 |
model = ChineseCLIPModel.from_pretrained("OFA-Sys/chinese-clip-vit-base-patch16")
|
|
|
28 |
image = Image.open(image_path)
|
29 |
|
30 |
# 2. 加載中文詞彙表
|
31 |
+
with open('./chiikawa/word_list.txt', 'r', encoding='utf-8') as f:
|
32 |
vocab = [line.strip() for line in f.readlines()]
|
33 |
|
34 |
# 3. 圖像和文本處理
|
|
|
65 |
|
66 |
# 6. 輸出最接近的前3名中文詞彙
|
67 |
|
68 |
+
# print("最接近的前3名中文詞彙是:")
|
69 |
+
# for rank, word in enumerate(top_k_words, 1):
|
70 |
+
# print(f"{rank}. {word}")
|
71 |
|
72 |
return top_k_words
|