【深度学习】fooocusapi,docker,inpainting图像

基础镜像制作来源

fooocusapi接口官方写的:

docker run -d --gpus=all \-e NVIDIA_DRIVER_CAPABILITIES=compute,utility \-e NVIDIA_VISIBLE_DEVICES=all \-p 8888:8888 konieshadow/fooocus-api

会下载一些模型,下载完后推这个镜像

docker commit 4dfd19dd1dc7 kevinchina/deeplearning:fooocusapi-office-v1

写个dockerfile:

FROM kevinchina/deeplearning:fooocusapi-office-v1
EXPOSE 7860
CMD ["python", "main.py", "--host", "0.0.0.0", "--port", "7860", "--skip-pip"]

构建一个新的镜像:

docker build -f Dockerfile . -t kevinchina/deeplearning:fooocusapi-office-v2
docker run -d --gpus=all -p 8881:7860 kevinchina/deeplearning:fooocusapi-office-v2

inpaint还需要下载一些东西,然年成为:

kevinchina/deeplearning:fooocusapi-office-v3

开启镜像

开启方式:

docker run --gpus device=0 -p 7881:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
docker run --gpus device=0 -p 7882:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
docker run --gpus device=1 -p 7883:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
docker run --gpus device=1 -p 7884:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
docker run --gpus device=1 -p 7885:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
docker run --gpus device=2 -p 7886:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
docker run --gpus device=2 -p 7887:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
docker run --gpus device=2 -p 7888:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
docker run --gpus device=3 -p 7889:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
docker run --gpus device=3 -p 7890:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
docker run --gpus device=3 -p 7891:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
docker run --gpus device=3 -p 7892:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
docker run --gpus device=0 -p 8550:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
docker run --gpus device=0 -p 8551:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
docker run --gpus device=1 -p 8552:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
docker run --gpus device=1 -p 8553:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3

多进程请求inpaint:

