feat generate img fast version 部署
fix
This commit is contained in:
@@ -35,7 +35,11 @@ class GenerateImage:
|
||||
# self.connection = pika.BlockingConnection(pika.ConnectionParameters(**RABBITMQ_PARAMS))
|
||||
# self.channel = self.connection.channel()
|
||||
# self.minio_client = Minio(MINIO_URL, access_key=MINIO_ACCESS, secret_key=MINIO_SECRET, secure=MINIO_SECURE)
|
||||
self.grpc_client = grpcclient.InferenceServerClient(url=GI_MODEL_URL)
|
||||
if request_data.version == "fast":
|
||||
self.grpc_client = grpcclient.InferenceServerClient(url=FAST_GI_MODEL_URL)
|
||||
else:
|
||||
self.grpc_client = grpcclient.InferenceServerClient(url=GI_MODEL_URL)
|
||||
|
||||
self.redis_client = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB, decode_responses=True)
|
||||
if request_data.mode == "img2img":
|
||||
# cv2 读图片是BGR PIL读图片是RGB
|
||||
@@ -185,7 +189,8 @@ if __name__ == '__main__':
|
||||
image_url="aida-collection-element/87/Printboard/842c09cf-7297-42d9-9e6e-9c17d4a13cb5.jpg",
|
||||
mode='txt2img',
|
||||
category="test",
|
||||
gender="male"
|
||||
gender="male",
|
||||
version="fast"
|
||||
)
|
||||
server = GenerateImage(rd)
|
||||
print(server.get_result())
|
||||
|
||||
@@ -55,7 +55,10 @@ class GenerateProductImage:
|
||||
self.redis_client.set(self.tasks_id, json.dumps(self.gen_product_data))
|
||||
else:
|
||||
# pil图像转成numpy数组
|
||||
image = result.as_numpy("generated_inpaint_image")
|
||||
if self.product_type == "single":
|
||||
image = result.as_numpy("generated_inpaint_image")
|
||||
else:
|
||||
image = result.as_numpy("generated_cnet_image")
|
||||
image_result = Image.fromarray(np.squeeze(image.astype(np.uint8))).resize(self.image_size)
|
||||
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")
|
||||
@@ -75,9 +78,14 @@ class GenerateProductImage:
|
||||
self.image = cv2.resize(self.image, (1024, 1024))
|
||||
images = [self.image.astype(np.uint8)] * self.batch_size
|
||||
|
||||
text_obj = np.array(prompts, dtype="object").reshape((1))
|
||||
image_obj = np.array(images, dtype=np.uint8).reshape((1024, 1024, 3))
|
||||
image_strength_obj = np.array(self.image_strength, dtype=np.float32).reshape((1))
|
||||
if self.product_type == "single":
|
||||
text_obj = np.array(prompts, dtype="object").reshape(-1, 1)
|
||||
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, 1)
|
||||
else:
|
||||
text_obj = np.array(prompts, dtype="object").reshape((1))
|
||||
image_obj = np.array(images, dtype=np.uint8).reshape((1024, 1024, 3))
|
||||
image_strength_obj = np.array(self.image_strength, dtype=np.float32).reshape((1))
|
||||
|
||||
# 假设 prompts、images 和 self.image_strength 已经定义
|
||||
|
||||
@@ -91,7 +99,11 @@ class GenerateProductImage:
|
||||
|
||||
inputs = [input_text, input_image, input_image_strength]
|
||||
|
||||
ctx = self.grpc_client.async_infer(model_name=GPI_MODEL_NAME_OVERALL, inputs=inputs, callback=self.callback)
|
||||
|
||||
if self.product_type == "single":
|
||||
ctx = self.grpc_client.async_infer(model_name="stable_diffusion_xl_cnet_inpaint", inputs=inputs, callback=self.callback)
|
||||
else:
|
||||
ctx = self.grpc_client.async_infer(model_name=GPI_MODEL_NAME_OVERALL, inputs=inputs, callback=self.callback)
|
||||
|
||||
time_out = 600
|
||||
while time_out > 0:
|
||||
@@ -173,10 +185,10 @@ if __name__ == '__main__':
|
||||
rd = GenerateProductImageModel(
|
||||
tasks_id="123-89",
|
||||
# prompt="",
|
||||
image_strength=0.65,
|
||||
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",
|
||||
product_type="overall"
|
||||
image_strength=0.7,
|
||||
prompt="The best quality, masterpiece,outwear, 8K realistic, HUD",
|
||||
image_url="aida-results/result_836dce70-ad59-11ef-86ab-0242ac130002.png",
|
||||
product_type="single"
|
||||
)
|
||||
server = GenerateProductImage(rd)
|
||||
print(server.get_result())
|
||||
print(server.get_result())
|
||||
Reference in New Issue
Block a user