update config
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
import tritonclient.http as httpclient
|
||||
@@ -5,14 +8,17 @@ import requests
|
||||
import cv2
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
from tqdm import tqdm
|
||||
|
||||
from app.service.outfit_matcher.dataset import FashionDataset
|
||||
from app.service.outfit_matcher.foco import extract_main_colors
|
||||
from app.service.outfit_matcher.outfit_evaluator import evaluate_outfits, visualize
|
||||
|
||||
|
||||
class OutfitMatcherHon:
|
||||
def __init__(self, outfits):
|
||||
self.outfits = outfits
|
||||
self.tritonclient = httpclient.InferenceServerClient(url="localhost:8000")
|
||||
self.tritonclient = httpclient.InferenceServerClient(url="10.1.1.240:10010")
|
||||
|
||||
@staticmethod
|
||||
def imnormalize(img, mean, std, to_rgb=True):
|
||||
@@ -91,7 +97,7 @@ class OutfitMatcherHon:
|
||||
for outfit in self.outfits:
|
||||
images = []
|
||||
colors = []
|
||||
for item in outfit["items"]:
|
||||
for item in outfit:
|
||||
image = self.load_image(item["image_path"])
|
||||
image = self.resize_image(image)
|
||||
normalized_image = self.imnormalize(image,
|
||||
@@ -108,7 +114,7 @@ class OutfitMatcherHon:
|
||||
outfit_colors, _ = self.pad_array(outfit_colors)
|
||||
return outfit_images, outfit_colors, mask
|
||||
|
||||
def get_result(self, outfits):
|
||||
def get_result(self):
|
||||
# start = time.time()
|
||||
image, color, mask = self.preprocess()
|
||||
# print(start - time.time())
|
||||
@@ -126,8 +132,29 @@ class OutfitMatcherHon:
|
||||
outputs = [
|
||||
httpclient.InferRequestedOutput("output__0", binary_data=True),
|
||||
]
|
||||
results = self.tritonclient.infer(model_name="outfit_matcher", inputs=inputs, outputs=outputs)
|
||||
results = self.tritonclient.infer(model_name="outfit_matcher_hon", inputs=inputs, outputs=outputs)
|
||||
# 推理
|
||||
# 取结果
|
||||
inference_output1 = torch.from_numpy(results.as_numpy("output__0"))
|
||||
return inference_output1 # Shape (N, 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
with open("./test_param/recommendation_test.json", "r") as f:
|
||||
param = json.load(f)
|
||||
fashion_dataset = FashionDataset(param["database"])
|
||||
for item in tqdm(param["query"]):
|
||||
outfits = fashion_dataset.generate_outfit(item, param["topk"], param["max_outfits"])
|
||||
service = OutfitMatcherHon(outfits=outfits)
|
||||
scores = service.get_result()
|
||||
visualize(outfits, scores, param["topk"], best=True,
|
||||
output_path=os.path.join(
|
||||
r"E:\workspace\outfit_matcher\2024 SS Outfit",
|
||||
f"{item['item_name']}_best_{param['topk']}.png"
|
||||
))
|
||||
visualize(outfits, scores, param["topk"], best=False,
|
||||
output_path=os.path.join(
|
||||
r"E:\workspace\outfit_matcher\2024 SS Outfit",
|
||||
f"{item['item_name']}_worst_{param['topk']}.png"
|
||||
))
|
||||
a = 1
|
||||
|
||||
Reference in New Issue
Block a user