Merge remote-tracking branch 'origin/develop'

# Conflicts:
#	app/api/api_attribute.py
#	app/core/config.py
#	app/service/outfit_matcher/outfit_evaluator.py
#	app/service/outfit_matcher/service.py
This commit is contained in:
zhouchengrong
2024-04-03 14:59:24 +08:00
36 changed files with 248 additions and 230 deletions

View File

@@ -21,6 +21,7 @@ class Backbone(object):
access_key=MINIO_ACCESS,
secret_key=MINIO_SECRET,
secure=MINIO_SECURE)
@RunTime
# TODO 用多线程读图片
def load_image(self, img_path):
@@ -38,6 +39,7 @@ class Backbone(object):
except Exception as e:
print(f"An error occurred: {e}")
return None
@staticmethod
def resize_image(img):
"""
@@ -195,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):

View File

@@ -49,11 +49,9 @@ if __name__ == '__main__':
best_outfits = [outfits[i] for i in sorted_indices] # 最好的五个
# 结果可视化
service.visualize(outfits, scores, param["topk"], best=True,
output_path=os.path.join(r"D:\PhD_Study\MIXI\mitu\image\123",
f"{item['item_name']}_best_{param['topk']}.png"))
service.visualize(outfits, scores, param["topk"], best=False,
output_path=os.path.join(r"D:\PhD_Study\MIXI\mitu\image\123",
f"{item['item_name']}_worst_{param['topk']}.png"))
# service.visualize(outfits, scores, param["topk"], best=True,
# output_path=os.path.join(r"D:\PhD_Study\MIXI\mitu\image\123",
# f"{item['item_name']}_best_{param['topk']}.png"))
# service.visualize(outfits, scores, param["topk"], best=False,
# output_path=os.path.join(r"D:\PhD_Study\MIXI\mitu\image\123",
# f"{item['item_name']}_worst_{param['topk']}.png"))