Spaces:
Runtime error
Runtime error
| <!--Copyright 2024 The HuggingFace Team. All rights reserved. | |
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | |
| the License. You may obtain a copy of the License at | |
| http://www.apache.org/licenses/LICENSE-2.0 | |
| Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | |
| an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| specific language governing permissions and limitations under the License. | |
| --> | |
| # Unconditional μ΄λ―Έμ§ μμ± | |
| unconditional μ΄λ―Έμ§ μμ±μ text-to-image λλ image-to-image λͺ¨λΈκ³Ό λ¬λ¦¬ ν μ€νΈλ μ΄λ―Έμ§μ λν μ‘°κ±΄μ΄ μμ΄ νμ΅ λ°μ΄ν° λΆν¬μ μ μ¬ν μ΄λ―Έμ§λ§μ μμ±ν©λλ€. | |
| <iframe | |
| src="https://stevhliu-ddpm-butterflies-128.hf.space" | |
| frameborder="0" | |
| width="850" | |
| height="550" | |
| ></iframe> | |
| μ΄ κ°μ΄λμμλ κΈ°μ‘΄μ μ‘΄μ¬νλ λ°μ΄ν°μ κ³Ό μμ λ§μ 컀μ€ν λ°μ΄ν°μ μ λν΄ unconditional image generation λͺ¨λΈμ νλ ¨νλ λ°©λ²μ μ€λͺ ν©λλ€. νλ ¨ μΈλΆ μ¬νμ λν΄ λ μμΈν μκ³ μΆλ€λ©΄ unconditional image generationμ μν λͺ¨λ νμ΅ μ€ν¬λ¦½νΈλ₯Ό [μ¬κΈ°](https://github.com/huggingface/diffusers/tree/main/examples/unconditional_image_generation)μμ νμΈν μ μμ΅λλ€. | |
| μ€ν¬λ¦½νΈλ₯Ό μ€ννκΈ° μ , λ¨Όμ μμ‘΄μ± λΌμ΄λΈλ¬λ¦¬λ€μ μ€μΉν΄μΌ ν©λλ€. | |
| ```bash | |
| pip install diffusers[training] accelerate datasets | |
| ``` | |
| κ·Έ λ€μ π€ [Accelerate](https://github.com/huggingface/accelerate/) νκ²½μ μ΄κΈ°νν©λλ€. | |
| ```bash | |
| accelerate config | |
| ``` | |
| λ³λμ μ€μ μμ΄ κΈ°λ³Έ μ€μ μΌλ‘ π€ [Accelerate](https://github.com/huggingface/accelerate/) νκ²½μ μ΄κΈ°νν΄λ΄ μλ€. | |
| ```bash | |
| accelerate config default | |
| ``` | |
| λ ΈνΈλΆκ³Ό κ°μ λνν μμ μ§μνμ§ μλ νκ²½μ κ²½μ°, λ€μκ³Ό κ°μ΄ μ¬μ©ν΄λ³Ό μλ μμ΅λλ€. | |
| ```py | |
| from accelerate.utils import write_basic_config | |
| write_basic_config() | |
| ``` | |
| ## λͺ¨λΈμ νλΈμ μ λ‘λνκΈ° | |
| νμ΅ μ€ν¬λ¦½νΈμ λ€μ μΈμλ₯Ό μΆκ°νμ¬ νλΈμ λͺ¨λΈμ μ λ‘λν μ μμ΅λλ€. | |
| ```bash | |
| --push_to_hub | |
| ``` | |
| ## 체ν¬ν¬μΈνΈ μ μ₯νκ³ λΆλ¬μ€κΈ° | |
| νλ ¨ μ€ λ¬Έμ κ° λ°μν κ²½μ°λ₯Ό λλΉνμ¬ μ²΄ν¬ν¬μΈνΈλ₯Ό μ κΈ°μ μΌλ‘ μ μ₯νλ κ²μ΄ μ’μ΅λλ€. 체ν¬ν¬μΈνΈλ₯Ό μ μ₯νλ €λ©΄ νμ΅ μ€ν¬λ¦½νΈμ λ€μ μΈμλ₯Ό μ λ¬ν©λλ€: | |
| ```bash | |
| --checkpointing_steps=500 | |
| ``` | |
| μ 체 νλ ¨ μνλ 500μ€ν λ§λ€ `output_dir`μ νμ ν΄λμ μ μ₯λλ©°, νμ΅ μ€ν¬λ¦½νΈμ `--resume_from_checkpoint` μΈμλ₯Ό μ λ¬ν¨μΌλ‘μ¨ μ²΄ν¬ν¬μΈνΈλ₯Ό λΆλ¬μ€κ³ νλ ¨μ μ¬κ°ν μ μμ΅λλ€. | |
| ```bash | |
| --resume_from_checkpoint="checkpoint-1500" | |
| ``` | |
| ## νμΈνλ | |
| μ΄μ νμ΅ μ€ν¬λ¦½νΈλ₯Ό μμν μ€λΉκ° λμμ΅λλ€! `--dataset_name` μΈμμ νμΈνλν λ°μ΄ν°μ μ΄λ¦μ μ§μ ν λ€μ, `--output_dir` μΈμμ μ§μ λ κ²½λ‘λ‘ μ μ₯ν©λλ€. λ³ΈμΈλ§μ λ°μ΄ν°μ λ₯Ό μ¬μ©νλ €λ©΄, [νμ΅μ© λ°μ΄ν°μ λ§λ€κΈ°](create_dataset) κ°μ΄λλ₯Ό μ°Έμ‘°νμΈμ. | |
| νμ΅ μ€ν¬λ¦½νΈλ `diffusion_pytorch_model.bin` νμΌμ μμ±νκ³ , κ·Έκ²μ λΉμ μ 리ν¬μ§ν 리μ μ μ₯ν©λλ€. | |
| <Tip> | |
| π‘ μ 체 νμ΅μ V100 GPU 4κ°λ₯Ό μ¬μ©ν κ²½μ°, 2μκ°μ΄ μμλ©λλ€. | |
| </Tip> | |
| μλ₯Ό λ€μ΄, [Oxford Flowers](https://huggingface.co/datasets/huggan/flowers-102-categories) λ°μ΄ν°μ μ μ¬μ©ν΄ νμΈνλν κ²½μ°: | |
| ```bash | |
| accelerate launch train_unconditional.py \ | |
| --dataset_name="huggan/flowers-102-categories" \ | |
| --resolution=64 \ | |
| --output_dir="ddpm-ema-flowers-64" \ | |
| --train_batch_size=16 \ | |
| --num_epochs=100 \ | |
| --gradient_accumulation_steps=1 \ | |
| --learning_rate=1e-4 \ | |
| --lr_warmup_steps=500 \ | |
| --mixed_precision=no \ | |
| --push_to_hub | |
| ``` | |
| <div class="flex justify-center"> | |
| <img src="https://user-images.githubusercontent.com/26864830/180248660-a0b143d0-b89a-42c5-8656-2ebf6ece7e52.png"/> | |
| </div> | |
| [Naruto](https://huggingface.co/datasets/lambdalabs/naruto-blip-captions) λ°μ΄ν°μ μ μ¬μ©ν κ²½μ°: | |
| ```bash | |
| accelerate launch train_unconditional.py \ | |
| --dataset_name="lambdalabs/naruto-blip-captions" \ | |
| --resolution=64 \ | |
| --output_dir="ddpm-ema-naruto-64" \ | |
| --train_batch_size=16 \ | |
| --num_epochs=100 \ | |
| --gradient_accumulation_steps=1 \ | |
| --learning_rate=1e-4 \ | |
| --lr_warmup_steps=500 \ | |
| --mixed_precision=no \ | |
| --push_to_hub | |
| ``` | |
| <div class="flex justify-center"> | |
| <img src="https://user-images.githubusercontent.com/26864830/180248200-928953b4-db38-48db-b0c6-8b740fe6786f.png"/> | |
| </div> | |
| ### μ¬λ¬κ°μ GPUλ‘ νλ ¨νκΈ° | |
| `accelerate`μ μ¬μ©νλ©΄ μνν λ€μ€ GPU νλ ¨μ΄ κ°λ₯ν©λλ€. `accelerate`μ μ¬μ©νμ¬ λΆμ° νλ ¨μ μ€ννλ €λ©΄ [μ¬κΈ°](https://huggingface.co/docs/accelerate/basic_tutorials/launch) μ§μΉ¨μ λ°λ₯΄μΈμ. λ€μμ λͺ λ Ήμ΄ μμ μ λλ€. | |
| ```bash | |
| accelerate launch --mixed_precision="fp16" --multi_gpu train_unconditional.py \ | |
| --dataset_name="lambdalabs/naruto-blip-captions" \ | |
| --resolution=64 --center_crop --random_flip \ | |
| --output_dir="ddpm-ema-naruto-64" \ | |
| --train_batch_size=16 \ | |
| --num_epochs=100 \ | |
| --gradient_accumulation_steps=1 \ | |
| --use_ema \ | |
| --learning_rate=1e-4 \ | |
| --lr_warmup_steps=500 \ | |
| --mixed_precision="fp16" \ | |
| --logger="wandb" \ | |
| --push_to_hub | |
| ``` | |