File size: 631 Bytes
ab9b7a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from utils.setup import load_collection
from utils.get_embeddings import preprocess_image, extract_features, create_resnet18_model

search_params = {
    "metric_type": "L2",
    "params": {"level": 2}
}

collection = load_collection()
model = create_resnet18_model()

def search_images(image_path, topk=6):
    processed_image = preprocess_image(image_path)
    processed_image = extract_features(model, processed_image)
    results = collection.search(
        [processed_image],
        anns_field="image_embedding",
        param=search_params,
        limit=topk,
        guarantee_timestamp=1
    )
    
    return results[0]