fix attribute 接口新增类别隐射 不完全依赖模型推理产品类别,以映射文件为主

This commit is contained in:
zhouchengrong
2024-04-08 15:23:23 +08:00
parent fda602b6fe
commit 3960a19014
5 changed files with 749 additions and 151 deletions

View File

@@ -0,0 +1,242 @@
category_mapping = {
"ACCECSSORY/BAG": "bags",
"ACCECSSORY/HAT": "hats",
"ACCESSORY/ACCESSORY": "accessories",
"ACCESSORY/BAG": "bags",
"ACCESSORY/BELT": "accessories",
"ACCESSORY/BOOTS": "shoes",
"ACCESSORY/BANGLE": "accessories",
"ACCESSORY/COMBO SET": "accessories",
"ACCESSORY/BRACELET": "accessories",
"ACCESSORY/BRA TOP": "tops",
"ACCESSORY/BIB": "accessories",
"ACCESSORY/GIFT": "accessories",
"ACCESSORY/FESTIVAL SET": "accessories",
"ACCESSORY/CAPE": "outerwear",
"ACCESSORY/BLANKET": "accessories",
"ACCESSORY/HAIR BAND": "accessories",
"ACCESSORY/GLOVES": "accessories",
"ACCESSORY/FUR SCARF": "accessories",
"ACCESSORY/BROOCH": "accessories",
"ACCESSORY/HAT": "hats",
"ACCESSORY/HAIR CLIPS": "accessories",
"ACCESSORY/SCARF": "scarves",
"ACCESSORY/CLIP": "accessories",
"ACCESSORY/HEAD BAND": "accessories",
"ACCESSORY/NECKLACE": "jewellery",
"ACCESSORY/SOCKS": "accessories",
"ACCESSORY/EARING": "jewellery",
"ACCESSORY/KEYRING": "accessories",
"ACCESSORY/OTHERS": "accessories",
"ACCESSORY/TOY": "accessories",
"ACCESSORY/HAIR CLIP": "accessories",
"ACCESSORY/RING": "jewellery",
"ACCESSORY/SANDALS": "shoes",
"ACCESSORY/SUN GLASS": "sunglasses",
"ACCESSORY/MASK": "accessories",
"ACCESSORY/Test Kit": "accessories",
"ACCESSORY/MUG": "accessories",
"ACCESSORY/TOWEL": "accessories",
"ACCESSORY/SCARF TOP": "scarves",
"ACCESSORY/SHOES": "shoes",
"ACCESSORY/SWIMSUIT": "all-body",
"ACCESSORY/TIE": "accessories",
"BOTTOM/BOTTOM": "bottoms",
"BOTTOM/CAPRI": "bottoms",
"BOTTOM/": "bottoms",
"BOTTOM/COAT": "outerwear",
"BOTTOM/CARDIGAN": "outerwear",
"BOTTOM/JEANS SHORTS": "bottoms",
"BOTTOM/BOOTS": "shoes",
"BOTTOM/JEANS": "bottoms",
"BOTTOM/CARPI": "bottoms",
"BOTTOM/JUMPSUIT": "all-body",
"BOTTOM/JEANS SKIRT": "skirt",
"BOTTOM/JEANS CARPI": "bottoms",
"BOTTOM/JACKET": "outerwear",
"BOTTOM/LEATHER JACKET": "outerwear",
"BOTTOM/LEATHER PANTS": "bottoms",
"BOTTOM/JEANS PANTS": "bottoms",
"BOTTOM/PANTS": "bottoms",
"BOTTOM/LEATHER SHORTS": "bottoms",
"BOTTOM/LEATHER SKIRT": "skirt",
"BOTTOM/OVERALL": "all-body",
"BOTTOM/SHORTS": "bottoms",
"BOTTOM/LEGGING": "bottoms",
"BOTTOM/UNDERWEAR": "bottoms",
"BOTTOM/SKIRT": "skirt",
"BOTTOM/TUTA": "all-body",
"BOTTOM/SANDALS": "shoes",
"BOTTOM/TEE": "tops",
"BOTTOM/SHOES": "shoes",
"BOTTOM/SPORTSWEAR PANTS": "bottoms",
"BOTTON/PANTS": "bottoms",
"DRESS/JEANS JACKET": "outerwear",
"DRESS/": "all-body",
"DRESS/ONE PIECE": "all-body",
"DRESS/DRESS": "all-body",
"DRESS/LEATHER DRESS": "all-body",
"DRESS/JEANS SKIRT": "skirt",
"DRESS/OVERALL": "all-body",
"DRESS/EVENING DRESS": "all-body",
"DRESS/SKIRT": "skirt",
"DRESS/LEATHER SKIRT": "skirt",
"DRESS/JEANS DRESS": "all-body",
"DRESS/SHORTS": "bottoms",
"DRESS/JUMPSUIT": "all-body",
"DRESS/VEST": "tops",
"DRESS/SHIRT": "tops",
"DRESS/TUTA": "all-body",
"FUR/DOWN COAT": "outerwear",
"FUR/HAT": "hats",
"FUR/FUR CAPE": "outerwear",
"FUR/FUR COAT": "outerwear",
"FUR/FUR DOWN JACKET": "outerwear",
"FUR/FUR GILET": "outerwear",
"FUR/FUR CARDIGAN": "outerwear",
"FUR/FUR JACKET": "outerwear",
"FUR/FUR HAT": "hats",
"FUR/FUR SCARF": "accessories",
"FUR/FUR VEST": "outerwear",
"GIFT/GIFT": "accessories",
"GIFT/SCARF": "accessories",
"JEANS/GILET": "outerwear",
"JEANS/JEANS CARPI": "bottoms",
"JEANS/DRESS": "all-body",
"JEANS/JEANS BLOUSE": "tops",
"JEANS/JEANS": "bottoms",
"JEANS/JEANS OVERALL": "all-body",
"JEANS/JEANS BLAZER": "outerwear",
"JEANS/JEANS DRESS": "all-body",
"JEANS/SHIRT": "tops",
"JEANS/JEANS SHORTS": "bottoms",
"JEANS/JEANS GILET": "outerwear",
"JEANS/JEANS JACKET": "outerwear",
"JEANS/SKIRT": "skirt",
"JEANS/TWIN SET": "all-body",
"JEANS/JEANS PANTS": "bottoms",
"JEANS/JEANS SHIRT": "tops",
"JEANS/JEANS SKIRT": "skirt",
"JEANS/JEANS VEST": "outerwear",
"JEANS/JEANS TOP": "tops",
"JEANS/OVERALL": "all-body",
"JEANS/PANTS": "bottoms",
"JEANS/SHORTS": "bottoms",
"KNIT/CARDGAIN": "outerwear",
"KNIT/ONE PIECE": "all-body",
"KNIT/CARDIGAN": "outerwear",
"KNIT/BRA TOP": "tops",
"KNIT/JACKET": "outerwear",
"KNIT/PULLOVER": "tops",
"KNIT/DRESS": "all-body",
"KNIT/CAPE": "outerwear",
"KNIT/KNIT TOP": "tops",
"KNIT/CARDGIAN": "outerwear",
"KNIT/PANTS": "bottoms",
"KNIT/GILET": "outerwear",
"KNIT/LONG TOP": "tops",
"KNIT/SKIRT": "skirt",
"KNIT/SHORTS": "bottoms",
"KNIT/SWEATER": "tops",
"KNIT/SWEATPR": "tops",
"KNIT/VEST": "outerwear",
"KNIT/TANK": "tops",
"KNIT/TOP": "tops",
"KNIT/TUTA": "all-body",
"KNIT/TWIN SET": "all-body",
"LEATHER/BLAZER": "outerwear",
"LEATHER/LEATHER BLAZER": "outerwear",
"LEATHER/LEATHER COAT": "outerwear",
"LEATHER/LEATHER PANTS": "bottoms",
"LEATHER/HAT": "hats",
"LEATHER/LEATHER BLOUSE": "tops",
"LEATHER/LEATHER DRESS": "all-body",
"LEATHER/LEATHER SHORTS": "bottoms",
"LEATHER/LEATHER SKIRT": "skirt",
"LEATHER/LEATHER GILET": "outerwear",
"LEATHER/LEATHER JACKET": "outerwear",
"LEATHER/LEATHER VEST": "outerwear",
"LEATHER/LEATHERSKIRT": "skirt",
"LEATHER/LEATHERSHIRT": "tops",
"LEATHER/LEATHER TOP": "tops",
"ONE PIECE/BODYSUIT": "all-body",
"ONE PIECE/COMBO SET": "all-body",
"ONE PIECE/BODY": "all-body",
"ONE PIECE/JUMPSUIT": "all-body",
"ONE PIECE/DRESS": "all-body",
"ONE PIECE/OVERALL": "all-body",
"ONE PIECE/SWIMSUIT": "all-body",
"ONE PIECE/TWIN SET": "all-body",
"OUTERWEAR/CARDIGAN": "outerwear",
"OUTERWEAR/BLAZER": "outerwear",
"OUTERWEAR/DOWN COAT": "outerwear",
"OUTERWEAR/": "outerwear",
"OUTERWEAR/DOWN JACKET": "outerwear",
"OUTERWEAR/COAT": "outerwear",
"OUTERWEAR/DOWN GILET": "outerwear",
"OUTERWEAR/CAPE": "outerwear",
"OUTERWEAR/DOWN VEST": "outerwear",
"OUTERWEAR/FUR JACKET": "outerwear",
"OUTERWEAR/FUR VEST": "outerwear",
"OUTERWEAR/CAPE COAT": "outerwear",
"OUTERWEAR/LEATHER VEST": "outerwear",
"OUTERWEAR/PULLOVER": "outerwear",
"OUTERWEAR/GILET": "outerwear",
"OUTERWEAR/FUR COAT": "outerwear",
"OUTERWEAR/QUILTED JACKET": "outerwear",
"OUTERWEAR/SPORTSWEAR JACKET": "outerwear",
"OUTERWEAR/JACKET": "outerwear",
"OUTERWEAR/FUR GILET": "outerwear",
"OUTERWEAR/SHIRT": "tops",
"OUTERWEAR/TWIN SET": "all-body",
"OUTERWEAR/LEATHER GILET": "outerwear",
"OUTERWEAR/JEANS JACKET": "outerwear",
"OUTERWEAR/TRENCH COAT": "outerwear",
"OUTERWEAR/LEATHER COAT": "outerwear",
"OUTERWEAR/ONE PIECE": "all-body",
"OUTERWEAR/LEATHER JACKET": "outerwear",
"OUTERWEAR/SCARF": "accessories",
"OUTERWEAR/SOCKS": "accessories",
"OUTERWEAR/TOP": "tops",
"OUTERWEAR/UNIFORM": "outerwear",
"OUTERWEAR/VEST": "outerwear",
"OUTERWEAR/WINDBREAKER": "outerwear",
"OUTERWEAR/WINDERBREAKER": "outerwear",
"OUTPRWEAR/BLAZER": "outerwear",
"SHOES/PUMPS": "shoes",
"SHOES/BOOTS": "shoes",
"SHOES/SHOES": "shoes",
"SHOES/SANDALS": "shoes",
"TOP/BLOUSE": "tops",
"TOP/BLAZER": "outerwear",
"TOP/BAR TOP": "tops",
"TOP/BRA TOP": "tops",
"TOP/CARDIGAN": "outerwear",
"TOP/BODY": "all-body",
"TOP/COAT": "outerwear",
"TOP/PANTS": "bottoms",
"TOP/DOWN VEST": "outerwear",
"TOP/JACKET": "outerwear",
"TOP/GILET": "outerwear",
"TOP/TWIN SET": "tops",
"TOP/LONG SLEEVES TEE": "tops",
"TOP/LONG TOP": "tops",
"TOP/KNIT TOP": "tops",
"TOP/VEST": "tops",
"TOP/ONE PIECE": "all-body",
"TOP/TANK": "tops",
"TOP/PULLOVER": "outerwear",
"TOP/TOP": "tops",
"TOP/OVERALL": "all-body",
"TOP/UNDERWEAR": "bottoms",
"TOP/SKIRT": "skirt",
"TOP/UNIFORM": "tops",
"TOP/SHIRT": "tops",
"TOP/SWEATER": "tops",
"TOP/TUTA": "all-body",
"TOP/TEE": "tops",
"TOP/TUNIC": "tops",
"TUTA/OVERALL": "all-body",
"TUTA/TWIN SET": "all-body",
"TUTA/TUTA": "all-body"
}

