Fixes for aug pipeline
This commit is contained in:
1 parent
07bf7bd7de
commit
d46112a354
3 files changed
+21
-5
No files matched your search
@@ -126,9 +126,13 @@ class SDTrainer(BaseSDTrainProcess):
|
|||||||
loss = loss.mean()
|
loss = loss.mean()
|
||||||
return loss
|
return loss
|
||||||
|
|
||||||
def hook_train_loop(self, batch):
|
def preprocess_batch(self, batch: 'DataLoaderBatchDTO'):
|
||||||
|
return batch
|
||||||
|
|
||||||
|
def hook_train_loop(self, batch: 'DataLoaderBatchDTO'):
|
||||||
|
|
||||||
self.timer.start('preprocess_batch')
|
self.timer.start('preprocess_batch')
|
||||||
|
batch = self.preprocess_batch(batch)
|
||||||
dtype = get_torch_dtype(self.train_config.dtype)
|
dtype = get_torch_dtype(self.train_config.dtype)
|
||||||
noisy_latents, noise, timesteps, conditioned_prompts, imgs = self.process_general_training_batch(batch)
|
noisy_latents, noise, timesteps, conditioned_prompts, imgs = self.process_general_training_batch(batch)
|
||||||
network_weight_list = batch.get_network_weight_list()
|
network_weight_list = batch.get_network_weight_list()
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ class TrainConfig:
|
|||||||
|
|
||||||
match_adapter_assist = kwargs.get('match_adapter_assist', False)
|
match_adapter_assist = kwargs.get('match_adapter_assist', False)
|
||||||
self.match_adapter_chance = kwargs.get('match_adapter_chance', 0.0)
|
self.match_adapter_chance = kwargs.get('match_adapter_chance', 0.0)
|
||||||
self.loss_target: LossTarget = kwargs.get('loss_target', 'noise') # noise, source, unaugmented,
|
self.loss_target: LossTarget = kwargs.get('loss_target', 'noise') # noise, source, unaugmented, differential_noise
|
||||||
|
|
||||||
# legacy
|
# legacy
|
||||||
if match_adapter_assist and self.match_adapter_chance == 0.0:
|
if match_adapter_assist and self.match_adapter_chance == 0.0:
|
||||||
@@ -262,6 +262,7 @@ class DatasetConfig:
|
|||||||
# https://albumentations.ai/docs/api_reference/augmentations/transforms
|
# https://albumentations.ai/docs/api_reference/augmentations/transforms
|
||||||
# augmentations are returned as a separate image and cannot currently be cached
|
# augmentations are returned as a separate image and cannot currently be cached
|
||||||
self.augmentations: List[dict] = kwargs.get('augmentations', None)
|
self.augmentations: List[dict] = kwargs.get('augmentations', None)
|
||||||
|
self.shuffle_augmentations: bool = kwargs.get('shuffle_augmentations', False)
|
||||||
|
|
||||||
has_augmentations = self.augmentations is not None and len(self.augmentations) > 0
|
has_augmentations = self.augmentations is not None and len(self.augmentations) > 0
|
||||||
|
|
||||||
|
|||||||
@@ -496,10 +496,17 @@ class AugmentationFileItemDTOMixin:
|
|||||||
self.has_augmentations = False
|
self.has_augmentations = False
|
||||||
self.unaugmented_tensor: Union[torch.Tensor, None] = None
|
self.unaugmented_tensor: Union[torch.Tensor, None] = None
|
||||||
# self.augmentations: Union[None, List[Augments]] = None
|
# self.augmentations: Union[None, List[Augments]] = None
|
||||||
dataset_config: 'DatasetConfig' = kwargs.get('dataset_config', None)
|
self.dataset_config: 'DatasetConfig' = kwargs.get('dataset_config', None)
|
||||||
if dataset_config.augmentations is not None and len(dataset_config.augmentations) > 0:
|
self.build_augmentation_transform()
|
||||||
|
|
||||||
|
def build_augmentation_transform(self: 'FileItemDTO'):
|
||||||
|
if self.dataset_config.augmentations is not None and len(self.dataset_config.augmentations) > 0:
|
||||||
self.has_augmentations = True
|
self.has_augmentations = True
|
||||||
augmentations = [Augments(**aug) for aug in dataset_config.augmentations]
|
augmentations = [Augments(**aug) for aug in self.dataset_config.augmentations]
|
||||||
|
|
||||||
|
if self.dataset_config.shuffle_augmentations:
|
||||||
|
random.shuffle(augmentations)
|
||||||
|
|
||||||
augmentation_list = []
|
augmentation_list = []
|
||||||
for aug in augmentations:
|
for aug in augmentations:
|
||||||
# make sure method name is valid
|
# make sure method name is valid
|
||||||
@@ -513,6 +520,10 @@ class AugmentationFileItemDTOMixin:
|
|||||||
|
|
||||||
def augment_image(self: 'FileItemDTO', img: Image, transform: Union[None, transforms.Compose], ):
|
def augment_image(self: 'FileItemDTO', img: Image, transform: Union[None, transforms.Compose], ):
|
||||||
|
|
||||||
|
# rebuild each time if shuffle
|
||||||
|
if self.dataset_config.shuffle_augmentations:
|
||||||
|
self.build_augmentation_transform()
|
||||||
|
|
||||||
# save the original tensor
|
# save the original tensor
|
||||||
self.unaugmented_tensor = transforms.ToTensor()(img) if transform is None else transform(img)
|
self.unaugmented_tensor = transforms.ToTensor()(img) if transform is None else transform(img)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user