update config
This commit is contained in:
@@ -6,6 +6,7 @@ import cv2
|
||||
import numpy as np
|
||||
import tritonclient.http as httpclient
|
||||
import torch
|
||||
from matplotlib import pyplot as plt, image as mpimg
|
||||
|
||||
from foco import extract_main_colors
|
||||
|
||||
@@ -178,6 +179,51 @@ def evaluate_outfits(outfits):
|
||||
return scores # Shape (N, 1)
|
||||
|
||||
|
||||
def visualize(outfits, scores, topk=5, best=True, output_path=None):
|
||||
# 将outfits和scores按照scores的值进行排序
|
||||
sorted_indices = np.argsort(-scores.flatten() if best else scores.flatten())[:topk] # 使用负号进行降序排序
|
||||
outfits = [outfits[i] for i in sorted_indices]
|
||||
scores = scores[sorted_indices]
|
||||
|
||||
# 设置子图的行列数
|
||||
num_rows = len(outfits)
|
||||
num_cols = max([len(x) for x in outfits]) + 1 # 一个是图片,一个是分数
|
||||
|
||||
# 创建一个新的图像,并指定子图的行列数
|
||||
fig, axes = plt.subplots(num_rows, num_cols, figsize=(8, 15))
|
||||
|
||||
title = f"Best {topk} Outfits" if best else f"Worst {topk} Outfits"
|
||||
fig.suptitle(title, fontsize=16)
|
||||
|
||||
# 遍历每套outfit并将其显示在对应的子图中
|
||||
for i, (outfit, score) in enumerate(zip(outfits, scores)):
|
||||
# 显示分数
|
||||
axes[i, 0].text(0.1, 0.5, f"Score: {score[0]:.4f}", fontsize=12)
|
||||
axes[i, 0].axis("off")
|
||||
# 显示图片
|
||||
for j, item in enumerate(outfit):
|
||||
img = mpimg.imread(item['image_path']) # 读取图片
|
||||
axes[i, j + 1].imshow(img) # 在对应的子图中显示图片
|
||||
axes[i, j + 1].axis('off') # 关闭坐标轴
|
||||
axes[i, j + 1].set_title(item["semantic_category"], fontsize=10)
|
||||
for j in range(len(outfit), num_cols):
|
||||
axes[i, j].axis("off")
|
||||
|
||||
# 在每一行的底部添加一条横线
|
||||
axes[i, 0].axhline(y=0, color='black', linewidth=1)
|
||||
# 隐藏最后一行的横线
|
||||
axes[-1, 0].axhline(y=0, color='white', linewidth=1)
|
||||
|
||||
# 调整布局
|
||||
plt.subplots_adjust(wspace=0.1, hspace=0.1)
|
||||
plt.tight_layout()
|
||||
|
||||
if output_path:
|
||||
plt.savefig(output_path)
|
||||
else:
|
||||
plt.show()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
with open("test_input.json", "r") as f:
|
||||
outfits = json.load(f)
|
||||
|
||||
Reference in New Issue
Block a user