fix 代码整理
This commit is contained in:
@@ -29,41 +29,41 @@ def outfit_matcher(request_item: OutfitMatcher):
|
|||||||
service = OutfitMaterTypeAware()
|
service = OutfitMaterTypeAware()
|
||||||
all_items = request_item["query"] + request_item["database"]
|
all_items = request_item["query"] + request_item["database"]
|
||||||
prepared_feature = {}
|
prepared_feature = {}
|
||||||
|
have_features_data = []
|
||||||
|
no_have_features_data = []
|
||||||
|
temp_data = deepcopy(all_items)
|
||||||
|
|
||||||
# 连接milvus
|
# 连接milvus
|
||||||
client = MilvusClient(uri=MILVUS_URL, token="root:Milvus", db_name="mixi")
|
client = MilvusClient(uri=MILVUS_URL, token="root:Milvus", db_name="mixi")
|
||||||
search_data = client.get(collection_name='mixi_outfit', ids=[item['item_name'] for item in all_items])
|
try:
|
||||||
|
search_data = client.get(collection_name='mixi_outfit', ids=[item['item_name'] for item in all_items])
|
||||||
|
# 查询数据库,分成两批 需要过模型推理的和不需要的
|
||||||
|
for td in temp_data:
|
||||||
|
for sd in search_data:
|
||||||
|
if td['item_name'] == sd['item_name']:
|
||||||
|
td['features'] = sd['features']
|
||||||
|
if "features" not in td.keys():
|
||||||
|
no_have_features_data.append(td)
|
||||||
|
else:
|
||||||
|
have_features_data.append(td)
|
||||||
|
|
||||||
# 查询数据库,分成两批 需要过模型推理的和不需要的
|
if len(no_have_features_data) > 0:
|
||||||
have_features_data = []
|
extracted_features = backbone_service.get_result(no_have_features_data)
|
||||||
no_have_features_data = []
|
|
||||||
|
|
||||||
temp_data = deepcopy(all_items)
|
# 准备数据
|
||||||
for td in temp_data:
|
data = deepcopy(no_have_features_data) # 做深拷贝 , all_items 是list 可变数组
|
||||||
for sd in search_data:
|
for i, feature in enumerate(extracted_features):
|
||||||
if td['item_name'] == sd['item_name']:
|
data[i]['features'] = feature
|
||||||
td['features'] = sd['features']
|
if 'mapped_cate' in data[i].keys():
|
||||||
if "features" not in td.keys():
|
del data[i]['mapped_cate']
|
||||||
no_have_features_data.append(td)
|
|
||||||
else:
|
|
||||||
have_features_data.append(td)
|
|
||||||
|
|
||||||
if len(no_have_features_data) > 0:
|
# 存入数据
|
||||||
extracted_features = backbone_service.get_result(no_have_features_data)
|
res = client.insert(collection_name="mixi_outfit", data=data)
|
||||||
|
# 断开连接
|
||||||
# 准备数据
|
for d in data:
|
||||||
data = deepcopy(no_have_features_data) # 做深拷贝 , all_items 是list 可变数组
|
prepared_feature[d['item_name']] = d['features']
|
||||||
for i, feature in enumerate(extracted_features):
|
finally:
|
||||||
data[i]['features'] = feature
|
|
||||||
if 'mapped_cate' in data[i].keys():
|
|
||||||
del data[i]['mapped_cate']
|
|
||||||
|
|
||||||
# 存入数据
|
|
||||||
res = client.insert(collection_name="mixi_outfit", data=data)
|
|
||||||
# 断开连接
|
|
||||||
client.close()
|
client.close()
|
||||||
for d in data:
|
|
||||||
prepared_feature[d['item_name']] = d['features']
|
|
||||||
|
|
||||||
for hfd in have_features_data:
|
for hfd in have_features_data:
|
||||||
prepared_feature[hfd['item_name']] = hfd['features']
|
prepared_feature[hfd['item_name']] = hfd['features']
|
||||||
|
|||||||
@@ -86,7 +86,6 @@ class SimilarMatch:
|
|||||||
|
|
||||||
@RunTime
|
@RunTime
|
||||||
def match_features(self):
|
def match_features(self):
|
||||||
# 连接milvus
|
|
||||||
# 连接milvus
|
# 连接milvus
|
||||||
client = MilvusClient(uri=MILVUS_URL, db_name="mixi")
|
client = MilvusClient(uri=MILVUS_URL, db_name="mixi")
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user