feat(新功能):
fix(修复bug): accessories 替换为 others docs(文档变更): refactor(重构): test(增加测试):
This commit is contained in:
@@ -5,7 +5,7 @@ from .top import Top, Blouse, Outwear, Dress
|
|||||||
from .bottom import Bottom, Trousers, Skirt
|
from .bottom import Bottom, Trousers, Skirt
|
||||||
from .shoes import Shoes
|
from .shoes import Shoes
|
||||||
from .bag import Bag
|
from .bag import Bag
|
||||||
from .accessories import Hairstyle, Earring
|
from .others import Hairstyle, Earring
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'ITEMS', 'build_item',
|
'ITEMS', 'build_item',
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ from celery import Celery
|
|||||||
from minio import Minio
|
from minio import Minio
|
||||||
|
|
||||||
from app.core.config import *
|
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.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.save_json import oss_upload_json
|
||||||
from app.service.design_batch.utils.synthesis_item import update_base_size_priority, synthesis, synthesis_single
|
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']:
|
elif item['type'].lower() in ['skirt', 'trousers', 'bottoms']:
|
||||||
bottom_server = BottomItem(data=item, basic=basic, minio_client=minio_client)
|
bottom_server = BottomItem(data=item, basic=basic, minio_client=minio_client)
|
||||||
item_data = bottom_server.process()
|
item_data = bottom_server.process()
|
||||||
elif item['type'].lower() in ['accessories']:
|
elif item['type'].lower() in ['others']:
|
||||||
bottom_server = AccessoriesItem(data=item, basic=basic, minio_client=minio_client)
|
bottom_server = OthersItem(data=item, basic=basic, minio_client=minio_client)
|
||||||
item_data = bottom_server.process()
|
item_data = bottom_server.process()
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError(f"Item type {item['type']} not implemented")
|
raise NotImplementedError(f"Item type {item['type']} not implemented")
|
||||||
@@ -47,8 +47,8 @@ def process_layer(item, layers):
|
|||||||
body_layer = organize_body(item)
|
body_layer = organize_body(item)
|
||||||
layers.append(body_layer)
|
layers.append(body_layer)
|
||||||
return item['body_image'].size
|
return item['body_image'].size
|
||||||
elif item['name'] == 'accessories':
|
elif item['name'] == 'others':
|
||||||
front_layer, back_layer = organize_accessories(item)
|
front_layer, back_layer = organize_others(item)
|
||||||
layers.append(front_layer)
|
layers.append(front_layer)
|
||||||
layers.append(back_layer)
|
layers.append(back_layer)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ class BaseItem:
|
|||||||
self.result.update(basic)
|
self.result.update(basic)
|
||||||
|
|
||||||
|
|
||||||
class AccessoriesItem(BaseItem):
|
class OthersItem(BaseItem):
|
||||||
def __init__(self, data, basic, minio_client):
|
def __init__(self, data, basic, minio_client):
|
||||||
super().__init__(data, basic)
|
super().__init__(data, basic)
|
||||||
self.Accessories_pipeline = [
|
self.Others_pipeline = [
|
||||||
LoadImage(minio_client),
|
LoadImage(minio_client),
|
||||||
# KeyPoint(),
|
# KeyPoint(),
|
||||||
ContourDetection(),
|
ContourDetection(),
|
||||||
@@ -25,7 +25,7 @@ class AccessoriesItem(BaseItem):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
for item in self.Accessories_pipeline:
|
for item in self.Others_pipeline:
|
||||||
self.result = item(self.result)
|
self.result = item(self.result)
|
||||||
return self.result
|
return self.result
|
||||||
|
|
||||||
|
|||||||
@@ -74,8 +74,8 @@ class LoadImage:
|
|||||||
keypoint = 'head_point'
|
keypoint = 'head_point'
|
||||||
elif name == 'earring':
|
elif name == 'earring':
|
||||||
keypoint = 'ear_point'
|
keypoint = 'ear_point'
|
||||||
elif name == 'accessories':
|
elif name == 'others':
|
||||||
keypoint = "accessories"
|
keypoint = "others"
|
||||||
else:
|
else:
|
||||||
raise KeyError(f"{name} does not belong to item category list: blouse, outwear, dress, trousers, skirt, "
|
raise KeyError(f"{name} does not belong to item category list: blouse, outwear, dress, trousers, skirt, "
|
||||||
f"bag, shoes, hairstyle, earring.")
|
f"bag, shoes, hairstyle, earring.")
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class Scaling:
|
|||||||
result['scale'] = result['scale_bag']
|
result['scale'] = result['scale_bag']
|
||||||
elif result['keypoint'] == 'ear_point':
|
elif result['keypoint'] == 'ear_point':
|
||||||
result['scale'] = result['scale_earrings']
|
result['scale'] = result['scale_earrings']
|
||||||
elif result['keypoint'] == 'accessories':
|
elif result['keypoint'] == 'others':
|
||||||
# 由于没有识别配饰keypoint的模型 所以统一将配饰的两个关键点设定为 (0,0) (0,img.width)
|
# 由于没有识别配饰keypoint的模型 所以统一将配饰的两个关键点设定为 (0,0) (0,img.width)
|
||||||
# 模特的关键点设定为(0,0) (0,320/2) 距离比例简写为 160 / img.width
|
# 模特的关键点设定为(0,0) (0,320/2) 距离比例简写为 160 / img.width
|
||||||
distance_clo = result['img_shape'][1]
|
distance_clo = result['img_shape'][1]
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class Split(object):
|
|||||||
def __call__(self, result):
|
def __call__(self, result):
|
||||||
try:
|
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:
|
if result['resize_scale'][0] == 1.0 and result['resize_scale'][1] == 1.0:
|
||||||
front_mask = result['front_mask']
|
front_mask = result['front_mask']
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ def organize_clothing(layer):
|
|||||||
return front_layer, back_layer
|
return front_layer, back_layer
|
||||||
|
|
||||||
|
|
||||||
def organize_accessories(layer):
|
def organize_others(layer):
|
||||||
# 起始坐标
|
# 起始坐标
|
||||||
start_point = (0, 0)
|
start_point = (0, 0)
|
||||||
# 前片数据
|
# 前片数据
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import requests
|
|||||||
from minio import Minio
|
from minio import Minio
|
||||||
|
|
||||||
from app.core.config import *
|
from app.core.config import *
|
||||||
from app.service.design_fast.item import BodyItem, TopItem, BottomItem, AccessoriesItem
|
from app.service.design_fast.item import BodyItem, TopItem, BottomItem, OthersItem
|
||||||
from app.service.design_fast.utils.organize import organize_body, organize_clothing, organize_accessories
|
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.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.design_fast.utils.synthesis_item import synthesis, synthesis_single, update_base_size_priority
|
||||||
from app.service.utils.decorator import RunTime
|
from app.service.utils.decorator import RunTime
|
||||||
@@ -30,8 +30,8 @@ def process_item(item, basic):
|
|||||||
elif item['type'].lower() in ['skirt', 'trousers', 'bottoms']:
|
elif item['type'].lower() in ['skirt', 'trousers', 'bottoms']:
|
||||||
bottom_server = BottomItem(data=item, basic=basic, minio_client=minio_client)
|
bottom_server = BottomItem(data=item, basic=basic, minio_client=minio_client)
|
||||||
item_data = bottom_server.process()
|
item_data = bottom_server.process()
|
||||||
elif item['type'].lower() in ['accessories']:
|
elif item['type'].lower() in ['others']:
|
||||||
bottom_server = AccessoriesItem(data=item, basic=basic, minio_client=minio_client)
|
bottom_server = OthersItem(data=item, basic=basic, minio_client=minio_client)
|
||||||
item_data = bottom_server.process()
|
item_data = bottom_server.process()
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError(f"Item type {item['type']} not implemented")
|
raise NotImplementedError(f"Item type {item['type']} not implemented")
|
||||||
@@ -44,8 +44,8 @@ def process_layer(item, layers):
|
|||||||
body_layer = organize_body(item)
|
body_layer = organize_body(item)
|
||||||
layers.append(body_layer)
|
layers.append(body_layer)
|
||||||
return item['body_image'].size
|
return item['body_image'].size
|
||||||
elif item['name'] == 'accessories':
|
elif item['name'] == 'others':
|
||||||
front_layer, back_layer = organize_accessories(item)
|
front_layer, back_layer = organize_others(item)
|
||||||
layers.append(front_layer)
|
layers.append(front_layer)
|
||||||
layers.append(back_layer)
|
layers.append(back_layer)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ class BaseItem:
|
|||||||
self.result.update(basic)
|
self.result.update(basic)
|
||||||
|
|
||||||
|
|
||||||
class AccessoriesItem(BaseItem):
|
class OthersItem(BaseItem):
|
||||||
def __init__(self, data, basic, minio_client):
|
def __init__(self, data, basic, minio_client):
|
||||||
super().__init__(data, basic)
|
super().__init__(data, basic)
|
||||||
self.Accessories_pipeline = [
|
self.Others_pipeline = [
|
||||||
LoadImage(minio_client),
|
LoadImage(minio_client),
|
||||||
# KeyPoint(),
|
# KeyPoint(),
|
||||||
# ContourDetection(),
|
# ContourDetection(),
|
||||||
@@ -26,7 +26,7 @@ class AccessoriesItem(BaseItem):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
for item in self.Accessories_pipeline:
|
for item in self.Others_pipeline:
|
||||||
self.result = item(self.result)
|
self.result = item(self.result)
|
||||||
return self.result
|
return self.result
|
||||||
|
|
||||||
|
|||||||
@@ -105,8 +105,8 @@ class LoadImage:
|
|||||||
keypoint = 'head_point'
|
keypoint = 'head_point'
|
||||||
elif name == 'earring':
|
elif name == 'earring':
|
||||||
keypoint = 'ear_point'
|
keypoint = 'ear_point'
|
||||||
elif name == 'accessories':
|
elif name == 'others':
|
||||||
keypoint = "accessories"
|
keypoint = "others"
|
||||||
else:
|
else:
|
||||||
raise KeyError(f"{name} does not belong to item category list: blouse, outwear, dress, trousers, skirt, "
|
raise KeyError(f"{name} does not belong to item category list: blouse, outwear, dress, trousers, skirt, "
|
||||||
f"bag, shoes, hairstyle, earring.")
|
f"bag, shoes, hairstyle, earring.")
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class Scaling:
|
|||||||
result['scale'] = result['scale_bag']
|
result['scale'] = result['scale_bag']
|
||||||
elif result['keypoint'] == 'ear_point':
|
elif result['keypoint'] == 'ear_point':
|
||||||
result['scale'] = result['scale_earrings']
|
result['scale'] = result['scale_earrings']
|
||||||
elif result['keypoint'] == 'accessories':
|
elif result['keypoint'] == 'others':
|
||||||
# 由于没有识别配饰keypoint的模型 所以统一将配饰的两个关键点设定为 (0,0) (0,img.width)
|
# 由于没有识别配饰keypoint的模型 所以统一将配饰的两个关键点设定为 (0,0) (0,img.width)
|
||||||
# 模特的关键点设定为(0,0) (0,320/2) 距离比例简写为 160 / img.width
|
# 模特的关键点设定为(0,0) (0,320/2) 距离比例简写为 160 / img.width
|
||||||
distance_clo = result['img_shape'][1]
|
distance_clo = result['img_shape'][1]
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class Split(object):
|
|||||||
|
|
||||||
def __call__(self, result):
|
def __call__(self, result):
|
||||||
try:
|
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_front_mask = result['front_mask'].copy()
|
||||||
ori_back_mask = result['back_mask'].copy()
|
ori_back_mask = result['back_mask'].copy()
|
||||||
|
|
||||||
|
|||||||
@@ -58,14 +58,14 @@ def organize_clothing(layer):
|
|||||||
return front_layer, back_layer
|
return front_layer, back_layer
|
||||||
|
|
||||||
|
|
||||||
def organize_accessories(layer):
|
def organize_others(layer):
|
||||||
# 起始坐标
|
# 起始坐标
|
||||||
start_point = (0, 0)
|
start_point = (0, 0)
|
||||||
layer['clothes_keypoint'] = {
|
layer['clothes_keypoint'] = {
|
||||||
'accessories_left': [0, 0]
|
'others_left': [0, 0]
|
||||||
}
|
}
|
||||||
layer['body_point_test'] = {
|
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"])
|
start_point = calculate_start_point(layer['keypoint'], layer['scale'], layer['clothes_keypoint'], layer['body_point_test'], layer["offset"], layer["resize_scale"])
|
||||||
|
|||||||
@@ -79,11 +79,11 @@ def synthesis(data, size, basic_info):
|
|||||||
_, binary_body_mask = cv2.threshold(body_mask, 127, 255, cv2.THRESH_BINARY)
|
_, binary_body_mask = cv2.threshold(body_mask, 127, 255, cv2.THRESH_BINARY)
|
||||||
top_outer_mask = np.array(binary_body_mask)
|
top_outer_mask = np.array(binary_body_mask)
|
||||||
bottom_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
|
top = True
|
||||||
bottom = True
|
bottom = True
|
||||||
accessories = True
|
others = True
|
||||||
i = len(data)
|
i = len(data)
|
||||||
while i:
|
while i:
|
||||||
i -= 1
|
i -= 1
|
||||||
@@ -111,7 +111,7 @@ def synthesis(data, size, basic_info):
|
|||||||
background = np.zeros_like(top_outer_mask)
|
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]
|
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
|
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
|
mask_shape = data[i]['mask'].shape
|
||||||
y_offset, x_offset = data[i]['adaptive_position']
|
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)
|
_, sketch_mask = cv2.threshold(data[i]['mask'], 127, 255, cv2.THRESH_BINARY)
|
||||||
background = np.zeros_like(top_outer_mask)
|
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]
|
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
|
pass
|
||||||
elif bottom is False and top is False:
|
elif bottom is False and top is False:
|
||||||
break
|
break
|
||||||
|
|
||||||
all_mask = cv2.bitwise_or(top_outer_mask, bottom_outer_mask)
|
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:
|
for layer in data:
|
||||||
if layer['image'] is not None:
|
if layer['image'] is not None:
|
||||||
|
|||||||
Reference in New Issue
Block a user