搭配服务修改

This commit is contained in:
zhouchengrong
2024-03-28 17:22:51 +08:00
parent 39dae92ea0
commit eb9351dc87
5 changed files with 117 additions and 79 deletions

View File

@@ -197,43 +197,45 @@ class OutfitMatcher(object):
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 # 一个是图片,一个是分数
return outfits, scores.tolist()
# 创建一个新的图像,并指定子图的行列数
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:.4f}", fontsize=12)
axes[i, 0].axis("off")
# 显示图片
for j, item in enumerate(outfit):
img = self.load_image(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()
# # 设置子图的行列数
# 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:.4f}", fontsize=12)
# axes[i, 0].axis("off")
# # 显示图片
# for j, item in enumerate(outfit):
# img = self.load_image(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()
class OutfitMatcherHon(OutfitMatcher):