d2353a6a5fd9031f - những game nổ hũ uy tín
Lần trước, chúng ta đã thử sử dụng towhee
và milvus
để chuyển đổi các bức ảnh thành vector. Tiếp nối ý tưởng đó, chúng ta có thể xây dựng một phiên bản cơ bản của hệ thống tìm kiếm hình ảnh qua hình ảnh.
Đầu tiên, chúng ta cần chuẩn những game nổ hũ uy tín bị một số hình ảnh để làm dữ liệu:
1from towhee import AutoPipes, AutoConfig, ops
2import towhee
3import os
4from pymilvus import MilvusClient
5import json
6
7# 1. Khởi tạo client Milvus
8client = MilvusClient(
9 uri="http://localhost:19530"
10)
11
12# Tải cấu hình cho việc chèn vào Milvus
13insert_conf = AutoConfig.load_config('insert_milvus')
14insert_conf.collection_name = 'text_image_search'
15insert_pipe = AutoPipes.pipeline('insert_milvus', insert_conf)
16
17# Tạo pipeline nhúng hình ảnh
18image_embedding_pipe = AutoPipes.pipeline('image-embedding')
19
20# Lấy danh sách các file trong thư mục ./images
21files = os.listdir("./images")
22
23for file in files:
24 file_path = os.path.join("./images", file)
25 if os.path.isfile(file_path):
26 embedding = image_embedding_pipe(file_path).get()[0]
27 insert_pipe([file_path, embedding])