merge
This commit is contained in:
@@ -379,7 +379,6 @@ class OutfitMaterTypeAware(OutfitMatcher):
|
|||||||
Returns:
|
Returns:
|
||||||
scores: List of float
|
scores: List of float
|
||||||
"""
|
"""
|
||||||
<<<<<<< HEAD
|
|
||||||
outfit_images, outfit_categories = self.preprocess(outfits, features)
|
outfit_images, outfit_categories = self.preprocess(outfits, features)
|
||||||
scores = []
|
scores = []
|
||||||
for images, categories in zip(outfit_images, outfit_categories):
|
for images, categories in zip(outfit_images, outfit_categories):
|
||||||
@@ -400,28 +399,3 @@ class OutfitMaterTypeAware(OutfitMatcher):
|
|||||||
|
|
||||||
scores = np.stack(scores, axis=0)
|
scores = np.stack(scores, axis=0)
|
||||||
return scores.flatten()
|
return scores.flatten()
|
||||||
=======
|
|
||||||
image, category, mask = self.preprocess(outfits)
|
|
||||||
client = httpclient.InferenceServerClient(url=f"{OM_TRITON_IP}:{OM_TRITON_PORT}")
|
|
||||||
# 输入集
|
|
||||||
inputs = [
|
|
||||||
httpclient.InferInput("input__0", image.shape, datatype="FP32"),
|
|
||||||
httpclient.InferInput("input__1", category.shape, datatype="INT16"),
|
|
||||||
httpclient.InferInput("input__2", mask.shape, datatype="FP32"),
|
|
||||||
]
|
|
||||||
inputs[0].set_data_from_numpy(image.astype(np.float32), binary_data=True)
|
|
||||||
inputs[1].set_data_from_numpy(category.astype(np.int16), binary_data=True)
|
|
||||||
inputs[2].set_data_from_numpy(mask.astype(np.float32), binary_data=True)
|
|
||||||
# 输出集
|
|
||||||
outputs = [
|
|
||||||
httpclient.InferRequestedOutput("output__0", binary_data=True),
|
|
||||||
httpclient.InferRequestedOutput("output__1", binary_data=True)
|
|
||||||
]
|
|
||||||
results = client.infer(model_name="outfit_matcher_type_aware", inputs=inputs, outputs=outputs)
|
|
||||||
# 推理
|
|
||||||
# 取结果
|
|
||||||
scores = torch.from_numpy(results.as_numpy("output__0")) # Shape (N, 1)
|
|
||||||
features = torch.from_numpy(results.as_numpy("output__1")) # Shape (N, 64)
|
|
||||||
|
|
||||||
return scores, features
|
|
||||||
>>>>>>> 1f23781b16e59bfbcbbb4d252e6a61685267e6c7
|
|
||||||
|
|||||||
@@ -18,38 +18,43 @@ if __name__ == '__main__':
|
|||||||
all_items = param["query"] + param["database"]
|
all_items = param["query"] + param["database"]
|
||||||
unextracted_item = []
|
unextracted_item = []
|
||||||
prepared_feature = {}
|
prepared_feature = {}
|
||||||
|
|
||||||
|
# 拿到所有需要提取特征的图片
|
||||||
for item in all_items:
|
for item in all_items:
|
||||||
if f'{item["item_name"]}.npy' not in os.listdir("feature"):
|
if f'{item["item_name"]}.npy' not in os.listdir("feature"):
|
||||||
unextracted_item.append(item)
|
unextracted_item.append(item)
|
||||||
if len(unextracted_item) > 0:
|
if len(unextracted_item) > 0:
|
||||||
|
# 通过backbone模型提取图片特征
|
||||||
extracted_features = backbone_service.get_result(unextracted_item)
|
extracted_features = backbone_service.get_result(unextracted_item)
|
||||||
for i, item in enumerate(unextracted_item):
|
for i, item in enumerate(unextracted_item):
|
||||||
np.save(f'feature/{item["item_name"]}.npy', extracted_features[i])
|
|
||||||
for item in all_items:
|
|
||||||
if item["item_name"] not in prepared_feature.keys():
|
|
||||||
prepared_feature[item["item_name"]] = np.load(f'feature/{item["item_name"]}.npy')
|
|
||||||
for item in tqdm(param["query"] * 10):
|
|
||||||
outfits = fashion_dataset.generate_outfit(item, param["topk"], param["max_outfits"])
|
|
||||||
<<<<<<< HEAD
|
|
||||||
scores = service.get_result(outfits, prepared_feature)
|
|
||||||
=======
|
|
||||||
scores, features = service.get_result(outfits)
|
|
||||||
# save features
|
# save features
|
||||||
|
|
||||||
# 链接milvus
|
# 链接milvus
|
||||||
|
# TODO
|
||||||
|
np.save(f'feature/{item["item_name"]}.npy', extracted_features[i])
|
||||||
# 存入数据库
|
# 存入数据库
|
||||||
# 关闭链接
|
# 关闭链接
|
||||||
|
|
||||||
>>>>>>> 1f23781b16e59bfbcbbb4d252e6a61685267e6c7
|
# TODO 读取本次任务需要的图片特征
|
||||||
# print(scores)
|
for item in all_items:
|
||||||
# print(len(scores))
|
if item["item_name"] not in prepared_feature.keys():
|
||||||
|
prepared_feature[item["item_name"]] = np.load(f'feature/{item["item_name"]}.npy')
|
||||||
|
|
||||||
|
# 开始服装搭配任务
|
||||||
|
for item in tqdm(param["query"] * 10):
|
||||||
|
# 根据一定规则生成outfit
|
||||||
|
outfits = fashion_dataset.generate_outfit(item, param["topk"], param["max_outfits"])
|
||||||
|
# 根据模型对生成的outfit打分
|
||||||
|
scores = service.get_result(outfits, prepared_feature)
|
||||||
|
# 对评分排序,拿到最好的topk个outfit输出
|
||||||
|
sorted_indices = np.argsort(scores)[:param["topk"]] # type-aware
|
||||||
|
outfits = [outfits[i] for i in sorted_indices] # 最好的五个
|
||||||
|
|
||||||
|
# 结果可视化
|
||||||
# service.visualize(outfits, scores, param["topk"], best=True,
|
# service.visualize(outfits, scores, param["topk"], best=True,
|
||||||
# output_path=os.path.join(r"D:\PhD_Study\MIXI\mitu\image\123",
|
# output_path=os.path.join(r"D:\PhD_Study\MIXI\mitu\image\123",
|
||||||
# f"{item['item_name']}_best_{param['topk']}.png"))
|
# f"{item['item_name']}_best_{param['topk']}.png"))
|
||||||
# service.visualize(outfits, scores, param["topk"], best=False,
|
# service.visualize(outfits, scores, param["topk"], best=False,
|
||||||
# output_path=os.path.join(r"D:\PhD_Study\MIXI\mitu\image\123",
|
# output_path=os.path.join(r"D:\PhD_Study\MIXI\mitu\image\123",
|
||||||
# f"{item['item_name']}_worst_{param['topk']}.png"))
|
# f"{item['item_name']}_worst_{param['topk']}.png"))
|
||||||
sorted_indices = np.argsort(scores)[:param["topk"]] # type-aware
|
|
||||||
outfits = [outfits[i] for i in sorted_indices] # 最好的五个
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user