feat(新功能):

fix(修复bug):   accessories 替换为 others
docs(文档变更):
refactor(重构):
test(增加测试):
This commit is contained in:
zchengrong
2025-11-07 10:56:34 +08:00
parent 7d2149dcaf
commit e8d8b715ae
15 changed files with 36 additions and 36 deletions

View File

@@ -5,7 +5,7 @@ from .top import Top, Blouse, Outwear, Dress
from .bottom import Bottom, Trousers, Skirt
from .shoes import Shoes
from .bag import Bag
from .accessories import Hairstyle, Earring
from .others import Hairstyle, Earring
__all__ = [
'ITEMS', 'build_item',

View File

@@ -5,9 +5,9 @@ from celery import Celery
from minio import Minio
from app.core.config import *
from app.service.design_batch.item import BodyItem, TopItem, BottomItem, AccessoriesItem
from app.service.design_batch.item import BodyItem, TopItem, BottomItem, OthersItem
from app.service.design_batch.utils.MQ import publish_status
from app.service.design_batch.utils.organize import organize_body, organize_clothing, organize_accessories
from app.service.design_batch.utils.organize import organize_body, organize_clothing, organize_others
from app.service.design_batch.utils.save_json import oss_upload_json
from app.service.design_batch.utils.synthesis_item import update_base_size_priority, synthesis, synthesis_single
@@ -33,8 +33,8 @@ def process_item(item, basic):
elif item['type'].lower() in ['skirt', 'trousers', 'bottoms']:
bottom_server = BottomItem(data=item, basic=basic, minio_client=minio_client)
item_data = bottom_server.process()
elif item['type'].lower() in ['accessories']:
bottom_server = AccessoriesItem(data=item, basic=basic, minio_client=minio_client)
elif item['type'].lower() in ['others']:
bottom_server = OthersItem(data=item, basic=basic, minio_client=minio_client)
item_data = bottom_server.process()
else:
raise NotImplementedError(f"Item type {item['type']} not implemented")
@@ -47,8 +47,8 @@ def process_layer(item, layers):
body_layer = organize_body(item)
layers.append(body_layer)
return item['body_image'].size
elif item['name'] == 'accessories':
front_layer, back_layer = organize_accessories(item)
elif item['name'] == 'others':
front_layer, back_layer = organize_others(item)
layers.append(front_layer)
layers.append(back_layer)
else:

View File

@@ -9,10 +9,10 @@ class BaseItem:
self.result.update(basic)
class AccessoriesItem(BaseItem):
class OthersItem(BaseItem):
def __init__(self, data, basic, minio_client):
super().__init__(data, basic)
self.Accessories_pipeline = [
self.Others_pipeline = [
LoadImage(minio_client),
# KeyPoint(),
ContourDetection(),
@@ -25,7 +25,7 @@ class AccessoriesItem(BaseItem):
]
def process(self):
for item in self.Accessories_pipeline:
for item in self.Others_pipeline:
self.result = item(self.result)
return self.result

View File

@@ -74,8 +74,8 @@ class LoadImage:
keypoint = 'head_point'
elif name == 'earring':
keypoint = 'ear_point'
elif name == 'accessories':
keypoint = "accessories"
elif name == 'others':
keypoint = "others"
else:
raise KeyError(f"{name} does not belong to item category list: blouse, outwear, dress, trousers, skirt, "
f"bag, shoes, hairstyle, earring.")

View File

@@ -46,7 +46,7 @@ class Scaling:
result['scale'] = result['scale_bag']
elif result['keypoint'] == 'ear_point':
result['scale'] = result['scale_earrings']
elif result['keypoint'] == 'accessories':
elif result['keypoint'] == 'others':
# 由于没有识别配饰keypoint的模型 所以统一将配饰的两个关键点设定为 (0,0) (0,img.width)
# 模特的关键点设定为(0,0) (0,320/2) 距离比例简写为 160 / img.width
distance_clo = result['img_shape'][1]

View File

@@ -21,7 +21,7 @@ class Split(object):
def __call__(self, result):
try:
if result['name'] in ('outwear', 'dress', 'blouse', 'skirt', 'trousers', 'tops', 'bottoms', 'accessories'):
if result['name'] in ('outwear', 'dress', 'blouse', 'skirt', 'trousers', 'tops', 'bottoms', 'others'):
if result['resize_scale'][0] == 1.0 and result['resize_scale'][1] == 1.0:
front_mask = result['front_mask']

View File

@@ -55,7 +55,7 @@ def organize_clothing(layer):
return front_layer, back_layer
def organize_accessories(layer):
def organize_others(layer):
# 起始坐标
start_point = (0, 0)
# 前片数据

View File

@@ -6,8 +6,8 @@ import requests
from minio import Minio
from app.core.config import *
from app.service.design_fast.item import BodyItem, TopItem, BottomItem, AccessoriesItem
from app.service.design_fast.utils.organize import organize_body, organize_clothing, organize_accessories
from app.service.design_fast.item import BodyItem, TopItem, BottomItem, OthersItem
from app.service.design_fast.utils.organize import organize_body, organize_clothing, organize_others
from app.service.design_fast.utils.progress import final_progress, update_progress
from app.service.design_fast.utils.synthesis_item import synthesis, synthesis_single, update_base_size_priority
from app.service.utils.decorator import RunTime
@@ -30,8 +30,8 @@ def process_item(item, basic):
elif item['type'].lower() in ['skirt', 'trousers', 'bottoms']:
bottom_server = BottomItem(data=item, basic=basic, minio_client=minio_client)
item_data = bottom_server.process()
elif item['type'].lower() in ['accessories']:
bottom_server = AccessoriesItem(data=item, basic=basic, minio_client=minio_client)
elif item['type'].lower() in ['others']:
bottom_server = OthersItem(data=item, basic=basic, minio_client=minio_client)
item_data = bottom_server.process()
else:
raise NotImplementedError(f"Item type {item['type']} not implemented")
@@ -44,8 +44,8 @@ def process_layer(item, layers):
body_layer = organize_body(item)
layers.append(body_layer)
return item['body_image'].size
elif item['name'] == 'accessories':
front_layer, back_layer = organize_accessories(item)
elif item['name'] == 'others':
front_layer, back_layer = organize_others(item)
layers.append(front_layer)
layers.append(back_layer)
else:

View File

@@ -9,10 +9,10 @@ class BaseItem:
self.result.update(basic)
class AccessoriesItem(BaseItem):
class OthersItem(BaseItem):
def __init__(self, data, basic, minio_client):
super().__init__(data, basic)
self.Accessories_pipeline = [
self.Others_pipeline = [
LoadImage(minio_client),
# KeyPoint(),
# ContourDetection(),
@@ -26,7 +26,7 @@ class AccessoriesItem(BaseItem):
]
def process(self):
for item in self.Accessories_pipeline:
for item in self.Others_pipeline:
self.result = item(self.result)
return self.result

View File

@@ -105,8 +105,8 @@ class LoadImage:
keypoint = 'head_point'
elif name == 'earring':
keypoint = 'ear_point'
elif name == 'accessories':
keypoint = "accessories"
elif name == 'others':
keypoint = "others"
else:
raise KeyError(f"{name} does not belong to item category list: blouse, outwear, dress, trousers, skirt, "
f"bag, shoes, hairstyle, earring.")

View File

@@ -46,7 +46,7 @@ class Scaling:
result['scale'] = result['scale_bag']
elif result['keypoint'] == 'ear_point':
result['scale'] = result['scale_earrings']
elif result['keypoint'] == 'accessories':
elif result['keypoint'] == 'others':
# 由于没有识别配饰keypoint的模型 所以统一将配饰的两个关键点设定为 (0,0) (0,img.width)
# 模特的关键点设定为(0,0) (0,320/2) 距离比例简写为 160 / img.width
distance_clo = result['img_shape'][1]

View File

@@ -20,7 +20,7 @@ class Split(object):
def __call__(self, result):
try:
if result['name'] in ('outwear', 'dress', 'blouse', 'skirt', 'trousers', 'tops', 'bottoms', 'accessories'):
if result['name'] in ('outwear', 'dress', 'blouse', 'skirt', 'trousers', 'tops', 'bottoms', 'others'):
ori_front_mask = result['front_mask'].copy()
ori_back_mask = result['back_mask'].copy()

View File

@@ -58,14 +58,14 @@ def organize_clothing(layer):
return front_layer, back_layer
def organize_accessories(layer):
def organize_others(layer):
# 起始坐标
start_point = (0, 0)
layer['clothes_keypoint'] = {
'accessories_left': [0, 0]
'others_left': [0, 0]
}
layer['body_point_test'] = {
'accessories_left': [0, 0]
'others_left': [0, 0]
}
start_point = calculate_start_point(layer['keypoint'], layer['scale'], layer['clothes_keypoint'], layer['body_point_test'], layer["offset"], layer["resize_scale"])

View File

@@ -79,11 +79,11 @@ def synthesis(data, size, basic_info):
_, binary_body_mask = cv2.threshold(body_mask, 127, 255, cv2.THRESH_BINARY)
top_outer_mask = np.array(binary_body_mask)
bottom_outer_mask = np.array(binary_body_mask)
accessories_outer_mask = np.array(binary_body_mask)
others_outer_mask = np.array(binary_body_mask)
top = True
bottom = True
accessories = True
others = True
i = len(data)
while i:
i -= 1
@@ -111,7 +111,7 @@ def synthesis(data, size, basic_info):
background = np.zeros_like(top_outer_mask)
background[all_y_start:all_y_end, all_x_start:all_x_end] = sketch_mask[mask_y_start:mask_y_end, mask_x_start:mask_x_end]
bottom_outer_mask = background + bottom_outer_mask
elif accessories and data[i]['name'] in ['accessories_front']:
elif others and data[i]['name'] in ['others_front']:
mask_shape = data[i]['mask'].shape
y_offset, x_offset = data[i]['adaptive_position']
# 初始化叠加区域的起始和结束位置
@@ -121,13 +121,13 @@ def synthesis(data, size, basic_info):
_, sketch_mask = cv2.threshold(data[i]['mask'], 127, 255, cv2.THRESH_BINARY)
background = np.zeros_like(top_outer_mask)
background[all_y_start:all_y_end, all_x_start:all_x_end] = sketch_mask[mask_y_start:mask_y_end, mask_x_start:mask_x_end]
accessories_outer_mask = background + accessories_outer_mask
others_outer_mask = background + others_outer_mask
pass
elif bottom is False and top is False:
break
all_mask = cv2.bitwise_or(top_outer_mask, bottom_outer_mask)
all_mask = cv2.bitwise_or(all_mask, accessories_outer_mask)
all_mask = cv2.bitwise_or(all_mask, others_outer_mask)
for layer in data:
if layer['image'] is not None: