-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from invoke-ai/ryan/dreambooth-prep
Preparation for DreamBooth
- Loading branch information
Showing
22 changed files
with
353 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import argparse | ||
from pathlib import Path | ||
|
||
import yaml | ||
|
||
from invoke_training.training.config.finetune_lora_config import DreamBoothLoRAConfig | ||
from invoke_training.training.dreambooth_lora.dreambooth_lora_sd import run_training | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser( | ||
description="DreamBooth training with LoRA for Stable Diffusion v1 and v2 base models." | ||
) | ||
parser.add_argument( | ||
"--cfg-file", | ||
type=Path, | ||
required=True, | ||
help="Path to the YAML training config file. See `DreamBoothLoRAConfig` for the supported fields.", | ||
) | ||
return parser.parse_args() | ||
|
||
|
||
def main(): | ||
args = parse_args() | ||
|
||
# Load YAML config file. | ||
with open(args.cfg_file, "r") as f: | ||
cfg = yaml.safe_load(f) | ||
|
||
train_config = DreamBoothLoRAConfig(**cfg) | ||
|
||
run_training(train_config) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
36 changes: 36 additions & 0 deletions
36
src/invoke_training/scripts/invoke_dreambooth_lora_sdxl.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import argparse | ||
from pathlib import Path | ||
|
||
import yaml | ||
|
||
from invoke_training.training.config.finetune_lora_config import ( | ||
DreamBoothLoRASDXLConfig, | ||
) | ||
from invoke_training.training.dreambooth_lora.dreambooth_lora_sd import run_training | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser(description="DreamBooth training with LoRA for Stable Diffusion XL base models.") | ||
parser.add_argument( | ||
"--cfg-file", | ||
type=Path, | ||
required=True, | ||
help="Path to the YAML training config file. See `DreamBoothLoRASDXLConfig` for the supported fields.", | ||
) | ||
return parser.parse_args() | ||
|
||
|
||
def main(): | ||
args = parse_args() | ||
|
||
# Load YAML config file. | ||
with open(args.cfg_file, "r") as f: | ||
cfg = yaml.safe_load(f) | ||
|
||
train_config = DreamBoothLoRASDXLConfig(**cfg) | ||
|
||
run_training(train_config) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import typing | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class ImageTransformConfig(BaseModel): | ||
# The resolution for input images. All of the images in the dataset will be resized to this (square) resolution. | ||
resolution: int = 512 | ||
|
||
# If True, input images will be center-cropped to resolution. | ||
# If False, input images will be randomly cropped to resolution. | ||
center_crop: bool = False | ||
|
||
# Whether random flip augmentations should be applied to input images. | ||
random_flip: bool = False | ||
|
||
|
||
class ImageCaptionDatasetConfig(BaseModel): | ||
# The name of a Hugging Face dataset. | ||
# One of dataset_name and dataset_dir should be set (dataset_name takes precedence). | ||
# See also: dataset_config_name. | ||
dataset_name: typing.Optional[str] = None | ||
|
||
# The directory to load a dataset from. The dataset is expected to be in | ||
# Hugging Face imagefolder format (https://huggingface.co/docs/datasets/v2.4.0/en/image_load#imagefolder). | ||
# One of 'dataset_name' and 'dataset_dir' should be set ('dataset_name' takes precedence). | ||
dataset_dir: typing.Optional[str] = None | ||
|
||
# The Hugging Face dataset config name. Leave as None if there's only one config. | ||
# This parameter is only used if dataset_name is set. | ||
dataset_config_name: typing.Optional[str] = None | ||
|
||
# The Hugging Face cache directory to use for dataset downloads. | ||
# If None, the default value will be used (usually '~/.cache/huggingface/datasets'). | ||
hf_cache_dir: typing.Optional[str] = None | ||
|
||
# The name of the dataset column that contains image paths. | ||
image_column: str = "image" | ||
|
||
# The name of the dataset column that contains captions. | ||
caption_column: str = "text" | ||
|
||
# Number of subprocesses to use for data loading. 0 means that the data will be loaded in the main process. | ||
dataloader_num_workers: int = 0 | ||
|
||
image_transforms: ImageTransformConfig | ||
|
||
|
||
class ImageDirDatasetConfig(BaseModel): | ||
# The directory to load images from. | ||
dataset_dir: str | ||
|
||
# The image file extensions to include in the dataset. | ||
# If None, then the following file extensions will be loaded: [".png", ".jpg", ".jpeg"]. | ||
image_file_extensions: typing.Optional[list[str]] = None | ||
|
||
image_transforms: ImageTransformConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
5 changes: 5 additions & 0 deletions
5
src/invoke_training/training/dreambooth_lora/dreambooth_lora_sd.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from invoke_training.training.config.finetune_lora_config import DreamBoothLoRAConfig | ||
|
||
|
||
def run_training(config: DreamBoothLoRAConfig): | ||
raise NotImplementedError |
7 changes: 7 additions & 0 deletions
7
src/invoke_training/training/dreambooth_lora/dreambooth_lora_sdxl.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from invoke_training.training.config.finetune_lora_config import ( | ||
DreamBoothLoRASDXLConfig, | ||
) | ||
|
||
|
||
def run_training(config: DreamBoothLoRASDXLConfig): | ||
raise NotImplementedError |
Oops, something went wrong.