首页 游戏 软件 资讯 排行榜 专题
首页
AI
使用Lora技术进行Dreambooth训练【抢先体验版】

使用Lora技术进行Dreambooth训练【抢先体验版】

热心网友
53
转载
2025-07-21
本文介绍了使用PaddleNLP等工具进行模型训练与推理的流程。先安装paddlenlp等依赖,再分别用dreambooth lora和文生图lora方式训练,设置参数并保存权重。之后可启动visualdl查看训练出图,最后加载训练好的文件,通过相关代码进行推理生成图像。

使用lora技术进行dreambooth训练【抢先体验版】 - 游乐网

1. 安装依赖

运行下面的按钮安装依赖,为了确保安装成功,安装完毕请重启内核!(注意:这里只需要运行一次!)In [1]
!pip install -U paddlenlp ppdiffusers safetensors --user
登录后复制        
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simpleRequirement already satisfied: paddlenlp in ./.data/webide/pip/lib/python3.7/site-packages (2.5.1)Requirement already satisfied: ppdiffusers in ./.data/webide/pip/lib/python3.7/site-packages (0.11.0)Requirement already satisfied: safetensors in ./.data/webide/pip/lib/python3.7/site-packages (0.2.8)Requirement already satisfied: paddlefsl in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp) (1.1.0)Requirement already satisfied: sentencepiece in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp) (0.1.96)Requirement already satisfied: huggingface-hub>=0.11.1 in ./.data/webide/pip/lib/python3.7/site-packages (from paddlenlp) (0.12.0)Requirement already satisfied: seqeval in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp) (1.2.2)Requirement already satisfied: fastapi in ./.data/webide/pip/lib/python3.7/site-packages (from paddlenlp) (0.91.0)Requirement already satisfied: typer in ./.data/webide/pip/lib/python3.7/site-packages (from paddlenlp) (0.7.0)Requirement already satisfied: multiprocess<=0.70.12.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp) (0.70.11.1)Requirement already satisfied: jieba in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp) (0.42.1)Requirement already satisfied: Flask-Babel<3.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp) (1.0.0)Requirement already satisfied: rich in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp) (12.6.0)Requirement already satisfied: datasets>=2.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp) (2.7.0)Requirement already satisfied: paddle2onnx in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp) (1.0.0)Requirement already satisfied: colorama in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp) (0.4.4)Requirement already satisfied: visualdl in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp) (2.4.0)Requirement already satisfied: uvicorn in ./.data/webide/pip/lib/python3.7/site-packages (from paddlenlp) (0.20.0)Requirement already satisfied: tqdm in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp) (4.64.1)Requirement already satisfied: dill<0.3.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp) (0.3.3)Requirement already satisfied: colorlog in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlenlp) (4.1.0)Requirement already satisfied: Pillow in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from ppdiffusers) (8.2.0)Requirement already satisfied: regex in ./.data/webide/pip/lib/python3.7/site-packages (from ppdiffusers) (2024.10.31)Requirement already satisfied: ftfy in ./.data/webide/pip/lib/python3.7/site-packages (from ppdiffusers) (6.1.1)Requirement already satisfied: pyyaml>=5.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from datasets>=2.0.0->paddlenlp) (5.1.2)Requirement already satisfied: numpy>=1.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from datasets>=2.0.0->paddlenlp) (1.19.5)Requirement already satisfied: pyarrow>=6.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from datasets>=2.0.0->paddlenlp) (10.0.0)Requirement already satisfied: fsspec[http]>=2024.11.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from datasets>=2.0.0->paddlenlp) (2024.11.0)Requirement already satisfied: requests>=2.19.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from datasets>=2.0.0->paddlenlp) (2.24.0)Requirement already satisfied: xxhash in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from datasets>=2.0.0->paddlenlp) (3.1.0)Requirement already satisfied: importlib-metadata in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from datasets>=2.0.0->paddlenlp) (4.2.0)Requirement already satisfied: packaging in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from datasets>=2.0.0->paddlenlp) (21.3)Requirement already satisfied: aiohttp in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from datasets>=2.0.0->paddlenlp) (3.8.3)Requirement already satisfied: responses<0.19 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from datasets>=2.0.0->paddlenlp) (0.18.0)Requirement already satisfied: pandas in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from datasets>=2.0.0->paddlenlp) (1.1.5)Requirement already satisfied: Jinja2>=2.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel<3.0.0->paddlenlp) (3.0.0)Requirement already satisfied: pytz in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel<3.0.0->paddlenlp) (2019.3)Requirement already satisfied: Babel>=2.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel<3.0.0->paddlenlp) (2.8.0)Requirement already satisfied: Flask in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel<3.0.0->paddlenlp) (1.1.1)Requirement already satisfied: filelock in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from huggingface-hub>=0.11.1->paddlenlp) (3.0.12)Requirement already satisfied: typing-extensions>=3.7.4.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from huggingface-hub>=0.11.1->paddlenlp) (4.3.0)Requirement already satisfied: starlette<0.25.0,>=0.24.0 in ./.data/webide/pip/lib/python3.7/site-packages (from fastapi->paddlenlp) (0.24.0)Requirement already satisfied: pydantic!=1.7,!=1.7.1,!=1.7.2,!=1.7.3,!=1.8,!=1.8.1,<2.0.0,>=1.6.2 in ./.data/webide/pip/lib/python3.7/site-packages (from fastapi->paddlenlp) (1.10.4)Requirement already satisfied: wcwidth>=0.2.5 in ./.data/webide/pip/lib/python3.7/site-packages (from ftfy->ppdiffusers) (0.2.6)Requirement already satisfied: pygments<3.0.0,>=2.6.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from rich->paddlenlp) (2.13.0)Requirement already satisfied: commonmark<0.10.0,>=0.9.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from rich->paddlenlp) (0.9.1)Requirement already satisfied: scikit-learn>=0.21.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from seqeval->paddlenlp) (0.24.2)Requirement already satisfied: click<9.0.0,>=7.1.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from typer->paddlenlp) (8.0.4)Requirement already satisfied: h21>=0.8 in ./.data/webide/pip/lib/python3.7/site-packages (from uvicorn->paddlenlp) (0.14.0)Requirement already satisfied: matplotlib in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl->paddlenlp) (2.2.3)Requirement already satisfied: six>=1.14.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl->paddlenlp) (1.16.0)Requirement already satisfied: protobuf>=3.11.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl->paddlenlp) (3.20.0)Requirement already satisfied: bce-python-sdk in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl->paddlenlp) (0.8.53)Requirement already satisfied: Werkzeug>=0.15 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask->Flask-Babel<3.0.0->paddlenlp) (0.16.0)Requirement already satisfied: itsdangerous>=0.24 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask->Flask-Babel<3.0.0->paddlenlp) (1.1.0)Requirement already satisfied: attrs>=17.3.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from aiohttp->datasets>=2.0.0->paddlenlp) (22.1.0)Requirement already satisfied: aiosignal>=1.1.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from aiohttp->datasets>=2.0.0->paddlenlp) (1.2.0)Requirement already satisfied: multidict<7.0,>=4.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from aiohttp->datasets>=2.0.0->paddlenlp) (6.0.2)Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from aiohttp->datasets>=2.0.0->paddlenlp) (4.0.2)Requirement already satisfied: asynctest==0.13.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from aiohttp->datasets>=2.0.0->paddlenlp) (0.13.0)Requirement already satisfied: frozenlist>=1.1.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from aiohttp->datasets>=2.0.0->paddlenlp) (1.3.0)Requirement already satisfied: yarl<2.0,>=1.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from aiohttp->datasets>=2.0.0->paddlenlp) (1.7.2)Requirement already satisfied: charset-normalizer<3.0,>=2.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from aiohttp->datasets>=2.0.0->paddlenlp) (2.1.1)Requirement already satisfied: MarkupSafe>=2.0.0rc2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Jinja2>=2.5->Flask-Babel<3.0.0->paddlenlp) (2.0.1)Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from packaging->datasets>=2.0.0->paddlenlp) (3.0.9)Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.19.0->datasets>=2.0.0->paddlenlp) (2019.9.11)Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.19.0->datasets>=2.0.0->paddlenlp) (1.25.11)Requirement already satisfied: chardet<4,>=3.0.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.19.0->datasets>=2.0.0->paddlenlp) (3.0.4)Requirement already satisfied: idna<3,>=2.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.19.0->datasets>=2.0.0->paddlenlp) (2.8)Requirement already satisfied: scipy>=0.19.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn>=0.21.3->seqeval->paddlenlp) (1.6.3)Requirement already satisfied: joblib>=0.11 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn>=0.21.3->seqeval->paddlenlp) (0.14.1)Requirement already satisfied: threadpoolctl>=2.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn>=0.21.3->seqeval->paddlenlp) (2.1.0)Requirement already satisfied: anyio<5,>=3.4.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from starlette<0.25.0,>=0.24.0->fastapi->paddlenlp) (3.6.1)Requirement already satisfied: future>=0.6.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl->paddlenlp) (0.18.0)Requirement already satisfied: pycryptodome>=3.8.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl->paddlenlp) (3.9.9)Requirement already satisfied: zipp>=0.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from importlib-metadata->datasets>=2.0.0->paddlenlp) (3.8.1)Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl->paddlenlp) (1.1.0)Requirement already satisfied: python-dateutil>=2.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl->paddlenlp) (2.8.2)Requirement already satisfied: cycler>=0.10 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl->paddlenlp) (0.10.0)Requirement already satisfied: sniffio>=1.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from anyio<5,>=3.4.0->starlette<0.25.0,>=0.24.0->fastapi->paddlenlp) (1.3.0)Requirement already satisfied: setuptools in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from kiwisolver>=1.0.1->matplotlib->visualdl->paddlenlp) (56.2.0)[notice] A new release of pip available: 22.1.2 -> 23.0.1[notice] To update, run: pip install --upgrade pip
登录后复制        

