IOPaint 是一款免费开源的图像修复扩展工具,能帮助用户去除图片中的不需要的物体、瑕疵、人物,或者替换特定对象,进行图像扩展。
IOPaint 支持自我托管,兼容 CPU、GPU 和苹果芯片设备,支持多种 AI 模型来执行擦除、修复或扩展任务:
• 擦除模型:用于移除图片中不需要的物体、瑕疵、水印或人物
• 扩散模型:用于替换物体或进行图像扩展
工具内置了多种实用模型,包括: • RemoveBG:移除图像背景或为前景物体生成遮罩
• Anime Segmentation:专为动漫图像设计的模型,功能类似于 RemoveBG
IOPaint 提供了网页界面,可以使用最新的人工智能模型编辑图片,安装和启动非常简单:
1、如果要使用 GPU,需要安装对应版本的 PyTorch • 对于 NVIDIA GPU 用户:
pip3 install torch==2.1.2 torchvision==0.16.2 --index-url https://download.pytorch.org/whl/cu118
• 对于 AMD GPU 用户(仅限 Linux 系统):
pip3 install torch==2.1.2 torchvision==0.16.2 --index-url https://download.pytorch.org/whl/rocm5.6
2、安装 IOPaint:
pip3 install iopaint
3、启动 IOPaint:
iopaint start --model=lama --device=cpu --port=8080
所有模型将在启动时自动下载,如果需要更改下载目录,可以添加 --model-dir
参数。
插件系统
IOPaint 支持插件扩展,启动服务时可以指定要使用的插件,通过 iopaint start --help
查看启用插件的命令。
批量处理
除了图形界面,IOPaint 还支持命令行批量处理图片:
iopaint run --model=lama --device=cpu \
--image=/path/to/image_folder \
--mask=/path/to/mask_folder \
--output=output_dir
• --image
参数指定包含输入图片的文件夹
• --mask
参数指定对应遮罩图片的文件夹
• 如果 --mask
指向单个遮罩文件,则所有图片都会使用这个遮罩进行处理
开发环境搭建
1、安装 Node.js
2、克隆项目并安装前端依赖:
git clone https://github.com/Sanster/IOPaint.git
cd IOPaint/web_app
npm install
npm run build
cp -r dist/ ../iopaint/web_app
3、在 web_app 文件夹中创建 .env.local
文件并填写后端 IP 和端口:
VITE_BACKEND=http://127.0.0.1:8080
4、启动前端开发环境:
npm run dev
5、安装后端依赖并启动服务:
pip install -r requirements.txt
python3 main.py start --model lama --port 8080
完成后,可以通过 http://localhost:5173/
访问开发中的前端界面,前端代码修改后会自动更新,后端 Python 代码修改后需要重启服务。