aleo1 commited on
Commit
ecd4a3e
1 Parent(s): 4ce0c66

Upload 16 files

Browse files
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(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()
@@ -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 = "A rectangular sports field with green artificial turf is visible. The field has white boundary lines and a bright blue surrounding track. Adjacent buildings with flat, gray roofs are visible. Roads with marked lanes run alongside the buildings. A red-roofed structure stands near the sports field. Vegetation includes small, scattered trees with green foliage. Cars are parked along the roads. Shadows cast by the buildings indicate different heights. Pedestrian pathways are present alongside the roads. The image contains a mix of recreational and residential zones. The layout suggests a planned urban environment."
84
- text2 = "The picture shows a wetland full of diverse plants. The area has a network of waterways and thick vegetation, mainly tall reeds and cattails with slender, bamboo-like stalks. The scene is mostly green, with touches of blue and brown, creating a peaceful vibe. The land is mostly flat, allowing a wide view of the wetland. The image is taken from high above, giving a bird's-eye view of the waterways and aquatic plants in the wetland ecosystem."
85
- text3 = "The residential area is depicted in the color remote sensing image with a bird's-eye view. The scene shows a heterogeneous mix of houses with varying shapes and sizes, spread across the area. The houses are painted in different colors, with some having white walls and red-tiled roofs, while others have blue or green exteriors. The residential area also contains several green spaces, including small front yards, larger parks, and gardens with various types of trees and shrubs. A broad road runs through the center of the residential area, connecting different parts of the community. The road is lined with trees on both sides and has a designated sidewalk for pedestrians. The image also captures various other elements of the urban landscape, including utility poles, streetlights, and a few commercial buildings on the outskirts of the residential area."
86
- text4 = "The image depicts a nature reserve on an island, with a landscape dominated by sparse shrubs and meadows in the interior. The color of the image is predominantly green, with hints of brown and yellow, representing the different types of vegetation and soil. The reserve is characterized by rolling hills and gentle valleys, with some areas of flat terrain interspersed throughout. The landscape is dotted with trees, which are scattered randomly and have a relatively low density."
87
- text5 = "The image shows a nature reserve on an island, featuring a landscape mainly covered with sparse shrubs and meadows. The dominant color is green, with touches of brown and yellow indicating various vegetation types and soil. The reserve has rolling hills and gentle valleys, along with some flat areas. Trees are scattered randomly across the landscape, with a relatively low density."
88
- text6 = "The image describes a scene of a residential area with several houses situated next to a large, open stretch of land, which serves as a waste land. The houses are single-story structures with rectangular shapes and are evenly distributed across the scene. They have a pale blue color with a hint of white, which suggests that they are constructed using plastered walls. The waste land is covered in a mixture of brown and green colors, with patches of dry grass and scattered shrubs. The trees around the houses are slender and tall, with a lush green canopy that provides shade to the area. The scene is captured from a high altitude, offering a bird's-eye view of the area. The houses and trees are clearly distinguishable, and the waste land appears as a large, empty space in the center of the image."
89
- text7 = "The neighborhood in the picture has streets arranged in a grid pattern with consistent, low-rise buildings. The buildings are mainly brown, red, and yellow, suggesting a blend of modern and traditional styles. The houses are surrounded by different kinds of greenery, such as small trees, bushes, and tall grasses."
90
- text8 = "The color remote sensing image shows a residential area from a bird's-eye view, revealing a mix of houses of different shapes and sizes spread throughout the area. The houses are painted in various colors, with some having white walls and red-tiled roofs, while others feature blue or green exteriors. The neighborhood includes several green spaces, such as small front yards, larger parks, and gardens with different types of trees and shrubs. A wide road runs through the center, linking different parts of the community. This road is lined with trees and has sidewalks for pedestrians. The image also shows other urban features like utility poles, streetlights, and a few commercial buildings on the edges of the residential area."
91
- text9 = "The image shows a barren and desolate landscape with little to no vegetation, dominated by a uniform color palette. The primary color is white, with some patches of gray and black. The terrain is mostly flat, with minimal changes in elevation. A white road is the only noticeable feature in the scene."
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
- # 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,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