关于保存特征的一些代码
This commit is contained in:
5
test/outfit_matcher_milvus/1.create databases.py
Normal file
5
test/outfit_matcher_milvus/1.create databases.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from pymilvus import connections, db
|
||||
|
||||
conn = connections.connect(host="10.1.1.240", port=19530)
|
||||
|
||||
database = db.create_database("mixi")
|
||||
23
test/outfit_matcher_milvus/2.create collection.py
Normal file
23
test/outfit_matcher_milvus/2.create collection.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from pymilvus import MilvusClient, DataType
|
||||
|
||||
# 创建client ,配置databases
|
||||
client = MilvusClient(
|
||||
uri="http://10.1.1.240:19530",
|
||||
token="root:Milvus",
|
||||
db_name="mixi"
|
||||
)
|
||||
from pymilvus import MilvusClient, DataType
|
||||
|
||||
schema = MilvusClient.create_schema(
|
||||
auto_id=True,
|
||||
enable_dynamic_field=False,
|
||||
)
|
||||
|
||||
schema.add_field(field_name="id", datatype=DataType.INT64, is_primary=True)
|
||||
schema.add_field(field_name="image_path", datatype=DataType.VARCHAR, max_length=200)
|
||||
schema.add_field(field_name="vector", datatype=DataType.FLOAT_VECTOR, dim=64)
|
||||
|
||||
client.create_collection(
|
||||
collection_name="mixi_outfit",
|
||||
schema=schema
|
||||
)
|
||||
23
test/outfit_matcher_milvus/3.create index.py
Normal file
23
test/outfit_matcher_milvus/3.create index.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from pymilvus import MilvusClient, Collection
|
||||
|
||||
client = MilvusClient(
|
||||
uri="http://10.1.1.240:19530",
|
||||
token="root:Milvus",
|
||||
db_name="mixi"
|
||||
)
|
||||
|
||||
index_params = client.prepare_index_params()
|
||||
index_params.add_index(
|
||||
field_name="id",
|
||||
index_type="STL_SORT"
|
||||
)
|
||||
index_params.add_index(
|
||||
field_name="vector",
|
||||
index_type="IVF_FLAT",
|
||||
metric_type="L2",
|
||||
params={"nlist": 1024}
|
||||
)
|
||||
client.create_index(
|
||||
collection_name="mixi_outfit",
|
||||
index_params=index_params
|
||||
)
|
||||
10
test/outfit_matcher_milvus/4.load clollection.py
Normal file
10
test/outfit_matcher_milvus/4.load clollection.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from pymilvus import MilvusClient
|
||||
|
||||
client = MilvusClient(
|
||||
uri="http://10.1.1.240:19530",
|
||||
token="root:Milvus",
|
||||
db_name="mixi"
|
||||
)
|
||||
client.load_collection(
|
||||
collection_name="mixi_outfit"
|
||||
)
|
||||
27
test/outfit_matcher_milvus/5.similar match.py
Normal file
27
test/outfit_matcher_milvus/5.similar match.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import json
|
||||
import time
|
||||
|
||||
from pymilvus import MilvusClient
|
||||
|
||||
client = MilvusClient(
|
||||
uri="http://10.1.1.240:19530",
|
||||
token="root:Milvus",
|
||||
db_name="mixi"
|
||||
)
|
||||
data = [0.019687360152602196, 0.839404821395874, 0.5053166747093201, 0.6062483787536621, 0.5455009341239929, 0.07595491409301758, 0.028354600071907043, 0.24453534185886383, 0.6116685271263123, 0.4527449309825897, 0.22063420712947845, 0.09205381572246552, 0.22853578627109528, 0.3041312098503113,
|
||||
0.8354143500328064, 0.05135197564959526, 0.9292615652084351, 0.03914223983883858, 0.7091595530509949, 0.17939062416553497, 0.2958671748638153, 0.46751415729522705, 0.05523946136236191, 0.976833164691925, 0.3593502938747406, 0.0806853398680687, 0.3097323179244995, 0.12855321168899536,
|
||||
0.12651172280311584, 0.3173355162143707, 0.17060844600200653, 0.9340737462043762, 0.8437095880508423, 0.7500482797622681, 0.22598184645175934, 0.8127533197402954, 0.39825528860092163, 0.9043431878089905, 0.9064653515815735, 0.14613617956638336, 0.582768976688385, 0.4516744315624237,
|
||||
0.6479957699775696, 0.909612774848938, 0.7674093842506409, 0.47747865319252014, 0.5617552995681763, 0.967750072479248, 0.9146659970283508, 0.28031912446022034, 0.5092940330505371, 0.21442186832427979, 0.43696293234825134, 0.7705745100975037, 0.09395607560873032, 0.9103220701217651,
|
||||
0.2616001069545746, 0.7469480037689209, 0.24508604407310486, 0.6890515089035034, 0.704613447189331, 0.7213652729988098, 0.3660031855106354, 0.2150406688451767]
|
||||
start_time = time.time()
|
||||
res = client.search(
|
||||
collection_name="mixi_outfit", # Replace with the actual name of your collection
|
||||
# Replace with your query vector
|
||||
data=[data],
|
||||
limit=5, # Max. number of search results to return
|
||||
# search_params={"metric_type": "IP", "params": {}} # Search parameters
|
||||
)
|
||||
print(time.time() - start_time)
|
||||
|
||||
result = json.dumps(res, indent=4)
|
||||
print(result)
|
||||
Reference in New Issue
Block a user