feat 测试批量上传图片
fix
This commit is contained in:
@@ -37,7 +37,8 @@ class Clothing(object):
|
||||
resize_scale=self.result["resize_scale"],
|
||||
mask=cv2.resize(self.result['mask'], self.result["front_image"].size),
|
||||
gradient_string=self.result['gradient_string'] if 'gradient_string' in self.result.keys() else "",
|
||||
pattern_image_url=self.result['pattern_image_url']
|
||||
pattern_image_url=self.result['pattern_image_url'],
|
||||
pattern_image=self.result['pattern_image']
|
||||
|
||||
)
|
||||
layer.insert(front_layer)
|
||||
@@ -54,7 +55,7 @@ class Clothing(object):
|
||||
resize_scale=self.result["resize_scale"],
|
||||
mask=cv2.resize(self.result['mask'], self.result["front_image"].size),
|
||||
gradient_string=self.result['gradient_string'] if 'gradient_string' in self.result.keys() else "",
|
||||
pattern_image_url=self.result['pattern_image_url']
|
||||
pattern_image_url=self.result['pattern_image_url'],
|
||||
)
|
||||
layer.insert(back_layer)
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import numpy as np
|
||||
from pymilvus import MilvusClient
|
||||
|
||||
from app.core.config import *
|
||||
from app.service.utils.decorator import RunTime, ClassCallRunTime
|
||||
from ..builder import PIPELINES
|
||||
from ...utils.design_ensemble import get_keypoint_result
|
||||
|
||||
@@ -27,7 +28,7 @@ class KeypointDetection(object):
|
||||
# self.client.close()
|
||||
# print(f"client close time : {time.time() - start_time}")
|
||||
|
||||
# @ RunTime
|
||||
@ ClassCallRunTime
|
||||
def __call__(self, result):
|
||||
# logging.info("KeypointDetection run ")
|
||||
if result['name'] in ['blouse', 'skirt', 'dress', 'outwear', 'trousers', 'tops', 'bottoms']: # 查询是否有数据 且类别相同 相同则直接读 不同则推理后更新
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import cv2
|
||||
|
||||
from app.service.utils.decorator import RunTime, ClassCallRunTime
|
||||
from app.service.utils.oss_client import oss_get_image
|
||||
from ..builder import PIPELINES
|
||||
|
||||
@@ -12,6 +13,7 @@ class LoadImageFromFile(object):
|
||||
self.print_dict = print_dict
|
||||
# self.minio_client = Minio(f"{MINIO_URL}", access_key=MINIO_ACCESS, secret_key=MINIO_SECRET, secure=MINIO_SECURE)
|
||||
|
||||
@ClassCallRunTime
|
||||
def __call__(self, result):
|
||||
result['image'], result['pre_mask'] = self.read_image(self.path)
|
||||
result['gray'] = cv2.cvtColor(result['image'], cv2.COLOR_BGR2GRAY)
|
||||
|
||||
@@ -4,6 +4,7 @@ import cv2
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
|
||||
from app.service.utils.decorator import RunTime, ClassCallRunTime
|
||||
from app.service.utils.oss_client import oss_get_image
|
||||
from ..builder import PIPELINES
|
||||
|
||||
@@ -13,7 +14,7 @@ class Painting(object):
|
||||
def __init__(self, painting_flag=True):
|
||||
self.painting_flag = painting_flag
|
||||
|
||||
# @ RunTime
|
||||
@ClassCallRunTime
|
||||
def __call__(self, result):
|
||||
if result['name'] not in ['hairstyle', 'earring'] and self.painting_flag and result['color'] != 'none':
|
||||
dim_image_h, dim_image_w = result['image'].shape[0:2]
|
||||
@@ -86,7 +87,7 @@ class PrintPainting(object):
|
||||
def __init__(self, print_flag=True):
|
||||
self.print_flag = print_flag
|
||||
|
||||
# @ RunTime
|
||||
@ClassCallRunTime
|
||||
def __call__(self, result):
|
||||
single_print = result['print']['single']
|
||||
overall_print = result['print']['overall']
|
||||
@@ -236,7 +237,6 @@ class PrintPainting(object):
|
||||
|
||||
print_background = cv2.cvtColor(np.array(source_image_pil), cv2.COLOR_RGBA2BGR)
|
||||
mask_background = cv2.cvtColor(np.array(source_image_pil_mask), cv2.COLOR_RGBA2BGR)
|
||||
print(1)
|
||||
else:
|
||||
mask = self.get_mask_inv(image)
|
||||
mask = np.expand_dims(mask, axis=2)
|
||||
|
||||
@@ -2,6 +2,7 @@ import math
|
||||
|
||||
import cv2
|
||||
|
||||
from app.service.utils.decorator import ClassCallRunTime
|
||||
from ..builder import PIPELINES
|
||||
|
||||
|
||||
@@ -10,7 +11,7 @@ class Scaling(object):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
# @ RunTime
|
||||
@ClassCallRunTime
|
||||
def __call__(self, result):
|
||||
if result['keypoint'] in ['waistband', 'shoulder', 'head_point']:
|
||||
# milvus_db_keypoint_cache
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
import os
|
||||
|
||||
import numpy as np
|
||||
|
||||
from app.core.config import SEG_CACHE_PATH
|
||||
from app.service.utils.decorator import ClassCallRunTime
|
||||
from ..builder import PIPELINES
|
||||
from ...utils.design_ensemble import get_seg_result
|
||||
|
||||
@@ -9,6 +15,32 @@ class Segmentation(object):
|
||||
self.device = device
|
||||
self.debug = debug
|
||||
|
||||
@ClassCallRunTime
|
||||
def __call__(self, result):
|
||||
result['seg_result'] = get_seg_result(result["image_id"], result['image'])
|
||||
_, seg_result = self.load_seg_result(result["image_id"])
|
||||
if not _:
|
||||
result['seg_result'] = get_seg_result(result["image_id"], result['image'])
|
||||
self.save_seg_result(result['seg_result'][0], result['image_id'])
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def save_seg_result(seg_result, image_id):
|
||||
file_path = f"{SEG_CACHE_PATH}{image_id}.npy"
|
||||
try:
|
||||
np.save(file_path, seg_result)
|
||||
print("保存成功", os.path.abspath(file_path))
|
||||
except Exception as e:
|
||||
print(f"保存失败: {e}")
|
||||
|
||||
@staticmethod
|
||||
def load_seg_result(image_id):
|
||||
file_path = f"{SEG_CACHE_PATH}{image_id}.npy"
|
||||
try:
|
||||
seg_result = np.load(file_path)
|
||||
return True, seg_result
|
||||
except FileNotFoundError:
|
||||
print("文件不存在")
|
||||
return False, None
|
||||
except Exception as e:
|
||||
print(f"加载失败: {e}")
|
||||
return False, None
|
||||
|
||||
@@ -5,6 +5,7 @@ import numpy as np
|
||||
from PIL import Image
|
||||
from cv2 import cvtColor, COLOR_BGR2RGBA
|
||||
|
||||
from app.service.utils.decorator import ClassCallRunTime
|
||||
from app.service.utils.generate_uuid import generate_uuid
|
||||
from ..builder import PIPELINES
|
||||
from ...utils.conversion_image import rgb_to_rgba
|
||||
@@ -17,6 +18,7 @@ class Split(object):
|
||||
Split image into front and back layer according to the segmentation result
|
||||
"""
|
||||
|
||||
@ClassCallRunTime
|
||||
# KNet
|
||||
def __call__(self, result):
|
||||
try:
|
||||
@@ -66,7 +68,7 @@ class Split(object):
|
||||
# 创建中间图层
|
||||
result_pattern_image_rgba = rgb_to_rgba(result['pattern_image'], result['mask'])
|
||||
result_pattern_image_pil = Image.fromarray(cvtColor(result_pattern_image_rgba, COLOR_BGR2RGBA))
|
||||
_, result['pattern_image_url'], _ = upload_png_mask(result_pattern_image_pil, f'{generate_uuid()}')
|
||||
result['pattern'], result['pattern_image_url'], _ = upload_png_mask(result_pattern_image_pil, f'{generate_uuid()}')
|
||||
return result
|
||||
except Exception as e:
|
||||
logging.warning(f"split runtime exception : {e} image_id : {result['image_id']}")
|
||||
|
||||
Reference in New Issue
Block a user