feat 测试批量上传图片
fix
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -120,6 +120,7 @@ dmypy.json
|
|||||||
|
|
||||||
#runtime produce
|
#runtime produce
|
||||||
test
|
test
|
||||||
|
seg_cache
|
||||||
logs
|
logs
|
||||||
seg_result/
|
seg_result/
|
||||||
seg_result
|
seg_result
|
||||||
|
|||||||
@@ -136,13 +136,16 @@ def design(request_data: DesignModel):
|
|||||||
"process_id": "89"
|
"process_id": "89"
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
try:
|
logger.info(f"design request item is : @@@@@@:{json.dumps(request_data.dict())}")
|
||||||
logger.info(f"design request item is : @@@@@@:{json.dumps(request_data.dict())}")
|
data = generate(request_data=request_data)
|
||||||
data = generate(request_data=request_data)
|
logger.info(f"design response @@@@@@:{json.dumps(data)}")
|
||||||
logger.info(f"design response @@@@@@:{json.dumps(data)}")
|
# try:
|
||||||
except Exception as e:
|
# logger.info(f"design request item is : @@@@@@:{json.dumps(request_data.dict())}")
|
||||||
logger.warning(f"design Run Exception @@@@@@:{e}")
|
# data = generate(request_data=request_data)
|
||||||
raise HTTPException(status_code=404, detail=str(e))
|
# logger.info(f"design response @@@@@@:{json.dumps(data)}")
|
||||||
|
# except Exception as e:
|
||||||
|
# logger.warning(f"design Run Exception @@@@@@:{e}")
|
||||||
|
# raise HTTPException(status_code=404, detail=str(e))
|
||||||
return ResponseModel(data=data)
|
return ResponseModel(data=data)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -24,11 +24,11 @@ DEBUG = False
|
|||||||
if DEBUG:
|
if DEBUG:
|
||||||
LOGS_PATH = "logs/"
|
LOGS_PATH = "logs/"
|
||||||
CATEGORY_PATH = "service/attribute/config/descriptor/category/category_dis.csv"
|
CATEGORY_PATH = "service/attribute/config/descriptor/category/category_dis.csv"
|
||||||
# FACE_CLASSIFIER = "service/generate_image/utils/haarcascade_frontalface_alt.xml"
|
SEG_CACHE_PATH = "../seg_cache/"
|
||||||
else:
|
else:
|
||||||
LOGS_PATH = "app/logs/"
|
LOGS_PATH = "app/logs/"
|
||||||
CATEGORY_PATH = "app/service/attribute/config/descriptor/category/category_dis.csv"
|
CATEGORY_PATH = "app/service/attribute/config/descriptor/category/category_dis.csv"
|
||||||
# FACE_CLASSIFIER = 'app/service/generate_image/utils/haarcascade_frontalface_alt.xml'
|
SEG_CACHE_PATH = "/seg_cache/"
|
||||||
|
|
||||||
# RABBITMQ_ENV = "" # 生产环境
|
# RABBITMQ_ENV = "" # 生产环境
|
||||||
RABBITMQ_ENV = "-dev" # 开发环境
|
RABBITMQ_ENV = "-dev" # 开发环境
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ class Clothing(object):
|
|||||||
resize_scale=self.result["resize_scale"],
|
resize_scale=self.result["resize_scale"],
|
||||||
mask=cv2.resize(self.result['mask'], self.result["front_image"].size),
|
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 "",
|
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)
|
layer.insert(front_layer)
|
||||||
@@ -54,7 +55,7 @@ class Clothing(object):
|
|||||||
resize_scale=self.result["resize_scale"],
|
resize_scale=self.result["resize_scale"],
|
||||||
mask=cv2.resize(self.result['mask'], self.result["front_image"].size),
|
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 "",
|
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)
|
layer.insert(back_layer)
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import numpy as np
|
|||||||
from pymilvus import MilvusClient
|
from pymilvus import MilvusClient
|
||||||
|
|
||||||
from app.core.config import *
|
from app.core.config import *
|
||||||
|
from app.service.utils.decorator import RunTime, ClassCallRunTime
|
||||||
from ..builder import PIPELINES
|
from ..builder import PIPELINES
|
||||||
from ...utils.design_ensemble import get_keypoint_result
|
from ...utils.design_ensemble import get_keypoint_result
|
||||||
|
|
||||||
@@ -27,7 +28,7 @@ class KeypointDetection(object):
|
|||||||
# self.client.close()
|
# self.client.close()
|
||||||
# print(f"client close time : {time.time() - start_time}")
|
# print(f"client close time : {time.time() - start_time}")
|
||||||
|
|
||||||
# @ RunTime
|
@ ClassCallRunTime
|
||||||
def __call__(self, result):
|
def __call__(self, result):
|
||||||
# logging.info("KeypointDetection run ")
|
# logging.info("KeypointDetection run ")
|
||||||
if result['name'] in ['blouse', 'skirt', 'dress', 'outwear', 'trousers', 'tops', 'bottoms']: # 查询是否有数据 且类别相同 相同则直接读 不同则推理后更新
|
if result['name'] in ['blouse', 'skirt', 'dress', 'outwear', 'trousers', 'tops', 'bottoms']: # 查询是否有数据 且类别相同 相同则直接读 不同则推理后更新
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import cv2
|
import cv2
|
||||||
|
|
||||||
|
from app.service.utils.decorator import RunTime, ClassCallRunTime
|
||||||
from app.service.utils.oss_client import oss_get_image
|
from app.service.utils.oss_client import oss_get_image
|
||||||
from ..builder import PIPELINES
|
from ..builder import PIPELINES
|
||||||
|
|
||||||
@@ -12,6 +13,7 @@ class LoadImageFromFile(object):
|
|||||||
self.print_dict = print_dict
|
self.print_dict = print_dict
|
||||||
# self.minio_client = Minio(f"{MINIO_URL}", access_key=MINIO_ACCESS, secret_key=MINIO_SECRET, secure=MINIO_SECURE)
|
# self.minio_client = Minio(f"{MINIO_URL}", access_key=MINIO_ACCESS, secret_key=MINIO_SECRET, secure=MINIO_SECURE)
|
||||||
|
|
||||||
|
@ClassCallRunTime
|
||||||
def __call__(self, result):
|
def __call__(self, result):
|
||||||
result['image'], result['pre_mask'] = self.read_image(self.path)
|
result['image'], result['pre_mask'] = self.read_image(self.path)
|
||||||
result['gray'] = cv2.cvtColor(result['image'], cv2.COLOR_BGR2GRAY)
|
result['gray'] = cv2.cvtColor(result['image'], cv2.COLOR_BGR2GRAY)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import cv2
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
from app.service.utils.decorator import RunTime, ClassCallRunTime
|
||||||
from app.service.utils.oss_client import oss_get_image
|
from app.service.utils.oss_client import oss_get_image
|
||||||
from ..builder import PIPELINES
|
from ..builder import PIPELINES
|
||||||
|
|
||||||
@@ -13,7 +14,7 @@ class Painting(object):
|
|||||||
def __init__(self, painting_flag=True):
|
def __init__(self, painting_flag=True):
|
||||||
self.painting_flag = painting_flag
|
self.painting_flag = painting_flag
|
||||||
|
|
||||||
# @ RunTime
|
@ClassCallRunTime
|
||||||
def __call__(self, result):
|
def __call__(self, result):
|
||||||
if result['name'] not in ['hairstyle', 'earring'] and self.painting_flag and result['color'] != 'none':
|
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]
|
dim_image_h, dim_image_w = result['image'].shape[0:2]
|
||||||
@@ -86,7 +87,7 @@ class PrintPainting(object):
|
|||||||
def __init__(self, print_flag=True):
|
def __init__(self, print_flag=True):
|
||||||
self.print_flag = print_flag
|
self.print_flag = print_flag
|
||||||
|
|
||||||
# @ RunTime
|
@ClassCallRunTime
|
||||||
def __call__(self, result):
|
def __call__(self, result):
|
||||||
single_print = result['print']['single']
|
single_print = result['print']['single']
|
||||||
overall_print = result['print']['overall']
|
overall_print = result['print']['overall']
|
||||||
@@ -236,7 +237,6 @@ class PrintPainting(object):
|
|||||||
|
|
||||||
print_background = cv2.cvtColor(np.array(source_image_pil), cv2.COLOR_RGBA2BGR)
|
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)
|
mask_background = cv2.cvtColor(np.array(source_image_pil_mask), cv2.COLOR_RGBA2BGR)
|
||||||
print(1)
|
|
||||||
else:
|
else:
|
||||||
mask = self.get_mask_inv(image)
|
mask = self.get_mask_inv(image)
|
||||||
mask = np.expand_dims(mask, axis=2)
|
mask = np.expand_dims(mask, axis=2)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import math
|
|||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
|
|
||||||
|
from app.service.utils.decorator import ClassCallRunTime
|
||||||
from ..builder import PIPELINES
|
from ..builder import PIPELINES
|
||||||
|
|
||||||
|
|
||||||
@@ -10,7 +11,7 @@ class Scaling(object):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# @ RunTime
|
@ClassCallRunTime
|
||||||
def __call__(self, result):
|
def __call__(self, result):
|
||||||
if result['keypoint'] in ['waistband', 'shoulder', 'head_point']:
|
if result['keypoint'] in ['waistband', 'shoulder', 'head_point']:
|
||||||
# milvus_db_keypoint_cache
|
# 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 ..builder import PIPELINES
|
||||||
from ...utils.design_ensemble import get_seg_result
|
from ...utils.design_ensemble import get_seg_result
|
||||||
|
|
||||||
@@ -9,6 +15,32 @@ class Segmentation(object):
|
|||||||
self.device = device
|
self.device = device
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
|
|
||||||
|
@ClassCallRunTime
|
||||||
def __call__(self, result):
|
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
|
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 PIL import Image
|
||||||
from cv2 import cvtColor, COLOR_BGR2RGBA
|
from cv2 import cvtColor, COLOR_BGR2RGBA
|
||||||
|
|
||||||
|
from app.service.utils.decorator import ClassCallRunTime
|
||||||
from app.service.utils.generate_uuid import generate_uuid
|
from app.service.utils.generate_uuid import generate_uuid
|
||||||
from ..builder import PIPELINES
|
from ..builder import PIPELINES
|
||||||
from ...utils.conversion_image import rgb_to_rgba
|
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
|
Split image into front and back layer according to the segmentation result
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ClassCallRunTime
|
||||||
# KNet
|
# KNet
|
||||||
def __call__(self, result):
|
def __call__(self, result):
|
||||||
try:
|
try:
|
||||||
@@ -66,7 +68,7 @@ class Split(object):
|
|||||||
# 创建中间图层
|
# 创建中间图层
|
||||||
result_pattern_image_rgba = rgb_to_rgba(result['pattern_image'], result['mask'])
|
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_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
|
return result
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.warning(f"split runtime exception : {e} image_id : {result['image_id']}")
|
logging.warning(f"split runtime exception : {e} image_id : {result['image_id']}")
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
|
import io
|
||||||
|
|
||||||
|
import cv2
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
from app.core.config import PRIORITY_DICT
|
from app.core.config import PRIORITY_DICT
|
||||||
from app.service.design.core.layer import Layer
|
from app.service.design.core.layer import Layer
|
||||||
@@ -6,6 +10,7 @@ from app.service.design.items import build_item
|
|||||||
from app.service.design.utils.redis_utils import Redis
|
from app.service.design.utils.redis_utils import Redis
|
||||||
from app.service.design.utils.synthesis_item import synthesis, synthesis_single
|
from app.service.design.utils.synthesis_item import synthesis, synthesis_single
|
||||||
from app.service.utils.decorator import RunTime
|
from app.service.utils.decorator import RunTime
|
||||||
|
from app.service.utils.oss_client import oss_upload_image
|
||||||
|
|
||||||
|
|
||||||
def process_item(item, layers):
|
def process_item(item, layers):
|
||||||
@@ -43,6 +48,7 @@ def final_progress(process_id):
|
|||||||
@RunTime
|
@RunTime
|
||||||
def generate(request_data):
|
def generate(request_data):
|
||||||
return_response = {}
|
return_response = {}
|
||||||
|
return_png_mask = []
|
||||||
request_data = request_data.dict()
|
request_data = request_data.dict()
|
||||||
assert "process_id" in request_data.keys(), "Need process_id parameters"
|
assert "process_id" in request_data.keys(), "Need process_id parameters"
|
||||||
|
|
||||||
@@ -55,14 +61,15 @@ def generate(request_data):
|
|||||||
# 获取处理结果
|
# 获取处理结果
|
||||||
for future in concurrent.futures.as_completed(futures):
|
for future in concurrent.futures.as_completed(futures):
|
||||||
obj = futures[future]
|
obj = futures[future]
|
||||||
|
return_response[obj] = future.result()[0]
|
||||||
result = future.result()
|
return_png_mask.extend(future.result()[1])
|
||||||
return_response[obj] = result
|
|
||||||
final_progress(process_id)
|
final_progress(process_id)
|
||||||
|
upload_results = process_images(return_png_mask)
|
||||||
return return_response
|
return return_response
|
||||||
|
|
||||||
|
|
||||||
def process_object(cfg, process_id, total):
|
def process_object(cfg, process_id, total):
|
||||||
|
uploaded_images = []
|
||||||
basic_info = cfg.get('basic')
|
basic_info = cfg.get('basic')
|
||||||
items_response = {
|
items_response = {
|
||||||
'layers': []
|
'layers': []
|
||||||
@@ -83,6 +90,15 @@ def process_object(cfg, process_id, total):
|
|||||||
layers = sorted(layers.layer, key=lambda s: s.get("priority", float('inf')))
|
layers = sorted(layers.layer, key=lambda s: s.get("priority", float('inf')))
|
||||||
else:
|
else:
|
||||||
layers = sorted(layers.layer, key=lambda x: PRIORITY_DICT.get(x['name'], float('inf')))
|
layers = sorted(layers.layer, key=lambda x: PRIORITY_DICT.get(x['name'], float('inf')))
|
||||||
|
# 上传所有图片
|
||||||
|
for layer in layers:
|
||||||
|
if 'image' in layer.keys() and layer['image'] is not None:
|
||||||
|
uploaded_images.append({'image_obj': layer['image'], 'image_url': layer['image_url']})
|
||||||
|
if 'pattern_image' in layer.keys() and layer['pattern_image'] is not None:
|
||||||
|
uploaded_images.append({'image_obj': layer['pattern_image'], 'image_url': layer['pattern_image_url']})
|
||||||
|
if 'mask' in layer.keys() and layer['mask'] is not None and layer['mask_url'] is not None:
|
||||||
|
uploaded_images.append({'image_obj': layer['mask'], 'image_url': layer['mask_url']})
|
||||||
|
|
||||||
# 合成
|
# 合成
|
||||||
items_response['synthesis_url'] = synthesis(layers, body_size)
|
items_response['synthesis_url'] = synthesis(layers, body_size)
|
||||||
|
|
||||||
@@ -131,4 +147,34 @@ def process_object(cfg, process_id, total):
|
|||||||
items_response['synthesis_url'] = synthesis_single(item.result['front_image'], item.result['back_image'])
|
items_response['synthesis_url'] = synthesis_single(item.result['front_image'], item.result['back_image'])
|
||||||
break
|
break
|
||||||
update_progress(process_id, total)
|
update_progress(process_id, total)
|
||||||
return items_response
|
return items_response, uploaded_images
|
||||||
|
|
||||||
|
|
||||||
|
@RunTime
|
||||||
|
def process_images(images):
|
||||||
|
with concurrent.futures.ThreadPoolExecutor() as executor:
|
||||||
|
results = list(executor.map(upload_images, images))
|
||||||
|
# results = []
|
||||||
|
# for image in images:
|
||||||
|
# results.append(upload_images(image))
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
@RunTime
|
||||||
|
def upload_images(image_obj):
|
||||||
|
bucket_name = image_obj['image_url'].split("/", 1)[0]
|
||||||
|
object_name = image_obj['image_url'].split("/", 1)[1]
|
||||||
|
if isinstance(image_obj['image_obj'], Image.Image):
|
||||||
|
image_data = io.BytesIO()
|
||||||
|
image_obj['image_obj'].save(image_data, format='PNG')
|
||||||
|
image_data.seek(0)
|
||||||
|
image_bytes = image_data.read()
|
||||||
|
req = oss_upload_image(bucket=bucket_name, object_name=object_name, image_bytes=image_bytes)
|
||||||
|
return image_obj['image_url']
|
||||||
|
else:
|
||||||
|
mask_inverted = cv2.bitwise_not(image_obj['image_obj'])
|
||||||
|
# 将掩模的3通道转换为4通道,白色部分不透明,黑色部分透明
|
||||||
|
rgba_image = cv2.cvtColor(mask_inverted, cv2.COLOR_BGR2BGRA)
|
||||||
|
rgba_image[rgba_image[:, :, 0] == 0] = [0, 0, 0, 0]
|
||||||
|
req = oss_upload_image(bucket=bucket_name, object_name=object_name, image_bytes=cv2.imencode('.png', rgba_image)[1])
|
||||||
|
return image_obj['image_url']
|
||||||
|
|||||||
@@ -13,33 +13,43 @@ import logging
|
|||||||
import cv2
|
import cv2
|
||||||
|
|
||||||
from app.core.config import *
|
from app.core.config import *
|
||||||
|
from app.service.utils.decorator import RunTime
|
||||||
from app.service.utils.oss_client import oss_upload_image
|
from app.service.utils.oss_client import oss_upload_image
|
||||||
|
|
||||||
|
|
||||||
# @RunTime
|
# @RunTime
|
||||||
def upload_png_mask(front_image, object_name, mask=None):
|
# def upload_png_mask(front_image, object_name, mask=None):
|
||||||
try:
|
# try:
|
||||||
mask_url = None
|
# mask_url = None
|
||||||
if mask is not None:
|
# if mask is not None:
|
||||||
mask_inverted = cv2.bitwise_not(mask)
|
# mask_inverted = cv2.bitwise_not(mask)
|
||||||
# 将掩模的3通道转换为4通道,白色部分不透明,黑色部分透明
|
# # 将掩模的3通道转换为4通道,白色部分不透明,黑色部分透明
|
||||||
rgba_image = cv2.cvtColor(mask_inverted, cv2.COLOR_BGR2BGRA)
|
# rgba_image = cv2.cvtColor(mask_inverted, cv2.COLOR_BGR2BGRA)
|
||||||
rgba_image[rgba_image[:, :, 0] == 0] = [0, 0, 0, 0]
|
# rgba_image[rgba_image[:, :, 0] == 0] = [0, 0, 0, 0]
|
||||||
# image_bytes = io.BytesIO()
|
# # image_bytes = io.BytesIO()
|
||||||
# image_bytes.write(cv2.imencode('.png', rgba_image)[1].tobytes())
|
# # image_bytes.write(cv2.imencode('.png', rgba_image)[1].tobytes())
|
||||||
# image_bytes.seek(0)
|
# # image_bytes.seek(0)
|
||||||
# mask_url = f"{AIDA_CLOTHING}/{minio_client.put_object('aida-clothing', f'mask/mask_{object_name}.png', image_bytes, len(image_bytes.getvalue()), content_type='image/png').object_name}"
|
# # mask_url = f"{AIDA_CLOTHING}/{minio_client.put_object('aida-clothing', f'mask/mask_{object_name}.png', image_bytes, len(image_bytes.getvalue()), content_type='image/png').object_name}"
|
||||||
# oss upload ####################
|
# # oss upload ####################
|
||||||
req = oss_upload_image(bucket=AIDA_CLOTHING, object_name=f"mask/mask_{object_name}.png", image_bytes=cv2.imencode('.png', rgba_image)[1])
|
# req = oss_upload_image(bucket=AIDA_CLOTHING, object_name=f"mask/mask_{object_name}.png", image_bytes=cv2.imencode('.png', rgba_image)[1])
|
||||||
mask_url = f"{AIDA_CLOTHING}/mask/mask_{object_name}.png"
|
# mask_url = f"{AIDA_CLOTHING}/mask/mask_{object_name}.png"
|
||||||
|
#
|
||||||
|
# image_data = io.BytesIO()
|
||||||
|
# front_image.save(image_data, format='PNG')
|
||||||
|
# image_data.seek(0)
|
||||||
|
# image_bytes = image_data.read()
|
||||||
|
# # image_url = f"{AIDA_CLOTHING}/{minio_client.put_object('aida-clothing', f'image/image_{object_name}.png', io.BytesIO(image_bytes), len(image_bytes), content_type='image/png').object_name}"
|
||||||
|
# req = oss_upload_image(bucket=AIDA_CLOTHING, object_name=f"image/image_{object_name}.png", image_bytes=image_bytes)
|
||||||
|
# image_url = f"{AIDA_CLOTHING}/image/image_{object_name}.png"
|
||||||
|
# return front_image, image_url, mask_url
|
||||||
|
# except Exception as e:
|
||||||
|
# logging.warning(f"upload_png_mask runtime exception : {e}")
|
||||||
|
|
||||||
image_data = io.BytesIO()
|
|
||||||
front_image.save(image_data, format='PNG')
|
@RunTime
|
||||||
image_data.seek(0)
|
def upload_png_mask(front_image, object_name, mask=None):
|
||||||
image_bytes = image_data.read()
|
mask_url = None
|
||||||
# image_url = f"{AIDA_CLOTHING}/{minio_client.put_object('aida-clothing', f'image/image_{object_name}.png', io.BytesIO(image_bytes), len(image_bytes), content_type='image/png').object_name}"
|
if mask is not None:
|
||||||
req = oss_upload_image(bucket=AIDA_CLOTHING, object_name=f"image/image_{object_name}.png", image_bytes=image_bytes)
|
mask_url = f"{AIDA_CLOTHING}/mask/mask_{object_name}.png"
|
||||||
image_url = f"{AIDA_CLOTHING}/image/image_{object_name}.png"
|
image_url = f"{AIDA_CLOTHING}/image/image_{object_name}.png"
|
||||||
return front_image, image_url, mask_url
|
return front_image, image_url, mask_url
|
||||||
except Exception as e:
|
|
||||||
logging.warning(f"upload_png_mask runtime exception : {e}")
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import time
|
|
||||||
import logging
|
import logging
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
def RunTime(func):
|
def RunTime(func):
|
||||||
@@ -12,3 +12,16 @@ def RunTime(func):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
def ClassCallRunTime(func):
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
start_time = time.time()
|
||||||
|
result = func(*args, **kwargs)
|
||||||
|
end_time = time.time()
|
||||||
|
execution_time = end_time - start_time
|
||||||
|
class_name = args[0].__class__.__name__ # 获取类名
|
||||||
|
print(f"class name: {class_name} , run time is : {execution_time} s")
|
||||||
|
return result
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|||||||
Reference in New Issue
Block a user