python -m pip install --upgrade pip\n\n### 2. 安装rembg\n\n`bash\npip install rembg\n`\n\n如需GPU加速(NVIDIA显卡),额外安装onnxruntime-gpu:\n`bash\npip install onnxruntime-gpu\n`\n\n### 3. 模型文件下载与放置\n\nrembg默认在首次运行时自动下载ONNX模型至~/.u2net目录。若需离线部署,可手动下载(官方GitHub Releases提供u2net.onnx、u2netp.onnx、u2nethumanseg.onnx等),并放置到对应目录。\n\n### 4. 验证安装\n\n`python\nfrom rembg import remove\ninputpath = 'test.jpg'\noutput = remove(open(inputpath, 'rb').read())\nopen('output.png', 'wb').write(output)\n`\n若运行后得到透明背景的PNG,则说明安装成功。\n\n### 5. 其他备选模型安装\n\n- MODNet:实时人像抠图模型,尺寸小、速度快,适合移动端。从GitHub克隆源码后,安装Python依赖并下载预训练模型。\n- Brave(ResNet网络) :可通过pip install backgroundremover安装,然后执行backgroundremover -i input.jpg -o output.png。\n\n选择建议:对通用物体优先选U^2-Net;人像自拍可取MODNet,加速比明显。模型统一支持推理验证,说明可靠性一致。\n\n## 三、选区范围抠图技巧\n\nAI工具虽能自动估算alpha遮罩,但在细节区域容易出现瑕疵(边缘不平滑或有不符合调度的残留)。要通过如若转载,请注明出处:http://www.boluoqiu.com/product/68.html
更新时间:2026-12-01 05:54:52
PRODUCT