当前位置:   article > 正文

训练Lora_pokemon-blip-captions下载

pokemon-blip-captions下载

1、下载数据

  1. import sys
  2. import os
  3. import json
  4. if __name__ =="__main__":
  5. jsonfile = "data/pokeman.json" #sys.argv[1]
  6. savedir = "data/pokemon-blip-captions/" # sys.argv[2]
  7. os.system("curl -X GET \"https://datasets-server.huggingface.co/first-rows?dataset=lambdalabs%2Fpokemon-blip-captions&config=lambdalabs--pokemon-blip-captions&split=train\" > data/pokeman.json")
  8. txtfile = savedir.rstrip("/")+"_text.txt"
  9. with open(jsonfile) as fb:
  10. lines = fb.readlines()
  11. line = lines[0].rstrip()
  12. data_dict = eval(line)
  13. #data_dict = json.load(fb)
  14. print(data_dict.keys())
  15. txt_list = []
  16. for ii in data_dict["rows"]:
  17. idx = ii["row_idx"]
  18. url = ii["row"]["image"]["src"]
  19. os.system(f"wget \"{url}\" -O {savedir}/{idx}.jpg")
  20. txt = ii["row"]["text"]
  21. txt_list.append(txt)
  22. with open(f"{savedir}/{idx}.txt", 'w') as fb:
  23. fb.writelines(txt)
  24. with open(txtfile, 'w') as fb:
  25. fb.writelines("\n".join(txt_list))
  26. ##

2、diffusers仓库

1)安装环境,需要额外安装dataset, pip install datasets

from datasets import load_dataset ModuleNotFoundError: No module named 'datasets' · Issue #1463 · huggingface/diffusers · GitHub

2)升级accelerate==0.16.0

ImportError: cannot import name 'ProjectConfiguration' from 'accelerate.utils' · Issue #2571 · huggingface/diffusers · GitHub

3、训练脚本

Using LoRA for Efficient Stable Diffusion Fine-Tuning

采用 diffuers训练脚本

  1. export MODEL_NAME="runwayml/stable-diffusion-v1-5"
  2. export OUTPUT_DIR="models/mymodel/lora_pokeman"
  3. export DATASET_NAME="lambdalabs/pokemon-blip-captions"
  4. accelerate launch --mixed_precision="fp16" examples/text_to_image/train_text_to_image_lora.py \
  5. --pretrained_model_name_or_path=$MODEL_NAME \
  6. --dataset_name=$DATASET_NAME \
  7. --dataloader_num_workers=8 \
  8. --resolution=512 --center_crop --random_flip \
  9. --train_batch_size=1 \
  10. --gradient_accumulation_steps=4 \
  11. --max_train_steps=15000 \
  12. --learning_rate=1e-04 \
  13. --max_grad_norm=1 \
  14. --lr_scheduler="cosine" --lr_warmup_steps=0 \
  15. --output_dir=${OUTPUT_DIR} \
  16. --checkpointing_steps=500 \
  17. --validation_prompt="" \
  18. --seed=1337

4、输出(sd1.5)

a drawing of a gray and yellow pokemon <lora:lora_pokeman-15000:1> 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/514103
推荐阅读
相关标签
  

闽ICP备14008679号