2. 准备要训练的图片

在这里我们已经在dogs文件夹准备好了如下所示的5张图片。使用Lora技术进行Dreambooth训练【抢先体验版】 - 游乐网            

3. 开始训练

参数解释:

免费影视、动漫、音乐、游戏、小说资源长期稳定更新! 👉 点此立即查看 👈

pretrained_model_name_or_path :想要训练的模型名称,例如:"runwayml/stable-diffusion-v1-5",更多模型可参考 paddlenlp 文档instance_data_dir:想要训练的图片地址。instance_prompt:训练的prompt文本。resolution:训练时图像的大小,建议为512。train_batch_size:训练时候使用的batch_size,可不修改。gradient_accumulation_steps:梯度累积的步数,可不修改。checkpointing_steps:每隔多少步保存模型。learning_rate:训练使用的学习率。report_to:我们将训练过程中出的图片导出到visudl工具中。lr_scheduler:学习率衰减策略,可以是:"linear", "constant", "cosine","cosine_with_restarts"等。lr_warmup_steps:学习率衰减前,warmup到最大学习率所需要的步数。max_train_steps:最多训练多少步。validation_prompt:训练的过程中我们会评估训练的怎么样,因此我们需要设置评估使用的prompt文本。validation_epochs:每隔多少个epoch评估模型,我们可以查看训练的进度条,知道当前到了第几个epoch。validation_guidance_scale:评估过程中的CFG引导值,默认为5.0.seed:随机种子,设置后可以复现训练结果。lora_rank:lora 的 rank值,默认为128,与开源的版本保持一致。use_lion:表示是否使用lion优化器,如果我们不想使用lion的话需要把 --use_lion True 表示使用 --use_lion False 表示不使用。lora_weight_or_path:我们需要加载的lora权重,当前支持:pt,ckpt,safetensors,和pdparams这些格式,可直接加载这里的lora权重 https://civitai.com/models。

