Spaces:
Running
Running
Upload 16 files
Browse files- app.py +17 -28
- 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
app.py
CHANGED
@@ -1,8 +1,8 @@
|
|
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,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 = 'image/'
|
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()
|
@@ -80,15 +80,15 @@ text_index = faiss.IndexFlatL2(512)
|
|
80 |
image_index.add(image_feat)
|
81 |
text_index.add(text_feat)
|
82 |
#example
|
83 |
-
text1 = "
|
84 |
-
text2 = "The
|
85 |
-
text3 = "The
|
86 |
-
text4 = "The image
|
87 |
-
text5 = "The image shows a
|
88 |
-
text6 = "The image
|
89 |
-
text7 = "The
|
90 |
-
text8 = "The
|
91 |
-
text9 = "The image shows a
|
92 |
text10 = "The image shows a residential area with several single-story houses next to a large open stretch of wasteland. The houses are rectangular, evenly spaced, and have pale blue walls with hints of white, suggesting they are plastered. The wasteland is a mix of brown and green, featuring patches of dry grass and scattered shrubs. Surrounding the houses are tall, slender trees with lush green canopies providing shade. The scene is captured from a high altitude, giving a bird's-eye view where the houses, trees, and the central wasteland are clearly visible."
|
93 |
text11 = "The color remote sensing image shows an urban city street from a high altitude. The street is flanked by tall, sleek buildings featuring a mix of modern and traditional architecture, mostly in white and beige, with some more colorful facades. The street is busy with cars in white, black, silver, and gold, and pedestrians of diverse ethnicities wearing both modern and traditional clothing. Tall, lush trees with various shades of green line the street. The sky is bright blue with a few fluffy clouds. The image is high quality, with clear, visible details."
|
94 |
text12 = "The image displays a residential area with houses arranged in a grid-like pattern, each having a small yard. The houses are mostly uniform in size and shape, featuring pitched roofs and rectangular windows. They come in a variety of colors, from bright ones like yellow and pink to more neutral tones like white and gray. Trees of different sizes and shapes are scattered throughout the area. A parking lot next to the houses is mostly filled with cars, though some spots are empty. Sidewalks and streets connect the houses to other parts of the island."
|
@@ -169,20 +169,8 @@ 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 |
-
|
173 |
-
|
174 |
if text_query != None:
|
175 |
-
|
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,6 +282,7 @@ def txt_search(text_query, top_k: int = 10):
|
|
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 |
|
|
|
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 |
cfg = config.merge_cfg_from_list(cfg, args.opts)
|
41 |
return cfg
|
42 |
args = get_parser()
|
43 |
+
data_dir = './LuojiaHOG(demo).json'
|
44 |
+
imgs_folder = './image/'
|
45 |
|
46 |
# image_id = 'sample44_1641.jpg'
|
47 |
# model_path = './rsvit.pth'
|
48 |
|
49 |
+
with open('image_features.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.pkl', 'rb') as f:
|
54 |
text_dict = pickle.load(f)
|
55 |
text_feat = np.array(list(text_dict.values()))
|
56 |
f.close()
|
|
|
80 |
image_index.add(image_feat)
|
81 |
text_index.add(text_feat)
|
82 |
#example
|
83 |
+
text1 = "The image shows an airfield situated within a military base, offering a comprehensive bird's-eye view of the entire area. The airfield is enclosed by a secure perimeter fence. The main runway, made of concrete and marked with distinct white stripes, is clearly visible and is designed for aircraft takeoffs and landings. Connected to the runway are several asphalt taxiways, which are slightly darker in color and provide pathways for aircraft to move between the runway and other parts of the airfield."
|
84 |
+
text2 = "The image shows a residential area with houses, parking lots, and significant vegetation. The houses are arranged in rows with roofs in various shades of brown and gray. Between the houses, there are lawns and gardens with green grass. The parking lots are paved with asphalt and have white lines indicating parking spaces. There are clusters of trees and shrubs around the residential buildings, forming green areas that separate different parts of the neighborhood. The vegetation is dense in some sections, especially along the edges of the residential zone. The layout is straightforward, with clear divisions between the houses, parking lots, and green spaces, indicating a well-organized residential area."
|
85 |
+
text3 = "The image shows a set of railway tracks running alongside several human-made structures. The tracks are made of metal and run parallel to each other, with wooden or concrete ties supporting them. Adjacent to the tracks, there are buildings that appear to be factories or office buildings. These structures are large and rectangular, with flat roofs and multiple windows. The ground near the tracks is clear of vegetation, indicating regular maintenance. There are access roads connecting the buildings to the railway tracks, facilitating transportation and logistics. The overall layout is organized, with clear separations between the railway, buildings, and paved areas. This setup indicates an industrial or commercial zone where the railway tracks are integral for transportation and operational efficiency."
|
86 |
+
text4 = "The image shows a school complex with several buildings and an adjacent playground. The school buildings are rectangular, with flat roofs and multiple windows. They are arranged in a compact formation, connected by pathways. The roofs are mostly light-colored, likely made of materials like concrete or metal. Next to the buildings is a large playground. The playground includes a grassy field, a running track, and several paved areas for various sports and activities. There are also small structures like sheds or pavilions within the playground area."
|
87 |
+
text5 = "The image shows a cemetery adjacent to a residential area. The cemetery is organized into neat rows of graves with headstones. The headstones are mostly rectangular and vary in size, creating a grid-like pattern. The ground within the cemetery is primarily grass, with some pathways made of gravel or pavement for access. Next to the cemetery is a residential area with houses arranged in rows. The houses have varied roof colors, including shades of brown and gray. Each house has a small yard with green lawns and some trees or shrubs, providing a touch of greenery."
|
88 |
+
text6 = "The image displays a soccer field, featuring a rectangular grassy surface with clearly marked boundaries and white lines defining the playing area. The field is surrounded by a track, possibly for running or warm-up exercises, and is enclosed by a fence or barrier. Near the field, there are seating areas, likely for spectators, arranged in rows or tiers. Floodlights are positioned around the perimeter, indicating the capability for night games or events. Adjacent to the field, there may be additional facilities such as changing rooms, restrooms, or concession stands. "
|
89 |
+
text7 = "The image presents a sports complex featuring both a soccer field and a basketball court. The soccer field occupies a rectangular area with neatly trimmed grass and clearly marked boundaries. White lines delineate the playing area, while surrounding tracks suggest space for warm-up or jogging. Adjacent to the field are seating arrangements for spectators, likely indicating the field's use for organized matches or events. Floodlights are positioned around the perimeter, enabling night-time activities. Adjacent to the soccer field is a basketball court, identifiable by its rectangular shape and hoop installations at each end. The court surface may be made of asphalt or concrete and is marked with lines for gameplay. The area around the court is open, with limited vegetation or structures nearby."
|
90 |
+
text8 = "The image showcases a sports complex featuring both a tennis court and a basketball court. The tennis court is distinguished by its rectangular shape, with a smooth playing surface marked by white lines indicating the boundaries and service areas. Surrounding the court is a fence or barrier, likely to prevent stray balls from interfering with gameplay. Adjacent to the tennis court, seating arrangements for spectators are visible, suggesting its use for organized matches or tournaments. "
|
91 |
+
text9 = "The aerial image shows a residential area with a centrally located swimming pool. The pool is a large, rectangular structure with clear blue water. Surrounding the pool, residential buildings are arranged in a neat grid pattern. These buildings vary in size and style, featuring different roof colors and garden layouts. Each house has a yard, some with green lawns, while others have patios or small gardens. Trees and shrubs are interspersed throughout the neighborhood, adding greenery and shade."
|
92 |
text10 = "The image shows a residential area with several single-story houses next to a large open stretch of wasteland. The houses are rectangular, evenly spaced, and have pale blue walls with hints of white, suggesting they are plastered. The wasteland is a mix of brown and green, featuring patches of dry grass and scattered shrubs. Surrounding the houses are tall, slender trees with lush green canopies providing shade. The scene is captured from a high altitude, giving a bird's-eye view where the houses, trees, and the central wasteland are clearly visible."
|
93 |
text11 = "The color remote sensing image shows an urban city street from a high altitude. The street is flanked by tall, sleek buildings featuring a mix of modern and traditional architecture, mostly in white and beige, with some more colorful facades. The street is busy with cars in white, black, silver, and gold, and pedestrians of diverse ethnicities wearing both modern and traditional clothing. Tall, lush trees with various shades of green line the street. The sky is bright blue with a few fluffy clouds. The image is high quality, with clear, visible details."
|
94 |
text12 = "The image displays a residential area with houses arranged in a grid-like pattern, each having a small yard. The houses are mostly uniform in size and shape, featuring pitched roofs and rectangular windows. They come in a variety of colors, from bright ones like yellow and pink to more neutral tones like white and gray. Trees of different sizes and shapes are scattered throughout the area. A parking lot next to the houses is mostly filled with cars, though some spots are empty. Sidewalks and streets connect the houses to other parts of the island."
|
|
|
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 |
# 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 |
|
exampel_image/1.jpg
ADDED
![]() |
exampel_image/10.jpg
ADDED
![]() |
exampel_image/11.jpg
ADDED
![]() |
exampel_image/12.jpg
ADDED
![]() |
exampel_image/13.jpg
ADDED
![]() |
exampel_image/14.jpg
ADDED
![]() |
exampel_image/15.jpg
ADDED
![]() |
exampel_image/2.jpg
ADDED
![]() |
exampel_image/3.jpg
ADDED
![]() |
exampel_image/4.jpg
ADDED
![]() |
exampel_image/5.jpg
ADDED
![]() |
exampel_image/6.jpg
ADDED
![]() |
exampel_image/7.jpg
ADDED
![]() |
exampel_image/8.jpg
ADDED
![]() |
exampel_image/9.jpg
ADDED
![]() |