generated from okotaku/template
-
Notifications
You must be signed in to change notification settings - Fork 10
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 #133 from okotaku/feat/ip_adapter_dino
[Feat] IP Adapter DINO
- Loading branch information
Showing
14 changed files
with
317 additions
and
251 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
diffengine/configs/_base_/datasets/pokemon_blip_xl_ip_adapter_dinov2.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,60 @@ | ||
import torchvision | ||
from mmengine.dataset import DefaultSampler | ||
|
||
from diffengine.datasets import HFDataset | ||
from diffengine.datasets.transforms import ( | ||
ComputeTimeIds, | ||
PackInputs, | ||
RandomCrop, | ||
RandomHorizontalFlip, | ||
RandomTextDrop, | ||
SaveImageShape, | ||
TorchVisonTransformWrapper, | ||
TransformersImageProcessor, | ||
) | ||
from diffengine.engine.hooks import IPAdapterSaveHook, VisualizationHook | ||
|
||
train_pipeline = [ | ||
dict(type=SaveImageShape), | ||
dict(type=TransformersImageProcessor, | ||
pretrained="facebook/dinov2-base"), | ||
dict(type=RandomTextDrop), | ||
dict(type=TorchVisonTransformWrapper, | ||
transform=torchvision.transforms.Resize, | ||
size=1024, interpolation="bilinear"), | ||
dict(type=RandomCrop, size=1024), | ||
dict(type=RandomHorizontalFlip, p=0.5), | ||
dict(type=ComputeTimeIds), | ||
dict(type=TorchVisonTransformWrapper, | ||
transform=torchvision.transforms.ToTensor), | ||
dict(type=TorchVisonTransformWrapper, | ||
transform=torchvision.transforms.Normalize, mean=[0.5], std=[0.5]), | ||
dict( | ||
type=PackInputs, input_keys=["img", "text", "time_ids", "clip_img"]), | ||
] | ||
train_dataloader = dict( | ||
batch_size=2, | ||
num_workers=2, | ||
dataset=dict( | ||
type=HFDataset, | ||
dataset="lambdalabs/pokemon-blip-captions", | ||
pipeline=train_pipeline), | ||
sampler=dict(type=DefaultSampler, shuffle=True), | ||
) | ||
|
||
val_dataloader = None | ||
val_evaluator = None | ||
test_dataloader = val_dataloader | ||
test_evaluator = val_evaluator | ||
|
||
custom_hooks = [ | ||
dict( | ||
type=VisualizationHook, | ||
prompt=["a drawing of a green pokemon with red eyes"] * 2 + [""] * 2, | ||
example_image=[ | ||
'https://github.com/LambdaLabsML/examples/blob/main/stable-diffusion-finetuning/README_files/README_2_0.png?raw=true' # noqa | ||
] * 4, | ||
height=1024, | ||
width=1024), | ||
dict(type=IPAdapterSaveHook), | ||
] |
60 changes: 60 additions & 0 deletions
60
diffengine/configs/_base_/datasets/pokemon_blip_xl_ip_adapter_dinov2_giant.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,60 @@ | ||
import torchvision | ||
from mmengine.dataset import DefaultSampler | ||
|
||
from diffengine.datasets import HFDataset | ||
from diffengine.datasets.transforms import ( | ||
ComputeTimeIds, | ||
PackInputs, | ||
RandomCrop, | ||
RandomHorizontalFlip, | ||
RandomTextDrop, | ||
SaveImageShape, | ||
TorchVisonTransformWrapper, | ||
TransformersImageProcessor, | ||
) | ||
from diffengine.engine.hooks import IPAdapterSaveHook, VisualizationHook | ||
|
||
train_pipeline = [ | ||
dict(type=SaveImageShape), | ||
dict(type=TransformersImageProcessor, | ||
pretrained="facebook/dinov2-giant"), | ||
dict(type=RandomTextDrop), | ||
dict(type=TorchVisonTransformWrapper, | ||
transform=torchvision.transforms.Resize, | ||
size=1024, interpolation="bilinear"), | ||
dict(type=RandomCrop, size=1024), | ||
dict(type=RandomHorizontalFlip, p=0.5), | ||
dict(type=ComputeTimeIds), | ||
dict(type=TorchVisonTransformWrapper, | ||
transform=torchvision.transforms.ToTensor), | ||
dict(type=TorchVisonTransformWrapper, | ||
transform=torchvision.transforms.Normalize, mean=[0.5], std=[0.5]), | ||
dict( | ||
type=PackInputs, input_keys=["img", "text", "time_ids", "clip_img"]), | ||
] | ||
train_dataloader = dict( | ||
batch_size=2, | ||
num_workers=2, | ||
dataset=dict( | ||
type=HFDataset, | ||
dataset="lambdalabs/pokemon-blip-captions", | ||
pipeline=train_pipeline), | ||
sampler=dict(type=DefaultSampler, shuffle=True), | ||
) | ||
|
||
val_dataloader = None | ||
val_evaluator = None | ||
test_dataloader = val_dataloader | ||
test_evaluator = val_evaluator | ||
|
||
custom_hooks = [ | ||
dict( | ||
type=VisualizationHook, | ||
prompt=["a drawing of a green pokemon with red eyes"] * 2 + [""] * 2, | ||
example_image=[ | ||
'https://github.com/LambdaLabsML/examples/blob/main/stable-diffusion-finetuning/README_files/README_2_0.png?raw=true' # noqa | ||
] * 4, | ||
height=1024, | ||
width=1024), | ||
dict(type=IPAdapterSaveHook), | ||
] |
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
22 changes: 22 additions & 0 deletions
22
diffengine/configs/ip_adapter/stable_diffusion_xl_pokemon_blip_ip_adapter_plus_dinov2.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,22 @@ | ||
from mmengine.config import read_base | ||
from transformers import AutoImageProcessor, Dinov2Model | ||
|
||
with read_base(): | ||
from .._base_.datasets.pokemon_blip_xl_ip_adapter_dinov2 import * | ||
from .._base_.default_runtime import * | ||
from .._base_.models.stable_diffusion_xl_ip_adapter_plus import * | ||
from .._base_.schedules.stable_diffusion_xl_50e import * | ||
|
||
|
||
model.image_encoder = dict( | ||
type=Dinov2Model.from_pretrained, | ||
pretrained_model_name_or_path="facebook/dinov2-base") | ||
model.feature_extractor = dict( | ||
type=AutoImageProcessor.from_pretrained, | ||
pretrained_model_name_or_path="facebook/dinov2-base") | ||
|
||
train_dataloader.update(batch_size=1) | ||
|
||
optim_wrapper.update(accumulative_counts=4) # update every four times | ||
|
||
train_cfg.update(by_epoch=True, max_epochs=100) |
22 changes: 22 additions & 0 deletions
22
...ngine/configs/ip_adapter/stable_diffusion_xl_pokemon_blip_ip_adapter_plus_dinov2_giant.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,22 @@ | ||
from mmengine.config import read_base | ||
from transformers import AutoImageProcessor, Dinov2Model | ||
|
||
with read_base(): | ||
from .._base_.datasets.pokemon_blip_xl_ip_adapter_dinov2_giant import * | ||
from .._base_.default_runtime import * | ||
from .._base_.models.stable_diffusion_xl_ip_adapter_plus import * | ||
from .._base_.schedules.stable_diffusion_xl_50e import * | ||
|
||
|
||
model.image_encoder = dict( | ||
type=Dinov2Model.from_pretrained, | ||
pretrained_model_name_or_path="facebook/dinov2-giant") | ||
model.feature_extractor = dict( | ||
type=AutoImageProcessor.from_pretrained, | ||
pretrained_model_name_or_path="facebook/dinov2-giant") | ||
|
||
train_dataloader.update(batch_size=1) | ||
|
||
optim_wrapper.update(accumulative_counts=4) # update every four times | ||
|
||
train_cfg.update(by_epoch=True, max_epochs=100) |
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
Oops, something went wrong.