注意:

会保存2种格式的权重,一个是paddle的,一个是safetensors的,可以使用 https://github.com/bmaltais/kohya_ss 这个人的加载。

dreambooth lora

In [6]
!python train_dreambooth_lora.py \  --pretrained_model_name_or_path="runwayml/stable-diffusion-v1-5"  \  --instance_data_dir="./dogs" \  --output_dir="./dream_booth_lora_outputs" \  --instance_prompt="a photo of sks dog" \  --resolution=512 \  --train_batch_size=1 \  --gradient_accumulation_steps=1 \  --checkpointing_steps=100 \  --learning_rate=1e-4 \  --report_to="visualdl" \  --lr_scheduler="constant" \  --lr_warmup_steps=0 \  --max_train_steps=500 \  --lora_rank=128 \  --validation_prompt="A photo of sks dog in a bucket" \  --validation_epochs=25 \  --validation_guidance_scale=5.0 \  --use_lion False \  --seed=0
登录后复制        
[2024-02-23 10:13:09,015] [ WARNING] - You are using a model of type clip_text_model to instantiate a model of type . This is not supported for all configurations of models and can yield errors.W0223 10:13:09.018703 11490 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 11.2W0223 10:13:09.022612 11490 gpu_resources.cc:91] device: 0, cuDNN Version: 8.2.Train Steps:  20%|███████████████████████▌                                                                                              | 100/500 [01:12<03:04,  2.16it/s, epoch=0019, step_loss=0.0413]Saved lora weights to ./dream_booth_lora_outputs/checkpoint-100Train Steps:  40%|███████████████████████████████████████████████▌                                                                       | 200/500 [02:25<02:19,  2.15it/s, epoch=0039, step_loss=0.446]Saved lora weights to ./dream_booth_lora_outputs/checkpoint-200Train Steps:  60%|██████████████████████████████████████████████████████████████████████▏                                              | 300/500 [03:37<01:33,  2.13it/s, epoch=0059, step_loss=0.00273]Saved lora weights to ./dream_booth_lora_outputs/checkpoint-300Train Steps:  80%|███████████████████████████████████████████████████████████████████████████████████████████████▏                       | 400/500 [04:53<00:47,  2.11it/s, epoch=0079, step_loss=0.275]Saved lora weights to ./dream_booth_lora_outputs/checkpoint-400Train Steps: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 500/500 [05:44<00:00,  2.14it/s, epoch=0099, step_loss=0.00985]Saved lora weights to ./dream_booth_lora_outputs/checkpoint-500Saved final lora weights to ./dream_booth_lora_outputsTrain Steps: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 500/500 [05:48<00:00,  1.43it/s, epoch=0099, step_loss=0.00985]
登录后复制        