import base64
import io
import os
import traceback
from multiprocessing import Manager, Poolimport requests
import cv2
import numpy as np
import json
from PIL import Image
from PIL import ImageDraw
import numpy as np
import cv2
import pyclipper
from shapely.geometry import Polygon
# plt显示图
import matplotlib.pyplot as plt
from tqdm import tqdm
import jsondef expand_polygon_pyclipper(polygon, expand_ratio):polygon_shape = Polygon(polygon)distance = (polygon_shape.area * (np.power(expand_ratio, 2) - 1) / polygon_shape.length)subject = [tuple(l) for l in polygon]padding = pyclipper.PyclipperOffset()padding.AddPath(subject, pyclipper.JT_ROUND, pyclipper.ET_CLOSEDPOLYGON)expanded = padding.Execute(distance)if expanded == []:expanded = np.array(expanded)else:expanded = np.array(expanded[0]).reshape(-1, 2)return expandeddef shrink_polygon_pyclipper(polygon, expand_ratio):polygon_shape = Polygon(polygon)distance = (polygon_shape.area * (np.power(expand_ratio, 2) - 1) / polygon_shape.length)subject = [tuple(l) for l in polygon]padding = pyclipper.PyclipperOffset()padding.AddPath(subject, pyclipper.JT_ROUND, pyclipper.ET_CLOSEDPOLYGON)expanded = padding.Execute(-distance)if expanded == []:expanded = np.array(expanded)else:expanded = np.array(expanded[0]).reshape(-1, 2)return expanded# 定义函数
def func(x):return 0.25 * (np.sin(x - np.pi / 2) + 1)# 生成0到pi的10个均匀分布的点
x_values = np.linspace(0, np.pi, 11)[1:][::-1]
y_values = func(x_values) + 1
# print(f"面积{len(y_values)}", y_values)
x_values = np.linspace(0, np.pi, 13)[1:]
weight_inpaint = func(x_values) * 2def draw_heatmap(image, polygons):# 计算函数值并加上1# 搞个和image一样大的二维矩阵inpaint_image_weights = np.zeros(image.shape[:2], dtype=np.float32)for i in range(10):for polygon in polygons:expanded_polygon = expand_polygon_pyclipper(polygon, y_values[i])if expanded_polygon.size > 0:cv2.fillPoly(inpaint_image_weights, [expanded_polygon.astype(np.int32)], weight_inpaint[i])# 收缩0.95区域用白色填充for polygon in polygons:for indx, shk in enumerate([0.99, 0.98]):expanded_polygon = shrink_polygon_pyclipper(polygon, shk)if expanded_polygon.size > 0:cv2.fillPoly(inpaint_image_weights, [expanded_polygon.astype(np.int32)], weight_inpaint[10 + indx])return inpaint_image_weightsdef listPathAllfiles(dirname):result = []for maindir, subdir, file_name_list in os.walk(dirname):for filename in file_name_list:apath = os.path.join(maindir, filename)result.append(apath)return resultdef batch_process(index1, src_image_file, urls):url = urls[index1 % len(urls)]ocr_ret_file = src_image_file.replace(".jpg", ".json")txt_file = src_image_file.replace(".jpg", ".txt")output_image_file = src_image_file.replace(src, save_img_dst_output_image_file)output_image_file_alpha = src_image_file.replace(src, save_img_dst_output_inpaint_alpha)if not os.path.exists(ocr_ret_file):returnif not os.path.exists(txt_file):returnif os.path.exists(output_image_file_alpha):returnoutput_image_file_father = os.path.dirname(output_image_file)os.makedirs(output_image_file_father, exist_ok=True)output_image_file_alpha_father = os.path.dirname(output_image_file_alpha)os.makedirs(output_image_file_alpha_father, exist_ok=True)prompt = open(txt_file, "r", encoding="utf-8").read()if len(prompt) < 7:prompt = "a people"# 造一个mask图片在本地mask_file = "tmp_inpaint_mask.jpg"ocr_json_data = json.load(open(ocr_ret_file, "r", encoding="utf-8"))image = cv2.imread(src_image_file)mask = np.zeros(image.shape, dtype=np.uint8)for item in ocr_json_data:box = item[0]cv2.fillPoly(mask, np.array([box], dtype=np.int32), (255, 255, 255))# cv2.imwrite(mask_file, mask)src_image_file_rb = cv2.imencode('.jpg', image)[1].tobytes()mask_file_rb = cv2.imencode('.jpg', mask)[1].tobytes()# 构建请求的 multipart/form-data 数据files = {'input_image': ('src.jpg', src_image_file_rb, 'image/jpeg'),'input_mask': ('mask.jpg', mask_file_rb, 'image/jpeg')}data = {'prompt': prompt,'negative_prompt': 'big nose, watermark, signature, label, worst quality, low quality, normal quality, lowres, watermark, monochrome, grayscale, ugly, blurry, Tan skin, dark skin, black skin, skin spots, skin blemishes, age spot, glans, disabled, distorted, bad anatomy, morbid, malformation, amputation, bad proportions, twins, missing body, fused body, extra head, poorly drawn face, bad eyes, deformed eye, unclear eyes, cross-eyed, long neck, malformed limbs, extra limbs, extra arms, missing arms, bad tongue, strange fingers, mutated hands, missing hands, poorly drawn hands, extra hands, fused hands, connected hand, bad hands, wrong fingers, missing fingers, extra fingers, 4 fingers, 3 fingers, deformed hands, extra legs, bad legs, many legs, more than two legs, bad feet, wrong feet, extra feets, Negro, black people, black race','sharpness': '10','guidance_scale': '5','outpaint_distance_right': '0','loras': '[{"enabled":true,"model_name":"sd_xl_offset_example-lora_1.0.safetensors","weight":0.1}]','outpaint_distance_left': '0','outpaint_distance_bottom': '0','image_number': '1','negative_prompt': 'bad','refiner_switch': '0.5','base_model_name': 'juggernautXL_v8Rundiffusion.safetensors','image_seed': '-1','style_selections': ['Fooocus V2', 'Fooocus Enhance', 'Fooocus Sharp'],'inpaint_additional_prompt': '','outpaint_selections': '','refiner_model_name': 'None','aspect_ratios_selection': '1024*1024','performance_selection': 'Speed','require_base64': True,'async_process': False,}headers = {'accept': 'application/json'}try:if len(ocr_json_data) > 0:response = requests.post(url, files=files, data=data, headers=headers)postres = response.json()b64 = postres[0]["base64"]# 将base64字符串解码并保存为图像文件imgdata = base64.b64decode(b64)with open(output_image_file, 'wb') as f:f.write(imgdata)# print(f"Output image saved as {output_image_file}")# pillow讲b64直接转为imageimage_inpaint = Image.open(io.BytesIO(imgdata)).convert('RGB')image_inpaint_cv2 = np.array(image_inpaint)image_inpaint_cv2 = cv2.cvtColor(image_inpaint_cv2, cv2.COLOR_RGB2BGR)# 和原图进行alpha混合text_polys = []for item in ocr_json_data:box = item[0]text_polys.append(np.array(box))alpha = draw_heatmap(image, text_polys)inpaint_image_weights = alpha[:, :, np.newaxis]# print(inpaint_image_weights.shape)new_image = image_inpaint_cv2 * inpaint_image_weights + image * (1 - inpaint_image_weights)cv2.imwrite(output_image_file_alpha, new_image)else:# 直接写入cv2.imwrite(output_image_file_alpha, image)except:print(ocr_ret_file)if __name__ == '__main__':src = r"/ssd/xiedong/xiezhenceshi/xiezhen_datasets"save_img_dst_output_image_file = r"/ssd/xiedong/xiezhenceshi/inpaint_output_image_file"save_img_dst_output_inpaint_alpha = r"/ssd/xiedong/xiezhenceshi/inpaint_alpha2"os.makedirs(save_img_dst_output_image_file, exist_ok=True)os.makedirs(save_img_dst_output_inpaint_alpha, exist_ok=True)files = listPathAllfiles(src)files.sort()files = [file for file in files if file.endswith(".jpg")][5304:]tasks = list(enumerate(files))urlname = 'http://10.136.19.26:port/v1/generation/image-inpaint-outpaint'urlsx = []for i in range(7881, 7893):urlsx.append(urlname.replace("port", str(i)))for i in range(8550, 8554):urlsx.append(urlname.replace("port", str(i)))# 去掉7889urlsx.remove('http://10.136.19.26:7889/v1/generation/image-inpaint-outpaint')for i in urlsx:print(i)with Manager() as manager:lock = manager.Lock()with Pool(processes=len(urlsx)) as pool:# 传递 lock 到 process_user_prompt 函数pool.starmap(batch_process,[(index, file, urlsx) for index, file in tasks])# docker run --gpus device=0 -p 7881:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
# docker run --gpus device=0 -p 7882:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
# docker run --gpus device=1 -p 7883:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
# docker run --gpus device=1 -p 7884:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
# docker run --gpus device=1 -p 7885:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
# docker run --gpus device=2 -p 7886:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
# docker run --gpus device=2 -p 7887:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
# docker run --gpus device=2 -p 7888:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
# docker run --gpus device=3 -p 7889:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
# docker run --gpus device=3 -p 7890:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
# docker run --gpus device=3 -p 7891:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
# docker run --gpus device=3 -p 7892:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
# docker run --gpus device=0 -p 8550:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
# docker run --gpus device=0 -p 8551:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
# docker run --gpus device=1 -p 8552:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3
# docker run --gpus device=1 -p 8553:7860 -d  kevinchina/deeplearning:fooocusapi-office-v3

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/47816.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

