一、创建lama Cleaner的bat文件,内容如下:
@echo off
pushd %~dp0
if not exist .\Tool\ ( mkdir .\Tool\ )
pushd .\Tool\
if not exist .\lama-cleaner\ (
mkdir .\lama-cleaner\
pushd .\lama-cleaner\
python -m venv venv
call venv\Scripts\activate
python -m pip install --upgrade pip
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
pip install lama-cleaner
popd
)
pushd .\lama-cleaner\
start http://localhost:7859/
call venv\Scripts\activate
echo http://localhost:7859/
lama-cleaner --model=lama --port=7859 --device=cuda --enable-interactive-seg --interactive-seg-model=vit_l --interactive-seg-device=cuda --enable-remove-bg --enable-realesrgan --realesrgan-model RealESRGAN_x4plus --realesrgan-device cuda
popd
popd
popd
二、上面代码中--enable-interactive-seg --interactive-seg-model=vit_l --interactive-seg-device=cuda --enable-remove-bg --enable-realesrgan --realesrgan-model RealESRGAN_x4plus --realesrgan-device cuda这些参数都是插件,需要手动安装,方法如下:
1、进入目录\Tool\lama-cleaner\venv\Scripts\,这是Python虚拟环境的安装目录,执行以下代码安装插件(这个安装命令在官网 https://lama-cleaner-docs.vercel.app/plugins 处寻找,安装什么插件就用什么指令)
\python.exe -m pip install realesrgan
2、等待安装完毕,再执行上面那个bat文件即可。每次打开lama都需要执行这个bat。