Learnable Regions 项目安装与配置指南
1. 项目基础介绍
"Learnable Regions" 是一个开源项目,它通过文本驱动的图像编辑技术,允许用户使用文本提示对图像进行区域编辑,而无需用户提供掩码或草图。该项目旨在提供一种简单而灵活的图像编辑方法,与当前的图像生成模型兼容,并能处理包含多个对象、复杂句子或长段落的复杂提示。该项目主要使用 Python 编程语言。
2. 项目使用的关键技术和框架
该项目利用了以下关键技术和框架:
- 预训练的文本到图像模型:用于理解和生成与文本提示相对应的图像内容。
- 边界框生成器:用于识别与文本提示相匹配的编辑区域。
- PyTorch:一个开源的机器学习库,用于项目的深度学习模型训练和推理。
- Stable Diffusion:一种用于图像修复和编辑的扩散模型。
3. 项目安装和配置的准备工作
在开始安装之前,请确保您的系统满足以下要求:
- Python 3.9
- conda (用于环境管理)
- Git (用于克隆项目仓库)
详细安装步骤
-
克隆项目仓库:
打开终端(或命令提示符),执行以下命令以克隆项目仓库:
git clone https://github.com/yuanze-lin/Learnable_Regions.git
-
创建虚拟环境并安装依赖:
进入项目目录,创建一个名为
LearnableRegion
的虚拟环境,并安装所需的 Python 包:cd Learnable_Regions conda create -n LearnableRegion python==3.9 -y source activate LearnableRegion pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 --index-url https://download.pytorch.org/whl/cu118 conda env update --file environment.yaml
请确保在执行上述命令时,您的系统已安装了 conda。
-
开始编辑图像:
根据您的需求,选择以下命令之一来编辑图像:
-
编辑单个图像:
torchrun --nnodes=1 --nproc_per_node=1 train.py \ --image_file_path images/1.png \ --image_caption 'trees' \ --editing_prompt 'a big tree with many flowers in the center' \ --diffusion_model_path 'stabilityai/stable-diffusion-2-inpainting' \ --output_dir output/ \ --draw_box \ --lr 5e-3 \ --max_window_size 15 \ --per_image_iteration 10 \ --epochs 1 \ --num_workers 8 \ --seed 42 \ --pin_mem \ --point_number 9 \ --batch_size 1 \ --save_path checkpoints/
-
编辑多个图像:
torchrun --nnodes=1 --nproc_per_node=2 train.py \ --image_dir_path images/ \ --output_dir output/ \ --json_file images.json \ --diffusion_model_path 'stabilityai/stable-diffusion-2-inpainting' \ --draw_box \ --lr 5e-3 \ --max_window_size 15 \ --per_image_iteration 10 \ --epochs 1 \ --num_workers 8 \ --seed 42 \ --pin_mem \ --point_number 9 \ --batch_size 1 \ --save_path checkpoints/
请根据您的具体情况调整命令中的参数。
-
以上步骤将帮助您成功安装和配置 "Learnable Regions" 项目,并开始图像编辑工作。
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考