---
title: RemoveAnything
canonical_url: "https://www.modelscope.cn/models/sisgog/RemoveAnything"
md_url: "https://www.modelscope.cn/models/sisgog/RemoveAnything.md"
repository: sisgog/RemoveAnything
chinese_name: RemoveAnythingInt4
last_updated: 2025-12-26
pipeline_tag: image-to-image
tasks:
  - image-to-image
parameters: 179.3M
tensor_type:
  - BF16
library_name:
  - safetensors
  - pytorch
frameworks:
  - Pytorch
downloads: 34
stars: 2
---

# RemoveAnything

> RemoveAnything - sisgog 在 ModelScope 开源的模型。消除，remove, erase，万物。结合nano banana pro, 效果更全面。

- **Repository**: sisgog/RemoveAnything
- **Tasks**: image-to-image
- **Parameters**: 179.3M
- **Downloads**: 34
- **Stars**: 2
- **Last updated**: 2025-12-26

Source: https://www.modelscope.cn/models/sisgog/RemoveAnything

---

# RemoveAnythingSimplify

基于 FLUX.1-Fill-dev 和 SAM2 的智能图像修复工具，支持物体移除、智能分割等功能。所有代码：[RemoveAnythingSimplify](https://github.com/foocker/RemoveAnythingSimplify)

## 主要功能

- **物体移除**: 使用 FLUX.1-Fill-dev + LoRA 实现高质量的物体消除和图像修复
- **智能分割**: 基于 SAM2 的交互式图像分割，支持点击和框选
- **模型训练**: 支持 Flux LoRA 模型训练，可自定义训练数据
- **量化加速**: 支持 Nunchaku INT4 量化，加速推理速度

## 效果展示

以下是物体移除的示例结果（左：原图+mask，右：移除后结果）：

<table>
  <tr>
    <td><img src="results_example/COCO_14003_mask_COCO_14003_seed42_steps20_size512_repeat0_concat.png" alt="示例1"></td>
    <td><img src="results_example/p1_4171_mask_p1_4171_seed42_steps20_size512_repeat0_concat.png" alt="示例2"></td>
  </tr>
  <tr>
    <td><img src="results_example/COCO_14203_mask_COCO_14203_seed42_steps20_size512_repeat0_concat.png" alt="示例3"></td>
    <td><img src="results_example/p1_40457_mask_p1_40457_seed42_steps20_size512_repeat0_concat.png" alt="示例4"></td>
  </tr>
  <tr>
    <td><img src="results_example/I-210729_I09026_W01_F0046_mask_I-210729_I09026_W01_F0046_seed42_steps20_size512_repeat0_concat.png" alt="示例5"></td>
    <td><img src="results_example/I-211222_O10043_W10_F0114_mask_I-211222_O10043_W10_F0114_seed42_steps20_size512_repeat0_concat.png" alt="示例6"></td>
  </tr>
</table>

*更多示例结果请查看 [results_example](results_example/) 目录*

## 项目结构

```
RemoveAnythingSimplify/
├── src/                    # 核心源代码
│   ├── data/              # 数据处理模块
│   ├── pipelines/         # 推理管道
│   ├── optimizer/         # 优化器
│   └── infer.py          # 推理脚本
├── comfyui_workflow/      # ComfyUI 工作流
├── infer/                 # 推理示例脚本
├── api_server.py          # 物体移除 API 服务
├── sam2_api_server.py     # SAM2 分割 API 服务
└── train_lora_flux_kontext.py  # LoRA 训练脚本
```

## 快速开始

### 环境要求

- Python 3.10+
- torch==2.6.0+cu124
- nunchaku==1.0.1.dev20250930+torch2.6

### 安装依赖

```bash
pip install -r api_requirements.txt
```

### 启动 API 服务

1. **物体移除服务**
```bash
bash start_api_server.sh
# 或直接运行
python api_server.py
```

2. **SAM2 分割服务**
```bash
bash start_sam2_server.sh
# 或直接运行
python sam2_api_server.py
```

### 模型准备

#### 基础模型下载

1. **FLUX.1-Fill-dev** - 图像修复基础模型
   - Hugging Face: [black-forest-labs/FLUX.1-Fill-dev](https://huggingface.co/black-forest-labs/FLUX.1-Fill-dev)
   - ModelScope: [black-forest-labs/FLUX.1-dev](https://modelscope.cn/models/black-forest-labs/FLUX.1-dev)

2. **FLUX.1-Redux-dev** - 图像编码模型
   - Hugging Face: [black-forest-labs/FLUX.1-Redux-dev](https://huggingface.co/black-forest-labs/FLUX.1-Redux-dev)
   - ModelScope: [black-forest-labs/FLUX.1-Redux-dev](https://modelscope.cn/models/black-forest-labs/FLUX.1-Redux-dev)

3. **SAM2 Checkpoints** - 图像分割模型
   - 下载地址: [SAM2 Checkpoints](https://github.com/facebookresearch/segment-anything-2#download-checkpoints)

#### LoRA 权重下载

右上角直接下载，或网盘：

- **百度网盘**: [https://pan.baidu.com/s/1kvCdVN1zp88_RApaisUuKw?pwd=2p9q](https://pan.baidu.com/s/1kvCdVN1zp88_RApaisUuKw?pwd=2p9q)
  - 提取码: `2p9q`

下载后将 `pytorch_lora_weights.safetensors` 放置到 `./models/lora/` 目录下。

## API 使用

### 物体移除 API

```python
import requests
import base64

# 读取图像并转换为 base64
with open("image.jpg", "rb") as f:
    image_b64 = base64.b64encode(f.read()).decode()

with open("mask.png", "rb") as f:
    mask_b64 = base64.b64encode(f.read()).decode()

# 调用 API
response = requests.post("http://localhost:8000/api/remove", json={
    "image": image_b64,
    "mask": mask_b64,
    "size": 512,
    "num_inference_steps": 20
})

result = response.json()
```

### SAM2 分割 API

```python
# 点击分割
response = requests.post("http://localhost:8002/api/predict", json={
    "image": image_b64,
    "points": [
        {"x": 100, "y": 200, "label": 1}  # 1=前景, 0=背景
    ]
})

result = response.json()
mask_b64 = result["mask"]
```

## 模型训练

使用自定义数据训练 LoRA：

```bash
accelerate launch src/train_bucket.py \
  --train_json_path $TRAIN_JSON_PATH \
  --val_json_path $VAL_JSON_PATH \
  --output_dir $OUTPUT_DIR \
  --aspect_ratio_buckets $aspect_ratio_buckets \
  --flux_fill_id $FLUX_FILL_ID \
  --flux_redux_id $FLUX_REDUX_ID \
  --learning_rate $LEARNING_RATE \
  --train_batch_size $TRAIN_BATCH_SIZE \
  --max_train_steps $MAX_TRAIN_STEPS \
  --gradient_accumulation_steps $GRADIENT_ACCUMULATION_STEPS \
  --validation_steps $VALIDATION_STEPS \
  --checkpointing_steps $CHECKPOINT_STEPS \
  --use_lora $USE_LORA \
  --lora_r $LORA_R \
  --lora_alpha $LORA_ALPHA \
  --lora_dropout $LORA_DROPOUT \
  --target_modules $TARGET_MODULES \
  --mixed_precision bf16 \
  --enable_xformers_memory_efficient_attention \
  --gradient_checkpointing
```

## 量化加速

使用 Nunchaku 量化模型以提升推理速度：

```bash
bash infer_quant.sh
```

详细说明请参考：[T5_QUANTIZATION_GUIDE.md](T5_QUANTIZATION_GUIDE.md)

## ComfyUI 工作流

支持通过 ComfyUI 进行可视化操作，详见 [comfyui_workflow](comfyui_workflow/) 目录。

## 文档

- [SAM2 服务文档](SAM2_SERVICE.md)
- [T5 量化指南](T5_QUANTIZATION_GUIDE.md)
- [ComfyUI 工作流说明](comfyui_workflow/README.md)

## 许可证

请遵守各模型的原始许可证：
- FLUX.1 系列: [FLUX License](https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md)
- SAM2: Meta 许可证

## 致谢

- [FLUX.1](https://github.com/black-forest-labs/flux) by Black Forest Labs
- [SAM2](https://github.com/facebookresearch/segment-anything-2) by Meta
- [Diffusers](https://github.com/huggingface/diffusers) by Hugging Face