typer 模块与装饰器

当使用 Typer 模块时&#xff0c;可以创建一个简单的命令行应用程序示例。以下是一个使用 Typer 创建的示例&#xff1a; import typerapp typer.Typer()app.command() def greet(name: str):typer.echo(f"Hello, {name}!")app.command() def answer(name: str):ty…

Linux入门以及Linux文件编程学习

Linux学习必备 首先我们学习Linux必须安装一个虚拟机&#xff0c;我是跟着韦东山老师安装的&#xff0c;具体可以跟着视频操作&#xff0c;简单易懂&#xff1a;安装虚拟机 Linux入门最基本简单的指令 一、Vi的使用 Vi文件名 创建或者打开一个文件&#xff0c;进入默认命令行…

notes for datawhale summer camp NPL task3

了解 Transformer 模型&#xff0c;并基于 Transformer 模型实现在机器翻译任务上的应用&#xff01; Transformer 介绍 基于循环或卷积神经网络的序列到序列建模方法是现存机器翻译任务中的经典方法。然而&#xff0c;它们在建模文本长程依赖方面都存在一定的局限性。 为了…

Java多线程游戏——坦克大战

一.游戏登陆界面 package TankFight;import javax.swing.*; import java.awt.*;public class GameUI {public void initUI() {JFrame jf new JFrame();jf.setSize(1100, 900);//设置窗口大小jf.setTitle("坦克大战" );//设置窗口标题jf.setLocationRelativeTo(null…

[PM]产品运营

生命周期 运营阶段 主要工作 拉新 新用户的定义 冷启动 拉新方式 促活 用户活跃的原因 量化活跃度 运营社区化/内容化 留存 用户流失 培养用户习惯 用户挽回 变现 变现方式 付费模式 广告模式 数据变现 变现指标 传播 营销 认识营销 电商营销中心 拼团活动 1.需求整理 2.…

大数据之路 读书笔记 Day7 实时技术 简介及流式技术架构

回顾&#xff1a; Day6 离线数据开发之数据开发平台Day5 数据同步遇到的问题与解决方案 1. 简介 阿里巴巴在流式数据处理方面采用了多种技术和框架&#xff0c;这些技术的特点包括&#xff1a; 高可伸缩性&#xff1a; 阿里巴巴使用Apache Flink进行大规模数据处理&#xff0c…

docker 容器内安装pdo_mysql扩展

1. 首先确定php配置文件&#xff08;php.ini&#xff09;打开了pdo_mysql注释。&#xff08;php.ini位置&#xff1a;运行容器时挂载文件时&#xff0c;指定的php.ini位置&#xff09; 2. 进入倒php容器内&#xff1a;docker exec -it 容器名 bash 3. 确认php扩展目录没有pdo…

Springboot项目远程部署gitee仓库(docker+Jenkins+maven+git)

创建仓库 创建一个Springboot项目&#xff0c;勾选web将该项目创建git本地仓库&#xff0c;再创建远程仓库推送上去 创建TestController RestControllerRequestMapping("/test")public class TestController {GetMapping("/hello")public String sayHell…

6.Kafka Acks详解

目录 概述Replication(分区副本)In-sync replicasAcknowledgementsacks0acks1acksallAck实用建议Minimum in-sync replicaCaveat(警告) 概述 本文对 kafka 的一些核心概念进行解释&#xff0c;也是 kafka 需要调优的一些地方。 官方原文速递 Replication(分区副本) 对于每个分…

如何识别Android init 中的缓慢操作

Android 14 开机时间优化措施汇总-CSDN博客 Android 14 开机时间优化措施-CSDN博客根据systrace报告优化系统时需要关注的指标和优化策略-CSDN博客Android系统上常见的性能优化工具-CSDN博客Android上如何使用perfetto分析systrace-CSDN博客Android系统设置kernel log level的…

222.买卖股票的最佳时机(力扣)

代码解决 class Solution { public:int maxProfit(vector<int>& prices) {// 初始化最小买入价为第一个价格int min1 prices[0];// 初始化最大利润为0int max1 0;// 从第二天开始遍历价格数组for (int i 1; i < prices.size(); i) {// 计算当前价卖出的利润&a…

windows edge自带的pdf分割工具(功能)

WPS分割pdf得会员&#xff0c;要充值&#xff01;网上一顿乱找&#xff0c;发现最简单&#xff0c;最好用&#xff0c;免费的还是回到Windows。 Windows上直接在edge浏览器打开PDF&#xff0c;点击 打印 按钮,页面下选择对应页数 打印机 选择 另存为PDF&#xff0c;然后保存就…

硬件开发——UART/I2C/SPI协议

硬件开发——UART/I2C/SPI协议 小狼http://blog.csdn.net/xiaolangyangyang 1、UART 电压&#xff1a; TTL电平&#xff1a;1&#xff1a;&#xff08;3.3V~5V&#xff09;&#xff0c;0&#xff1a;&#xff08;0V&#xff09;RS232电平&#xff1a;1&#xff1a;&#xff0…

【C++题解】1212. 移动数组元素

问题&#xff1a;1212. 移动数组元素 类型&#xff1a;数组找数 题目描述&#xff1a; 在一个不重复的数组中&#xff0c;请将这个数组的最小数和数组第一个数交换&#xff0c;最大数和数组最后一个数交换。 输入&#xff1a; 第一行有一个整数 n ( 5≤n≤100 &#xff09;…

Windows 11登录密码遗忘后如何在登录

在现代社会中&#xff0c;随着信息技术的迅猛发展&#xff0c;计算机操作系统如Windows 11已经成为我们日常生活和工作中不可或缺的一部分。然而&#xff0c;有时我们可能会遇到忘记登录密码的尴尬情况。为了帮助大家解决这个问题&#xff0c;本文将详细讲解如何快速破解Window…

浅谈端到端(自动驾驶)

一、 引言 端到端是近期非常火的话题&#xff0c;尤其在自动驾驶、具身智能等领域。去年UniAD的发布&#xff0c;给大家普及了端到端的网络设计&#xff0c;带动了行业的发展。产业界&#xff0c;特斯拉FSD Beta V12效果惊艳&#xff0c;近期理想也推出了双系统的E2E自动驾驶系…

MySQL 分组函数

目录 1. 单/多行处理 2. 分组函数分类 3. 分组函数组合使用 4. 注意 1. 单/多行处理 分组函数又被叫做多行处理函数&#xff08;多个输入&#xff0c;一个输出&#xff09;&#xff1b; 前面提到的数据处理函数又叫做单行处理函数&#xff08;一个输入&#xff0c;一个输出…

<Qt> 信号和槽

目录 一、信号和槽概述 二、信号和槽的使用​​​​​​ &#xff08;一&#xff09;connect函数 &#xff08;二&#xff09;实现一个点击按钮关闭窗口的功能 &#xff08;三&#xff09;再谈connect 三、自定义槽函数 四、自定义信号 五、带参数的信号和槽 六、信号…

哈喽GPT-4o,程序员如何通过GPT-4o保护自己的合法权益

目录 一、法律研究Prompt&#xff1a;派遣合同和劳务外包合同有什么区别&#xff1f;详细说一下在被裁员时的区别&#xff1f; 二、法律条文检索Prompt&#xff1a;检索《劳动合同法》&#xff0c;以下情况属于第几条&#xff0c;如果公司进行技能考试&#xff0c;并以技能考试…

在Ubuntu上安装redis

Ubuntu上安装redis 一、通过下载redis的压缩包安装二、通过apt包管理器安装Redis三、修改redis的配置文件四、控制redis启动 Redis是一种开源的内存数据存储&#xff0c;可以用作数据库、缓存和消息代理等。本文将会介绍两种不同的安装方式&#xff0c;包括通过压缩包安装以及通…