Spaces:
Sleeping
Sleeping
'app.py
Browse files- app.py +19 -8
- exampel_image/1.jpg +0 -0
- exampel_image/10.jpg +0 -0
- exampel_image/11.jpg +0 -0
- exampel_image/12.jpg +0 -0
- exampel_image/13.jpg +0 -0
- exampel_image/14.jpg +0 -0
- exampel_image/15.jpg +0 -0
- exampel_image/2.jpg +0 -0
- exampel_image/3.jpg +0 -0
- exampel_image/4.jpg +0 -0
- exampel_image/5.jpg +0 -0
- exampel_image/6.jpg +0 -0
- exampel_image/7.jpg +0 -0
- exampel_image/8.jpg +0 -0
- exampel_image/9.jpg +0 -0
- example_image/1.jpg +0 -0
- example_image/10.jpg +0 -0
- example_image/11.jpg +0 -0
- example_image/12.jpg +0 -0
- example_image/13.jpg +0 -0
- example_image/14.jpg +0 -0
- example_image/15.jpg +0 -0
- example_image/2.jpg +0 -0
- example_image/3.jpg +0 -0
- example_image/4.jpg +0 -0
- example_image/5.jpg +0 -0
- example_image/6.jpg +0 -0
- example_image/7.jpg +0 -0
- example_image/8.jpg +0 -0
- example_image/9.jpg +0 -0
app.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
import time
|
2 |
import os
|
3 |
-
|
4 |
-
|
5 |
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"
|
|
|
|
|
6 |
from PIL import Image
|
7 |
import numpy as np
|
8 |
import argparse
|
@@ -40,17 +40,17 @@ def get_parser():
|
|
40 |
cfg = config.merge_cfg_from_list(cfg, args.opts)
|
41 |
return cfg
|
42 |
args = get_parser()
|
43 |
-
data_dir = './LuojiaHOG(
|
44 |
-
imgs_folder = '
|
45 |
|
46 |
# image_id = 'sample44_1641.jpg'
|
47 |
# model_path = './rsvit.pth'
|
48 |
|
49 |
-
with open('
|
50 |
image_dict = pickle.load(f)
|
51 |
image_feat = np.array(list(image_dict.values()))
|
52 |
f.close()
|
53 |
-
with open('
|
54 |
text_dict = pickle.load(f)
|
55 |
text_feat = np.array(list(text_dict.values()))
|
56 |
f.close()
|
@@ -169,8 +169,20 @@ def search(text_query, image_query, top_k: int = 10):
|
|
169 |
# {"Score": [torch.round(torch.tensor(value)*100)/100 for value in top_k_scores], "Title": top_k_titles, "Text": top_k_texts}
|
170 |
# )
|
171 |
# 获取图像
|
|
|
|
|
172 |
if text_query != None:
|
173 |
-
image_output = [Image.open(imgs_folder + img.replace('_','/')) for img in info]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
else:
|
175 |
image_output = []
|
176 |
|
@@ -282,7 +294,6 @@ def txt_search(text_query, top_k: int = 10):
|
|
282 |
# query_embedding = model.encode(query)
|
283 |
|
284 |
text = tokenize(text_query, 328)
|
285 |
-
|
286 |
query_vector = model.text_encode(text)
|
287 |
index = text_index
|
288 |
|
|
|
1 |
import time
|
2 |
import os
|
|
|
|
|
3 |
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"
|
4 |
+
import zipfile
|
5 |
+
from io import BytesIO
|
6 |
from PIL import Image
|
7 |
import numpy as np
|
8 |
import argparse
|
|
|
40 |
cfg = config.merge_cfg_from_list(cfg, args.opts)
|
41 |
return cfg
|
42 |
args = get_parser()
|
43 |
+
data_dir = './LuojiaHOG(best)_.json'
|
44 |
+
imgs_folder = 'image/'
|
45 |
|
46 |
# image_id = 'sample44_1641.jpg'
|
47 |
# model_path = './rsvit.pth'
|
48 |
|
49 |
+
with open('image_features_best.pkl', 'rb') as f:
|
50 |
image_dict = pickle.load(f)
|
51 |
image_feat = np.array(list(image_dict.values()))
|
52 |
f.close()
|
53 |
+
with open('text_features_best.pkl', 'rb') as f:
|
54 |
text_dict = pickle.load(f)
|
55 |
text_feat = np.array(list(text_dict.values()))
|
56 |
f.close()
|
|
|
169 |
# {"Score": [torch.round(torch.tensor(value)*100)/100 for value in top_k_scores], "Title": top_k_titles, "Text": top_k_texts}
|
170 |
# )
|
171 |
# 获取图像
|
172 |
+
|
173 |
+
|
174 |
if text_query != None:
|
175 |
+
# image_output = [Image.open(imgs_folder + img.replace('_','/')) for img in info]
|
176 |
+
image_output = []
|
177 |
+
for img in info:
|
178 |
+
sample_name = img.split('_')[0]
|
179 |
+
image_path = imgs_folder + sample_name + '.zip'
|
180 |
+
with zipfile.ZipFile(image_path, 'r') as zip_ref:
|
181 |
+
# 读取图像文件
|
182 |
+
with zip_ref.open(img.replace('_', '/')) as image_file:
|
183 |
+
# 将读取的字节流转换为图像
|
184 |
+
image = Image.open(BytesIO(image_file.read()))
|
185 |
+
image_output.append(image)
|
186 |
else:
|
187 |
image_output = []
|
188 |
|
|
|
294 |
# query_embedding = model.encode(query)
|
295 |
|
296 |
text = tokenize(text_query, 328)
|
|
|
297 |
query_vector = model.text_encode(text)
|
298 |
index = text_index
|
299 |
|
exampel_image/1.jpg
DELETED
Binary file (32 kB)
|
|
exampel_image/10.jpg
DELETED
Binary file (32.6 kB)
|
|
exampel_image/11.jpg
DELETED
Binary file (31.9 kB)
|
|
exampel_image/12.jpg
DELETED
Binary file (31.3 kB)
|
|
exampel_image/13.jpg
DELETED
Binary file (33 kB)
|
|
exampel_image/14.jpg
DELETED
Binary file (25.5 kB)
|
|
exampel_image/15.jpg
DELETED
Binary file (14.2 kB)
|
|
exampel_image/2.jpg
DELETED
Binary file (36.6 kB)
|
|
exampel_image/3.jpg
DELETED
Binary file (38.1 kB)
|
|
exampel_image/4.jpg
DELETED
Binary file (45.6 kB)
|
|
exampel_image/5.jpg
DELETED
Binary file (30.3 kB)
|
|
exampel_image/6.jpg
DELETED
Binary file (35.7 kB)
|
|
exampel_image/7.jpg
DELETED
Binary file (34.2 kB)
|
|
exampel_image/8.jpg
DELETED
Binary file (29.1 kB)
|
|
exampel_image/9.jpg
DELETED
Binary file (43.9 kB)
|
|
example_image/1.jpg
CHANGED
![]() |
![]() |
example_image/10.jpg
CHANGED
![]() |
![]() |
example_image/11.jpg
CHANGED
![]() |
![]() |
example_image/12.jpg
CHANGED
![]() |
![]() |
example_image/13.jpg
CHANGED
![]() |
![]() |
example_image/14.jpg
CHANGED
![]() |
![]() |
example_image/15.jpg
CHANGED
![]() |
![]() |
example_image/2.jpg
CHANGED
![]() |
![]() |
example_image/3.jpg
CHANGED
![]() |
![]() |
example_image/4.jpg
CHANGED
![]() |
![]() |
example_image/5.jpg
CHANGED
![]() |
![]() |
example_image/6.jpg
CHANGED
![]() |
![]() |
example_image/7.jpg
CHANGED
![]() |
![]() |
example_image/8.jpg
CHANGED
![]() |
![]() |
example_image/9.jpg
CHANGED
![]() |
![]() |