|
# νμ΅μ μν λ°μ΄ν°μ
λ§λ€κΈ° |
|
|
|
[Hub](https://huggingface.co/datasets?task_categories=task_categories:text-to-image&sort=downloads) μλ λͺ¨λΈ κ΅μ‘μ μν λ§μ λ°μ΄ν°μ
μ΄ μμ§λ§, |
|
κ΄μ¬μ΄ μκ±°λ μ¬μ©νκ³ μΆμ λ°μ΄ν°μ
μ μ°Ύμ μ μλ κ²½μ° π€ [Datasets](hf.co/docs/datasets) λΌμ΄λΈλ¬λ¦¬λ₯Ό μ¬μ©νμ¬ λ°μ΄ν°μ
μ λ§λ€ μ μμ΅λλ€. |
|
λ°μ΄ν°μ
ꡬ쑰λ λͺ¨λΈμ νμ΅νλ €λ μμ
μ λ°λΌ λ¬λΌμ§λλ€. |
|
κ°μ₯ κΈ°λ³Έμ μΈ λ°μ΄ν°μ
ꡬ쑰λ unconditional μ΄λ―Έμ§ μμ±κ³Ό κ°μ μμ
μ μν μ΄λ―Έμ§ λλ ν 리μ
λλ€. |
|
λ λ€λ₯Έ λ°μ΄ν°μ
ꡬ쑰λ μ΄λ―Έμ§ λλ ν 리μ text-to-image μμ±κ³Ό κ°μ μμ
μ ν΄λΉνλ ν
μ€νΈ μΊ‘μ
μ΄ ν¬ν¨λ ν
μ€νΈ νμΌμΌ μ μμ΅λλ€. |
|
|
|
μ΄ κ°μ΄λμλ νμΈ νλν λ°μ΄ν°μ
μ λ§λλ λ κ°μ§ λ°©λ²μ μκ°ν©λλ€: |
|
|
|
- μ΄λ―Έμ§ ν΄λλ₯Ό `--train_data_dir` μΈμμ μ 곡ν©λλ€. |
|
- λ°μ΄ν°μ
μ Hubμ μ
λ‘λνκ³ λ°μ΄ν°μ
리ν¬μ§ν 리 idλ₯Ό `--dataset_name` μΈμμ μ λ¬ν©λλ€. |
|
|
|
<Tip> |
|
|
|
π‘ νμ΅μ μ¬μ©ν μ΄λ―Έμ§ λ°μ΄ν°μ
μ λ§λλ λ°©λ²μ λν μμΈν λ΄μ©μ [μ΄λ―Έμ§ λ°μ΄ν°μ
λ§λ€κΈ°](https://huggingface.co/docs/datasets/image_dataset) κ°μ΄λλ₯Ό μ°Έκ³ νμΈμ. |
|
|
|
</Tip> |
|
|
|
## ν΄λ ννλ‘ λ°μ΄ν°μ
ꡬμΆνκΈ° |
|
|
|
Unconditional μμ±μ μν΄ μ΄λ―Έμ§ ν΄λλ‘ μμ μ λ°μ΄ν°μ
μ ꡬμΆν μ μμ΅λλ€. |
|
νμ΅ μ€ν¬λ¦½νΈλ π€ Datasetsμ [ImageFolder](https://huggingface.co/docs/datasets/en/image_dataset#imagefolder) λΉλλ₯Ό μ¬μ©νμ¬ |
|
μλμΌλ‘ ν΄λμμ λ°μ΄ν°μ
μ ꡬμΆν©λλ€. λλ ν 리 ꡬ쑰λ λ€μκ³Ό κ°μμΌ ν©λλ€ : |
|
|
|
```bash |
|
data_dir/xxx.png |
|
data_dir/xxy.png |
|
data_dir/[...]/xxz.png |
|
``` |
|
|
|
λ°μ΄ν°μ
λλ ν°λ¦¬μ κ²½λ‘λ₯Ό `--train_data_dir` μΈμλ‘ μ λ¬ν λ€μ νμ΅μ μμν μ μμ΅λλ€: |
|
|
|
```bash |
|
accelerate launch train_unconditional.py \ |
|
# argumentλ‘ ν΄λ μ§μ νκΈ° \ |
|
--train_data_dir <path-to-train-directory> \ |
|
<other-arguments> |
|
``` |
|
|
|
## Hubμ λ°μ΄ν° μ¬λ¦¬κΈ° |
|
|
|
<Tip> |
|
|
|
π‘ λ°μ΄ν°μ
μ λ§λ€κ³ Hubμ μ
λ‘λνλ κ²μ λν μμΈν λ΄μ©μ [π€ Datasetsμ μ¬μ©ν μ΄λ―Έμ§ κ²μ](https://huggingface.co/blog/image-search-datasets) κ²μλ¬Όμ μ°Έκ³ νμΈμ. |
|
|
|
</Tip> |
|
|
|
PIL μΈμ½λ©λ μ΄λ―Έμ§κ° ν¬ν¨λ `μ΄λ―Έμ§` μ΄μ μμ±νλ [μ΄λ―Έμ§ ν΄λ](https://huggingface.co/docs/datasets/image_load#imagefolder) κΈ°λ₯μ μ¬μ©νμ¬ λ°μ΄ν°μ
μμ±μ μμν©λλ€. |
|
|
|
`data_dir` λλ `data_files` λ§€κ° λ³μλ₯Ό μ¬μ©νμ¬ λ°μ΄ν°μ
μ μμΉλ₯Ό μ§μ ν μ μμ΅λλ€. |
|
`data_files` 맀κ°λ³μλ νΉμ νμΌμ `train` μ΄λ `test` λ‘ λΆλ¦¬ν λ°μ΄ν°μ
μ 맀ννλ κ²μ μ§μν©λλ€: |
|
|
|
```python |
|
from datasets import load_dataset |
|
|
|
# μμ 1: λ‘컬 ν΄λ |
|
dataset = load_dataset("imagefolder", data_dir="path_to_your_folder") |
|
|
|
# μμ 2: λ‘컬 νμΌ (μ§μ ν¬λ§· : tar, gzip, zip, xz, rar, zstd) |
|
dataset = load_dataset("imagefolder", data_files="path_to_zip_file") |
|
|
|
# μμ 3: μ격 νμΌ (μ§μ ν¬λ§· : tar, gzip, zip, xz, rar, zstd) |
|
dataset = load_dataset( |
|
"imagefolder", |
|
data_files="https://download.microsoft.com/download/3/E/1/3E1C3F21-ECDB-4869-8368-6DEBA77B919F/kagglecatsanddogs_3367a.zip", |
|
) |
|
|
|
# μμ 4: μ¬λ¬κ°λ‘ λΆν |
|
dataset = load_dataset( |
|
"imagefolder", data_files={"train": ["path/to/file1", "path/to/file2"], "test": ["path/to/file3", "path/to/file4"]} |
|
) |
|
``` |
|
|
|
[push_to_hub(https://huggingface.co/docs/datasets/v2.13.1/en/package_reference/main_classes#datasets.Dataset.push_to_hub) μ μ¬μ©ν΄μ Hubμ λ°μ΄ν°μ
μ μ
λ‘λ ν©λλ€: |
|
|
|
```python |
|
# ν°λ―Έλμμ huggingface-cli login 컀맨λλ₯Ό μ΄λ―Έ μ€ννλ€κ³ κ°μ ν©λλ€ |
|
dataset.push_to_hub("name_of_your_dataset") |
|
|
|
# κ°μΈ repoλ‘ push νκ³ μΆλ€λ©΄, `private=True` μ μΆκ°νμΈμ: |
|
dataset.push_to_hub("name_of_your_dataset", private=True) |
|
``` |
|
|
|
μ΄μ λ°μ΄ν°μ
μ΄λ¦μ `--dataset_name` μΈμμ μ λ¬νμ¬ λ°μ΄ν°μ
μ νμ΅μ μ¬μ©ν μ μμ΅λλ€: |
|
|
|
```bash |
|
accelerate launch --mixed_precision="fp16" train_text_to_image.py \ |
|
--pretrained_model_name_or_path="runwayml/stable-diffusion-v1-5" \ |
|
--dataset_name="name_of_your_dataset" \ |
|
<other-arguments> |
|
``` |
|
|
|
## λ€μ λ¨κ³ |
|
|
|
λ°μ΄ν°μ
μ μμ±νμΌλ μ΄μ νμ΅ μ€ν¬λ¦½νΈμ `train_data_dir` (λ°μ΄ν°μ
μ΄ λ‘컬μ΄λ©΄) νΉμ `dataset_name` (Hubμ λ°μ΄ν°μ
μ μ¬λ ΈμΌλ©΄) μΈμμ μ°κ²°ν μ μμ΅λλ€. |
|
|
|
λ€μ λ¨κ³μμλ λ°μ΄ν°μ
μ μ¬μ©νμ¬ [unconditional μμ±](https://huggingface.co/docs/diffusers/v0.18.2/en/training/unconditional_training) λλ [ν
μ€νΈ-μ΄λ―Έμ§ μμ±](https://huggingface.co/docs/diffusers/training/text2image)μ μν λͺ¨λΈμ νμ΅μμΌλ³΄μΈμ! |
|
|