Skip to content

Lama Cleaner 使用指南

运行

  • 先切换到 venv 环境:source venv/bin/activate,没有先创建。

  • 然后根据电脑情况选择模型:

  1. CPU 模式:lama-cleaner --model=lama --device=cpu --port=8080 --host=0.0.0.0
  2. GPU 模式:lama-cleaner --model=lama --device=cuda --port=8080 --host=0.0.0.0
  • 运行界面

运行界面

基本用法

安装&错误处理

环境准备

  • Python 3.10.0:下载地址 https://www.python.org/downloads/
  • Rust/Cargo :安装地址 https://www.rust-lang.org/learn/get-started

下载lama-cleaner

pip install lama-cleaner

如果在Mac上安装失败,如:

bash
Building wheels for collected packages: tokenizers
  Building wheel for tokenizers (pyproject.toml) ...
...
...
...
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
         --> tokenizers-lib/src/models/bpe/trainer.rs:526:47
          |
      522 |                     let w = &words[*i] as *const _ as *mut _;
          |                             -------------------------------- casting happend here
      ...
      526 |                         let word: &mut Word = &mut (*w);
          |                                               ^^^^^^^^^
          |
          = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
          = note: `#[deny(invalid_reference_casting)]` on by default

      warning: `tokenizers` (lib) generated 3 warnings
      error: could not compile `tokenizers` (lib) due to 1 previous error; 3 warnings emitted
...
...
...
note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for tokenizers
Failed to build tokenizers
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (tokenizers)

解决方法:

  • 1.create a empty dir;
  • 2.enter this dir;
  • 3.create a clean venv:
shell
python3 -m venv venv
source venv/bin/activate
  • 4.pip install lama-cleaner

如果自动安装模型失败:

手动下载模型:curl -L -o big-lama.pt https://github.com/Sanster/models/releases/download/add_big_lama/big-lama.pt

然后将它放到指定目录下: Mac目录:mv big-lama.pt /Users/YOUR_USER_NAME/.cache/torch/hub/checkpoints/ Windows目录:mv big-lama.pt C:\Users\YOUR_USER_NAME\.cache\torch\hub\checkpoints\

修改了文件夹名称后运行lama-cleaner报错:命令不存在

原因

更改文件夹名称后,原来的虚拟环境路径会失效。解决方法是重新创建虚拟环境并重新安装所有依赖。这样可以确保所有路径都是正确的,并且所有依赖都能正常工作。

解决方法:

  • 步骤 1:重新创建虚拟环境 rm -rf /Users/fatiaoya/codedev/wc/AI/lama_cleaner/venv

  • 步骤 2:在新位置重新创建虚拟环境

cd /Users/fatiaoya/codedev/wc/AI/lama_cleaner
python3 -m venv venv
source venv/bin/activate
  • 步骤 3:重新安装 lama-cleaner

pip install lama-cleaner

如果GPU模式启动失败

说明电脑没有CUDA版本的Pytorch,请安装CUDA版本的Pytorch。

个性化安装CUDA版本的Pytorch,下载页面:https://pytorch.org/get-started/locally/

如果上面的链接没有对应版本,访问链接:https://pytorch.org/get-started/previous-versions/

比如CUDA版本12.1:pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

查看CUDA版本的方法:打开CMD命令行,输入:nvidia-smi 查看CUDA版本。

参考链接:

1.https://lama-cleaner-docs.vercel.app/install/pip

2.https://github.com/Sanster/lama-cleaner-docs/issues/21

3.https://blog.csdn.net/Changxing_J/article/details/128604798

Released under the MIT License.