文生图 lora

--train_data_dir 这个需要放图文对的文件夹,里面是图片和txt。

--image_format 表示 train_data_dir 文件夹内的图片格式,比如png,jpg,jpeg

--use_lion Fasle 表示不使用lion优化器。

In [3]
!python train_text_to_image_lora.py \  --pretrained_model_name_or_path="runwayml/stable-diffusion-v1-5"  \  --output_dir="./text_to_image_lora_outputs3" \  --train_data_dir="mishanwu" \  --image_format="png" \  --resolution=512 \  --train_batch_size=1 \  --gradient_accumulation_steps=1 \  --checkpointing_steps=500 \  --learning_rate=6e-5 \  --report_to="visualdl" \  --lr_scheduler="cosine_with_restarts" \  --lr_warmup_steps=0 \  --max_train_steps=1000 \  --lora_rank=128 \  --validation_prompt="1girl, solo, black_background, looking_at_viewer, parted_lips, tears, brown_eyes" \  --validation_epochs=1 \  --validation_guidance_scale=5.0 \  --use_lion False \  --seed=0
登录后复制        
[2024-02-23 11:11:34,386] [ WARNING] - You are using a model of type clip_text_model to instantiate a model of type . This is not supported for all configurations of models and can yield errors.W0223 11:11:34.389356  7327 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 11.2W0223 11:11:34.392953  7327 gpu_resources.cc:91] device: 0, cuDNN Version: 8.2.Resolving data files: 100%|████████████████| 581/581 [00:00<00:00, 50722.06it/s]Using custom data configuration default-4fb24e511b7f6118Downloading and preparing dataset imagefolder/default to /home/aistudio/.cache/huggingface/datasets/imagefolder/default-4fb24e511b7f6118/0.0.0/37fbb85cc714a338bea574ac6c7d0b5be5aff46c1862c1989b20e0771199e93f...Downloading data files #0:   0%|                        | 0/19 [00:00 by passing `safety_checker=None`. Ensure that you abide to the conditions of the Stable Diffusion license and do not expose unfiltered results in services or applications open to the public. PaddleNLP team, diffusers team and Hugging Face strongly recommend to keep the safety filter enabled in all public facing circumstances, disabling it only for use-cases that involve analyzing network behavior or auditing its results. For more information, please have a look at https://github.com/huggingface/diffusers/pull/254 .Train Steps:  50%|▌| 500/1000 [04:16<03:54,  2.13it/s, epoch=0001, step_loss=0.0Saved lora weights to ./text_to_image_lora_outputs3/checkpoint-500Train Steps:  58%|▌| 580/1000 [04:55<03:09,  2.22it/s, epoch=0001, step_loss=0.2You have disabled the safety checker for  by passing `safety_checker=None`. Ensure that you abide to the conditions of the Stable Diffusion license and do not expose unfiltered results in services or applications open to the public. PaddleNLP team, diffusers team and Hugging Face strongly recommend to keep the safety filter enabled in all public facing circumstances, disabling it only for use-cases that involve analyzing network behavior or auditing its results. For more information, please have a look at https://github.com/huggingface/diffusers/pull/254 .Train Steps:  87%|▊| 870/1000 [07:40<00:58,  2.22it/s, epoch=0002, step_loss=0.0You have disabled the safety checker for  by passing `safety_checker=None`. Ensure that you abide to the conditions of the Stable Diffusion license and do not expose unfiltered results in services or applications open to the public. PaddleNLP team, diffusers team and Hugging Face strongly recommend to keep the safety filter enabled in all public facing circumstances, disabling it only for use-cases that involve analyzing network behavior or auditing its results. For more information, please have a look at https://github.com/huggingface/diffusers/pull/254 .Train Steps: 100%|█| 1000/1000 [09:10<00:00,  1.25it/s, epoch=0003, step_loss=0.Saved lora weights to ./text_to_image_lora_outputs3/checkpoint-1000You have disabled the safety checker for  by passing `safety_checker=None`. Ensure that you abide to the conditions of the Stable Diffusion license and do not expose unfiltered results in services or applications open to the public. PaddleNLP team, diffusers team and Hugging Face strongly recommend to keep the safety filter enabled in all public facing circumstances, disabling it only for use-cases that involve analyzing network behavior or auditing its results. For more information, please have a look at https://github.com/huggingface/diffusers/pull/254 .Saved final lora weights to ./text_to_image_lora_outputs3Train Steps: 100%|█| 1000/1000 [09:44<00:00,  1.71it/s, epoch=0003, step_loss=0.
登录后复制        

