feat 4090 triton server 测试
fix
This commit is contained in:
@@ -117,10 +117,10 @@ GEN_SINGLE_LOGO_RABBITMQ_QUEUES = os.getenv("GEN_SINGLE_LOGO_RABBITMQ_QUEUES", f
|
|||||||
|
|
||||||
# Generate Product service config
|
# Generate Product service config
|
||||||
GPI_RABBITMQ_QUEUES = os.getenv("GEN_PRODUCT_IMAGE_RABBITMQ_QUEUES", f"ToProductImage{RABBITMQ_ENV}")
|
GPI_RABBITMQ_QUEUES = os.getenv("GEN_PRODUCT_IMAGE_RABBITMQ_QUEUES", f"ToProductImage{RABBITMQ_ENV}")
|
||||||
GPI_MODEL_NAME_OVERALL = 'diffusion_ensemble_all'
|
GPI_MODEL_NAME_OVERALL = 'stable_diffusion_xl_cnet'
|
||||||
GPI_MODEL_NAME_SINGLE = 'stable_diffusion_1_5_cnet'
|
GPI_MODEL_NAME_SINGLE = 'stable_diffusion_xl_cnet'
|
||||||
|
|
||||||
GPI_MODEL_URL = '10.1.1.240:10041'
|
GPI_MODEL_URL = '10.1.1.243:10051'
|
||||||
|
|
||||||
# Generate Single Logo service config
|
# Generate Single Logo service config
|
||||||
GRI_RABBITMQ_QUEUES = os.getenv("GEN_RELIGHT_IMAGE_RABBITMQ_QUEUES", f"Relight{RABBITMQ_ENV}")
|
GRI_RABBITMQ_QUEUES = os.getenv("GEN_RELIGHT_IMAGE_RABBITMQ_QUEUES", f"Relight{RABBITMQ_ENV}")
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import cv2
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import redis
|
import redis
|
||||||
import tritonclient.grpc as grpcclient
|
import tritonclient.grpc as grpcclient
|
||||||
from PIL import Image, ImageOps
|
from PIL import Image
|
||||||
from tritonclient.utils import np_to_triton_dtype
|
from tritonclient.utils import np_to_triton_dtype
|
||||||
|
|
||||||
from app.core.config import *
|
from app.core.config import *
|
||||||
@@ -41,7 +41,7 @@ class GenerateProductImage:
|
|||||||
self.batch_size = 1
|
self.batch_size = 1
|
||||||
self.product_type = request_data.product_type
|
self.product_type = request_data.product_type
|
||||||
self.prompt = request_data.prompt
|
self.prompt = request_data.prompt
|
||||||
self.image, self.image_size = pre_processing_image(request_data.image_url)
|
self.image, self.image_size, self.left, self.top = pre_processing_image(request_data.image_url)
|
||||||
self.tasks_id = request_data.tasks_id
|
self.tasks_id = request_data.tasks_id
|
||||||
self.user_id = self.tasks_id[self.tasks_id.rfind('-') + 1:]
|
self.user_id = self.tasks_id[self.tasks_id.rfind('-') + 1:]
|
||||||
self.gen_product_data = {'tasks_id': self.tasks_id, 'status': 'PENDING', 'message': "pending", 'image_url': ''}
|
self.gen_product_data = {'tasks_id': self.tasks_id, 'status': 'PENDING', 'message': "pending", 'image_url': ''}
|
||||||
@@ -58,9 +58,10 @@ class GenerateProductImage:
|
|||||||
if self.product_type == "single":
|
if self.product_type == "single":
|
||||||
image = result.as_numpy("generated_cnet_image")
|
image = result.as_numpy("generated_cnet_image")
|
||||||
else:
|
else:
|
||||||
image = result.as_numpy("generated_inpaint_image")
|
image = result.as_numpy("generated_cnet_image")
|
||||||
image_result = Image.fromarray(np.squeeze(image.astype(np.uint8))).resize(self.image_size)
|
image_result = Image.fromarray(np.squeeze(image.astype(np.uint8))).resize(self.image_size)
|
||||||
image_url = upload_SDXL_image(image_result, user_id=self.user_id, category=f"{self.category}", file_name=f"{self.tasks_id}.png")
|
cropped_image = post_processing_image(image_result, self.left, self.top)
|
||||||
|
image_url = upload_SDXL_image(cropped_image, user_id=self.user_id, category=f"{self.category}", file_name=f"{self.tasks_id}.png")
|
||||||
self.gen_product_data['status'] = "SUCCESS"
|
self.gen_product_data['status'] = "SUCCESS"
|
||||||
self.gen_product_data['message'] = "success"
|
self.gen_product_data['message'] = "success"
|
||||||
self.gen_product_data['image_url'] = str(image_url)
|
self.gen_product_data['image_url'] = str(image_url)
|
||||||
@@ -74,7 +75,7 @@ class GenerateProductImage:
|
|||||||
try:
|
try:
|
||||||
prompts = [self.prompt] * self.batch_size
|
prompts = [self.prompt] * self.batch_size
|
||||||
self.image = cv2.cvtColor(self.image, cv2.COLOR_BGR2RGB)
|
self.image = cv2.cvtColor(self.image, cv2.COLOR_BGR2RGB)
|
||||||
self.image = cv2.resize(self.image, (512, 768))
|
self.image = cv2.resize(self.image, (1024, 1024))
|
||||||
images = [self.image.astype(np.uint8)] * self.batch_size
|
images = [self.image.astype(np.uint8)] * self.batch_size
|
||||||
|
|
||||||
if self.product_type == "single":
|
if self.product_type == "single":
|
||||||
@@ -82,9 +83,9 @@ class GenerateProductImage:
|
|||||||
image_obj = np.array(images, dtype=np.uint8).reshape((-1, 768, 512, 3))
|
image_obj = np.array(images, dtype=np.uint8).reshape((-1, 768, 512, 3))
|
||||||
image_strength_obj = np.array(self.image_strength, dtype=np.float32).reshape(-1, 1)
|
image_strength_obj = np.array(self.image_strength, dtype=np.float32).reshape(-1, 1)
|
||||||
else:
|
else:
|
||||||
text_obj = np.array(prompts, dtype="object").reshape(1)
|
text_obj = np.array(prompts, dtype="object").reshape((-1, 1))
|
||||||
image_obj = np.array(images, dtype=np.uint8).reshape((768, 512, 3))
|
image_obj = np.array(images, dtype=np.uint8).reshape((-1, 1024, 1024, 3))
|
||||||
image_strength_obj = np.array(self.image_strength, dtype=np.float32).reshape((1))
|
image_strength_obj = np.array(self.image_strength, dtype=np.float32).reshape((-1, 1))
|
||||||
|
|
||||||
# 假设 prompts、images 和 self.image_strength 已经定义
|
# 假设 prompts、images 和 self.image_strength 已经定义
|
||||||
|
|
||||||
@@ -136,22 +137,13 @@ def infer_cancel(tasks_id):
|
|||||||
|
|
||||||
def pre_processing_image(image_url):
|
def pre_processing_image(image_url):
|
||||||
image = oss_get_image(bucket=image_url.split('/')[0], object_name=image_url[image_url.find('/') + 1:], data_type="PIL")
|
image = oss_get_image(bucket=image_url.split('/')[0], object_name=image_url[image_url.find('/') + 1:], data_type="PIL")
|
||||||
|
# resize 原图至1024*1024
|
||||||
|
image = image.resize((int(1024 / image.height * image.width), 1024))
|
||||||
|
|
||||||
# 原始图片的尺寸
|
# 原始图片的尺寸
|
||||||
width, height = image.size
|
width, height = image.size
|
||||||
|
|
||||||
# 计算长宽比为 3:2 的新尺寸
|
new_height, new_width = 1024, 1024
|
||||||
desired_ratio = 2 / 3
|
|
||||||
current_ratio = width / height
|
|
||||||
|
|
||||||
if current_ratio > desired_ratio:
|
|
||||||
# 原始图片更宽,需要在上下添加 padding
|
|
||||||
new_width = width
|
|
||||||
new_height = int(width / desired_ratio)
|
|
||||||
else:
|
|
||||||
# 原始图片更高或者长宽比已经为 3:2
|
|
||||||
new_height = height
|
|
||||||
new_width = int(height * desired_ratio)
|
|
||||||
|
|
||||||
# 创建一个新的画布,大小为添加 padding 后的尺寸,并设置为白色背景
|
# 创建一个新的画布,大小为添加 padding 后的尺寸,并设置为白色背景
|
||||||
pad_image = Image.new('RGBA', (new_width, new_height), (0, 0, 0, 0))
|
pad_image = Image.new('RGBA', (new_width, new_height), (0, 0, 0, 0))
|
||||||
|
|
||||||
@@ -160,9 +152,9 @@ def pre_processing_image(image_url):
|
|||||||
top = (new_height - height) // 2
|
top = (new_height - height) // 2
|
||||||
pad_image.paste(image, (left, top))
|
pad_image.paste(image, (left, top))
|
||||||
|
|
||||||
# 将画布 resize 成宽度 500,长度 750
|
# 将画布 resize 成宽度 1024,长度 1024
|
||||||
resized_image = pad_image.resize((500, 750))
|
resized_image = pad_image.resize((1024, 1024))
|
||||||
image_size = (512, 768)
|
image_size = (1024, 1024)
|
||||||
|
|
||||||
if resized_image.mode in ('RGBA', 'LA') or (resized_image.mode == 'P' and 'transparency' in resized_image.info):
|
if resized_image.mode in ('RGBA', 'LA') or (resized_image.mode == 'P' and 'transparency' in resized_image.info):
|
||||||
# 创建白色背景
|
# 创建白色背景
|
||||||
@@ -171,15 +163,28 @@ def pre_processing_image(image_url):
|
|||||||
background.paste(resized_image, mask=resized_image.split()[3])
|
background.paste(resized_image, mask=resized_image.split()[3])
|
||||||
image = np.array(background)
|
image = np.array(background)
|
||||||
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
||||||
return image, image_size
|
return image, image_size, left, top
|
||||||
|
|
||||||
|
|
||||||
|
def post_processing_image(image, left, top):
|
||||||
|
width, height = image.size
|
||||||
|
# 计算裁剪后的宽度和坐标
|
||||||
|
new_width = width - 2 * left
|
||||||
|
right = left + new_width
|
||||||
|
|
||||||
|
# 进行裁剪操作
|
||||||
|
cropped_image = image.crop((left, 0, right, height))
|
||||||
|
|
||||||
|
# 保存裁剪后的图像,将此处的 'cropped_image.jpg' 替换为你想要保存的文件名
|
||||||
|
return cropped_image
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
rd = GenerateProductImageModel(
|
rd = GenerateProductImageModel(
|
||||||
tasks_id="123-89",
|
tasks_id="123-89",
|
||||||
# prompt="",
|
# prompt="",
|
||||||
image_strength=0.9,
|
image_strength=0.65,
|
||||||
prompt=" the best quality, masterpiece. detailed, high-res, simple background, studio photography, extremely detailed, updo, detailed face, face, close-up, HDR, UHD, 8K realistic, Highly detailed, simple background, Studio lighting",
|
prompt="The best quality, masterpiece, real image. A handsome man wearing blouse, outwear, trousers, 8K realistic, HUD",
|
||||||
image_url="aida-results/result_00097282-ebb2-11ee-a822-b48351119060.png",
|
image_url="aida-results/result_00097282-ebb2-11ee-a822-b48351119060.png",
|
||||||
product_type="overall"
|
product_type="overall"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ if __name__ == '__main__':
|
|||||||
# url = "aida-users/89/sketchboard/female/Dress/e6724ab7-8d3f-4677-abe0-c3e42ab7af85.jpeg"
|
# url = "aida-users/89/sketchboard/female/Dress/e6724ab7-8d3f-4677-abe0-c3e42ab7af85.jpeg"
|
||||||
# url = "aida-users/87/print/956614a2-7e75-4fbe-9ed0-c1831e37a2c9-4-87.png"
|
# url = "aida-users/87/print/956614a2-7e75-4fbe-9ed0-c1831e37a2c9-4-87.png"
|
||||||
# url = "aida-users/89/single_logo/123-89.png"
|
# url = "aida-users/89/single_logo/123-89.png"
|
||||||
url ="aida-results/result_91559b60-a61c-11ef-af8e-0242ac150002.png"
|
url ="aida-results/result_27915298-a656-11ef-b4f3-0242ac150002.png"
|
||||||
|
|
||||||
# url = "aida-collection-element/12148/Sketchboard/95ea577b-305b-4a62-b30a-39c0dd3ddb3f.png"
|
# url = "aida-collection-element/12148/Sketchboard/95ea577b-305b-4a62-b30a-39c0dd3ddb3f.png"
|
||||||
read_type = "2"
|
read_type = "2"
|
||||||
|
|||||||
Reference in New Issue
Block a user