View File

@@ -14,6 +14,7 @@ import pandas as pd
from minio import Minio
from app.core.config import MINIO_IP, MINIO_PORT, MINIO_SECURE, MINIO_ACCESS, MINIO_SECRET, ATT_TRITON_IP, ATT_TRITON_PORT
from app.service.attribute_recognition.config.category_mapping import category_mapping
def Merge(dict1, dict2):
@@ -92,22 +93,28 @@ class AttributeRecognition:
sample = self.preprocess(img_path)
category_model_path = args.category_model
category_description = args.category_discription
category_list = self.get_attribute(category_model_path, category_description, sample)['category']
# 如果category为all-body 则通过category获取类别 主要用去区分为连体裤和连衣裙
mapping_category = category_mapping[request_data.upload_img_category[l]]
if mapping_category not in ["tops", "bottoms", "skirt", "dress", "outerwear"]:
category_list = self.get_attribute(category_model_path, category_description, sample)['category']
else:
category_list = [mapping_category]
attr_dict = {}
if len(category_list) >= 1:
category = category_list[0]
print(category)
if category == 'top':
if category == 'tops':
attr_dict = {'Item': category}
for i in range(len(args.top_discription_list)):
# print('top: ', i)
attr_description = args.top_discription_list[i]
attr_model_path = args.top_model_list[i]
present_dict = self.get_attribute(attr_model_path, attr_description, sample)
attr_dict = Merge(attr_dict, present_dict)
elif category == 'pants':
elif category == 'bottoms':
attr_dict = {}
category = 'bottom'
attr_dict['Item'] = category
@@ -136,7 +143,7 @@ class AttributeRecognition:
present_dict = self.get_attribute(attr_model_path, attr_description, sample)
attr_dict = Merge(attr_dict, present_dict)
elif category == 'outwear':
elif category == 'outerwear':
attr_dict = {'Item': 'outer'}
for i in range(len(args.outwear_discription_list)):
@@ -152,8 +159,6 @@ class AttributeRecognition:
attr_model_path = args.jumpsuit_model_list[i]
present_dict = self.get_attribute(attr_model_path, attr_description, sample)
attr_dict = Merge(attr_dict, present_dict)
else:
attr_dict = {}
print('attr_dict: ', attr_dict)
final_dict[request_data.upload_img_id[l]] = attr_dict
@@ -210,6 +215,6 @@ class AttributeRecognition:
if __name__ == '__main__':
from app.service.attribute_recognition import const_debug
request_data = {'upload_img_path': ['./test_top1.jpg'], 'upload_img_id': ["2"]}
request_data = {'upload_img_path': ['./test_top1.jpg'], 'upload_img_id': ["2"], "update_img_category": ["TOP/ONE PIECE"]}
service = AttributeRecognition()
pprint(service.attribute(const_debug, request_data))