4. 启动visualdl程序,查看我们训练过程中出图情况

使用Lora技术进行Dreambooth训练【抢先体验版】 - 游乐网使用Lora技术进行Dreambooth训练【抢先体验版】 - 游乐网        

5. 加载训练好的文件进行推理

In [1]
import lora_helperfrom allinone import StableDiffusionPipelineAllinOnefrom ppdiffusers import DPMSolverMultistepSchedulerimport paddle# 基础模型,需要是paddle版本的权重,未来会加更多的权重pretrained_model_name_or_path = "runwayml/stable-diffusion-v1-5"# 我们加载safetensor版本的权重lora_outputs_path = "9070.safetensors"# 加载之前的模型pipe = StableDiffusionPipelineAllinOne.from_pretrained(pretrained_model_name_or_path, safety_checker=None)pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)# 加载lora权重from IPython.display import clear_output, displayclear_output()pipe.apply_lora(lora_outputs_path)
登录后复制        
|---------------当前的rank是 128!|---------------当前的alpha是 128.0!Loading lora_weights successfully!
登录后复制        In [5]
import lora_helperfrom allinone import StableDiffusionPipelineAllinOnefrom ppdiffusers import DPMSolverMultistepSchedulerprompt               = "A photo of sks dog in a bucket"negative_prompt      = ""guidance_scale       = 8num_inference_steps  = 25height               = 512width                = 512img = pipe(prompt, negative_prompt=negative_prompt, guidance_scale=guidance_scale, height=height, width=width, num_inference_steps=num_inference_steps).images[0]display(img)display(img.argument)
登录后复制        
  0%|          | 0/25 [00:00登录后复制                
登录后复制                
{'prompt': 'A photo of sks dog in a bucket', 'negative_prompt': '', 'height': 512, 'width': 512, 'num_inference_steps': 25, 'guidance_scale': 8, 'num_images_per_prompt': 1, 'eta': 0.0, 'seed': 3574959348, 'latents': None, 'max_embeddings_multiples': 1, 'no_boseos_middle': False, 'skip_parsing': False, 'skip_weighting': False, 'epoch_time': 1676862593.5281246}
登录后复制                
来源:https://www.php.cn/faq/1419539.html
免责声明: 游乐网为非赢利性网站,所展示的游戏/软件/文章内容均来自于互联网或第三方用户上传分享,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系youleyoucom@outlook.com。

相关攻略

Pywinrm,一个 Python 管理利器!
科技数码
Pywinrm,一个 Python 管理利器!

Pywinrm 通过Windows远程管理(WinRM)协议,让Python能够像操作本地一样执行远程Windows命令,真正打通了跨平台管理的最后一公里。 在混合IT环境中,Linux机器管理Wi

热心网友
04.07
全网炸了!5亿人用的Axios竟被投毒,你的密钥还保得住吗?
科技数码
全网炸了!5亿人用的Axios竟被投毒,你的密钥还保得住吗?

早些时候,聊过 Python 领域那场惊心动魄的供应链攻击。当时我就感叹,虽然我们 JavaScript 开发者对这类套路烂熟于心,但亲眼目睹这种规模的“投毒”还是头一次。 早些时候,聊过 Pyth

热心网友
04.07
Toga,一个超精简的 Python 项目!
科技数码
Toga,一个超精简的 Python 项目!

Toga 是 BeeWare 家族的核心成员,号称“写一次,跑遍所有平台”,而且用的是系统原生控件,不是那种一看就是网页套壳的界面 。 写了这么多年 Python,你是不是也想过:要是能一套代码跑

热心网友
04.07
Python 异常处理:别再用裸奔的 try 了
科技数码
Python 异常处理:别再用裸奔的 try 了

异常处理的核心:让错误在正确的地方被有效处理。正确的地方,就是别在底层就把异常吞了,也别在顶层还抛裸奔的 Exception。 异常处理写得好,半夜不用起来改 bug。1 你是不是也这么干过?tr

热心网友
04.07
OpenClaw如何自定义SKILL
AI
OpenClaw如何自定义SKILL

1 Skills机制概述 提起OpenClaw的Skills机制,不少人可能会把它想象成传统意义上的可执行插件。其实,它的内涵要更精妙一些。 简单说,Skills本质上是一套基于提示驱动的能力扩展机制。它并不是一个可以独立“跑”起来的程序模块,而是通过一份结构化描述文件(核心就是那个SKILL m

热心网友
04.07

最新APP

宝宝过生日
宝宝过生日
应用辅助 04-07
台球世界
台球世界
体育竞技 04-07
解绳子
解绳子
休闲益智 04-07
骑兵冲突
骑兵冲突
棋牌策略 04-07
三国真龙传
三国真龙传
角色扮演 04-07

热门推荐

美国SEC主席Paul Atkins证实:加密货币安全港提案已送交白宫审查
web3.0
美国SEC主席Paul Atkins证实:加密货币安全港提案已送交白宫审查

加密货币行业翘首以盼的监管里程碑,终于有了实质性进展。美国证券交易委员会(SEC)主席保罗·阿特金斯(Paul Atkins)近日证实,那份允许加密项目在早期获得注册豁免权的“安全港”框架提案,已经正式送抵白宫,进入了最终审查阶段。 在范德堡大学与区块链协会联合举办的数字资产峰会上,阿特金斯透露了这

热心网友
04.08
微策略Strategy报告:第一季录得144.6亿美元浮亏 再斥资约3.3亿美元买进4871枚比特币
web3.0
微策略Strategy报告:第一季录得144.6亿美元浮亏 再斥资约3.3亿美元买进4871枚比特币

微策略Strategy报告:第一季录得144 6亿美元浮亏 再斥资约3 3亿美元买进4871枚比特币 市场震荡的威力有多大?看看Strategy的最新季报就明白了。根据其最新向美国证管会(SEC)提交的8-K报告,受市场剧烈波动影响,这家公司所持的比特币在第一季度录得了一笔惊人的数字——144 6亿

热心网友
04.08
稳定币发行商Tether再扩Web3版图!Paolo Ardoino:正开发去中心化搜索引擎Hypersearch
web3.0
稳定币发行商Tether再扩Web3版图!Paolo Ardoino:正开发去中心化搜索引擎Hypersearch

稳定币巨头Tether的动向,向来是加密世界的风向标。这不,它向Web3基础设施的版图扩张,又迈出了关键一步。公司执行长Paolo Ardoino在社交平台X上透露,其工程团队正在全力“烹制”一个新项目——去中心化搜索引擎 “Hypersearch”。这个消息一出,立刻引发了行业的广泛猜想。 采用D

热心网友
04.08
Base链首个原生DeFi借贷协议Seamless Protocol倒闭 将于2026年6月30日下线
web3.0
Base链首个原生DeFi借贷协议Seamless Protocol倒闭 将于2026年6月30日下线

基地位于Coinbase旗下以太坊Layer2网络Base的Seamless Protocol,日前正式宣告了服务的终结。这个曾经吸引了超过20万用户的原生DeFi借贷协议,在运营不到三年后,终究没能跑赢时间。它主打的核心产品是Integrated Leverage Markets(ILMs)——一

热心网友
04.08
PAAL代币如何参与治理?社区投票能决定哪些事项?
web3.0
PAAL代币如何参与治理?社区投票能决定哪些事项?

PAAL代币揭秘:深度解析Web3社区治理的核心钥匙 在去中心化自治组织的浪潮中,谁真正掌握了项目的话语权?PAAL代币提供了一套系统化的答案。它不仅是生态内流转的价值媒介,更是开启链上治理大门的核心凭证。通过持有并质押PAAL代币,用户能够对协议升级、资金分配乃至战略方向等关键事务投出决定性的一票

热心网友
04.08