Spaces:
Runtime error
Runtime error
adaface-neurips
commited on
Commit
Β·
aa5aad2
1
Parent(s):
bd5559e
Reorganize code files
Browse files- __init__.py +0 -0
- app.py +2 -2
- {BiSeNet β lib/BiSeNet}/6.jpg +0 -0
- {BiSeNet β lib/BiSeNet}/__init__.py +0 -0
- {BiSeNet β lib/BiSeNet}/evaluate.py +0 -0
- {BiSeNet β lib/BiSeNet}/face_dataset.py +0 -0
- {BiSeNet β lib/BiSeNet}/hair.png +0 -0
- {BiSeNet β lib/BiSeNet}/logger.py +0 -0
- {BiSeNet β lib/BiSeNet}/loss.py +0 -3
- {BiSeNet β lib/BiSeNet}/makeup.py +0 -1
- {BiSeNet β lib/BiSeNet}/makeup/116_1.png +0 -0
- {BiSeNet β lib/BiSeNet}/makeup/116_3.png +0 -0
- {BiSeNet β lib/BiSeNet}/makeup/116_lip_ori.png +0 -0
- {BiSeNet β lib/BiSeNet}/makeup/116_ori.png +0 -0
- {BiSeNet β lib/BiSeNet}/model.py +1 -2
- {BiSeNet β lib/BiSeNet}/modules/__init__.py +0 -0
- {BiSeNet β lib/BiSeNet}/modules/bn.py +0 -0
- {BiSeNet β lib/BiSeNet}/modules/deeplab.py +0 -0
- {BiSeNet β lib/BiSeNet}/modules/dense.py +0 -0
- {BiSeNet β lib/BiSeNet}/modules/functions.py +0 -0
- {BiSeNet β lib/BiSeNet}/modules/misc.py +0 -0
- {BiSeNet β lib/BiSeNet}/modules/residual.py +0 -0
- {BiSeNet β lib/BiSeNet}/modules/src/checks.h +0 -0
- {BiSeNet β lib/BiSeNet}/modules/src/inplace_abn.cpp +0 -0
- {BiSeNet β lib/BiSeNet}/modules/src/inplace_abn.h +0 -0
- {BiSeNet β lib/BiSeNet}/modules/src/inplace_abn_cpu.cpp +0 -0
- {BiSeNet β lib/BiSeNet}/modules/src/inplace_abn_cuda.cu +0 -0
- {BiSeNet β lib/BiSeNet}/modules/src/inplace_abn_cuda_half.cu +0 -0
- {BiSeNet β lib/BiSeNet}/modules/src/utils/checks.h +0 -0
- {BiSeNet β lib/BiSeNet}/modules/src/utils/common.h +0 -0
- {BiSeNet β lib/BiSeNet}/modules/src/utils/cuda.cuh +0 -0
- {BiSeNet β lib/BiSeNet}/optimizer.py +0 -0
- {BiSeNet β lib/BiSeNet}/prepropess_data.py +0 -0
- {BiSeNet β lib/BiSeNet}/resnet.py +0 -0
- {BiSeNet β lib/BiSeNet}/test.py +0 -0
- {BiSeNet β lib/BiSeNet}/train.py +0 -0
- {BiSeNet β lib/BiSeNet}/transform.py +0 -0
- attention.py β lib/attention.py +1 -2
- functions.py β lib/functions.py +0 -0
- pipline_ConsistentID.py β lib/pipline_ConsistentID.py +16 -13
__init__.py
ADDED
File without changes
|
app.py
CHANGED
@@ -8,11 +8,11 @@ import numpy as np
|
|
8 |
from PIL import Image
|
9 |
from diffusers.utils import load_image
|
10 |
from diffusers import EulerDiscreteScheduler
|
11 |
-
from pipline_ConsistentID import ConsistentIDPipeline
|
12 |
import argparse
|
13 |
parser = argparse.ArgumentParser()
|
14 |
parser.add_argument('--base_model_path', type=str,
|
15 |
-
default="SG161222/Realistic_Vision_V4.0_noVAE")
|
16 |
parser.add_argument('--gpu', type=int, default=0)
|
17 |
args = parser.parse_args()
|
18 |
|
|
|
8 |
from PIL import Image
|
9 |
from diffusers.utils import load_image
|
10 |
from diffusers import EulerDiscreteScheduler
|
11 |
+
from lib.pipline_ConsistentID import ConsistentIDPipeline
|
12 |
import argparse
|
13 |
parser = argparse.ArgumentParser()
|
14 |
parser.add_argument('--base_model_path', type=str,
|
15 |
+
default="models/SG161222/Realistic_Vision_V4.0_noVAE")
|
16 |
parser.add_argument('--gpu', type=int, default=0)
|
17 |
args = parser.parse_args()
|
18 |
|
{BiSeNet β lib/BiSeNet}/6.jpg
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/__init__.py
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/evaluate.py
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/face_dataset.py
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/hair.png
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/logger.py
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/loss.py
RENAMED
@@ -6,9 +6,6 @@ import torch
|
|
6 |
import torch.nn as nn
|
7 |
import torch.nn.functional as F
|
8 |
|
9 |
-
import numpy as np
|
10 |
-
|
11 |
-
|
12 |
class OhemCELoss(nn.Module):
|
13 |
def __init__(self, thresh, n_min, ignore_lb=255, *args, **kwargs):
|
14 |
super(OhemCELoss, self).__init__()
|
|
|
6 |
import torch.nn as nn
|
7 |
import torch.nn.functional as F
|
8 |
|
|
|
|
|
|
|
9 |
class OhemCELoss(nn.Module):
|
10 |
def __init__(self, thresh, n_min, ignore_lb=255, *args, **kwargs):
|
11 |
super(OhemCELoss, self).__init__()
|
{BiSeNet β lib/BiSeNet}/makeup.py
RENAMED
@@ -1,5 +1,4 @@
|
|
1 |
import cv2
|
2 |
-
import os
|
3 |
import numpy as np
|
4 |
from skimage.filters import gaussian
|
5 |
|
|
|
1 |
import cv2
|
|
|
2 |
import numpy as np
|
3 |
from skimage.filters import gaussian
|
4 |
|
{BiSeNet β lib/BiSeNet}/makeup/116_1.png
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/makeup/116_3.png
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/makeup/116_lip_ori.png
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/makeup/116_ori.png
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/model.py
RENAMED
@@ -5,9 +5,8 @@
|
|
5 |
import torch
|
6 |
import torch.nn as nn
|
7 |
import torch.nn.functional as F
|
8 |
-
import torchvision
|
9 |
|
10 |
-
from
|
11 |
# from modules.bn import InPlaceABNSync as BatchNorm2d
|
12 |
|
13 |
|
|
|
5 |
import torch
|
6 |
import torch.nn as nn
|
7 |
import torch.nn.functional as F
|
|
|
8 |
|
9 |
+
from .resnet import Resnet18
|
10 |
# from modules.bn import InPlaceABNSync as BatchNorm2d
|
11 |
|
12 |
|
{BiSeNet β lib/BiSeNet}/modules/__init__.py
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/modules/bn.py
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/modules/deeplab.py
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/modules/dense.py
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/modules/functions.py
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/modules/misc.py
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/modules/residual.py
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/modules/src/checks.h
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/modules/src/inplace_abn.cpp
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/modules/src/inplace_abn.h
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/modules/src/inplace_abn_cpu.cpp
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/modules/src/inplace_abn_cuda.cu
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/modules/src/inplace_abn_cuda_half.cu
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/modules/src/utils/checks.h
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/modules/src/utils/common.h
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/modules/src/utils/cuda.cuh
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/optimizer.py
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/prepropess_data.py
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/resnet.py
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/test.py
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/train.py
RENAMED
File without changes
|
{BiSeNet β lib/BiSeNet}/transform.py
RENAMED
File without changes
|
attention.py β lib/attention.py
RENAMED
@@ -2,8 +2,7 @@ import torch
|
|
2 |
import torch.nn as nn
|
3 |
import torch.nn.functional as F
|
4 |
from diffusers.models.lora import LoRALinearLayer
|
5 |
-
from functions import AttentionMLP
|
6 |
-
|
7 |
|
8 |
class FuseModule(nn.Module):
|
9 |
def __init__(self, embed_dim):
|
|
|
2 |
import torch.nn as nn
|
3 |
import torch.nn.functional as F
|
4 |
from diffusers.models.lora import LoRALinearLayer
|
5 |
+
from .functions import AttentionMLP
|
|
|
6 |
|
7 |
class FuseModule(nn.Module):
|
8 |
def __init__(self, embed_dim):
|
functions.py β lib/functions.py
RENAMED
File without changes
|
pipline_ConsistentID.py β lib/pipline_ConsistentID.py
RENAMED
@@ -13,15 +13,15 @@ from transformers import CLIPImageProcessor, CLIPVisionModelWithProjection
|
|
13 |
from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
|
14 |
from diffusers.pipelines.stable_diffusion import StableDiffusionPipeline
|
15 |
from diffusers.utils.import_utils import is_xformers_available
|
16 |
-
from functions import insert_markers_to_prompt, masks_for_unique_values, apply_mask_to_raw_image, tokenize_and_mask_noun_phrases_ends, prepare_image_token_idx
|
17 |
-
from functions import ProjPlusModel, masks_for_unique_values
|
18 |
-
from attention import Consistent_IPAttProcessor, Consistent_AttProcessor, FacialEncoder
|
19 |
from easydict import EasyDict as edict
|
20 |
from huggingface_hub import hf_hub_download
|
21 |
### Model can be imported from https://github.com/zllrunning/face-parsing.PyTorch?tab=readme-ov-file
|
22 |
### We use the ckpt of 79999_iter.pth: https://drive.google.com/open?id=154JgKpzCPW82qINcVieuPH3fZ2e0P812
|
23 |
### Thanks for the open source of face-parsing model.
|
24 |
-
from BiSeNet.model import BiSeNet
|
25 |
import os
|
26 |
|
27 |
PipelineImageInput = Union[
|
@@ -33,7 +33,7 @@ PipelineImageInput = Union[
|
|
33 |
|
34 |
### Download the pretrained model from huggingface and put it locally, then place the model in a local directory and specify the directory location.
|
35 |
class ConsistentIDPipeline(StableDiffusionPipeline):
|
36 |
-
|
37 |
def cuda(self, dtype=torch.float16, use_xformers=False):
|
38 |
self.to('cuda', dtype)
|
39 |
|
@@ -364,14 +364,17 @@ class ConsistentIDPipeline(StableDiffusionPipeline):
|
|
364 |
|
365 |
return parsed_image_parts, facial_masks, key_masked_raw_images_dict
|
366 |
|
367 |
-
# Release the unet
|
368 |
-
def
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
|
|
|
|
|
|
375 |
|
376 |
# input_subj_image_obj: an Image object.
|
377 |
def generate_id_prompt_embeds(self, prompt, negative_prompt, input_subj_image_obj, device, calc_uncond=True):
|
|
|
13 |
from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
|
14 |
from diffusers.pipelines.stable_diffusion import StableDiffusionPipeline
|
15 |
from diffusers.utils.import_utils import is_xformers_available
|
16 |
+
from .functions import insert_markers_to_prompt, masks_for_unique_values, apply_mask_to_raw_image, tokenize_and_mask_noun_phrases_ends, prepare_image_token_idx
|
17 |
+
from .functions import ProjPlusModel, masks_for_unique_values
|
18 |
+
from .attention import Consistent_IPAttProcessor, Consistent_AttProcessor, FacialEncoder
|
19 |
from easydict import EasyDict as edict
|
20 |
from huggingface_hub import hf_hub_download
|
21 |
### Model can be imported from https://github.com/zllrunning/face-parsing.PyTorch?tab=readme-ov-file
|
22 |
### We use the ckpt of 79999_iter.pth: https://drive.google.com/open?id=154JgKpzCPW82qINcVieuPH3fZ2e0P812
|
23 |
### Thanks for the open source of face-parsing model.
|
24 |
+
from .BiSeNet.model import BiSeNet
|
25 |
import os
|
26 |
|
27 |
PipelineImageInput = Union[
|
|
|
33 |
|
34 |
### Download the pretrained model from huggingface and put it locally, then place the model in a local directory and specify the directory location.
|
35 |
class ConsistentIDPipeline(StableDiffusionPipeline):
|
36 |
+
|
37 |
def cuda(self, dtype=torch.float16, use_xformers=False):
|
38 |
self.to('cuda', dtype)
|
39 |
|
|
|
364 |
|
365 |
return parsed_image_parts, facial_masks, key_masked_raw_images_dict
|
366 |
|
367 |
+
# Release the unet or vae to save memory.
|
368 |
+
def release_components(self, release_unet=False, release_vae=True):
|
369 |
+
if release_unet:
|
370 |
+
unet = edict()
|
371 |
+
# Only keep the config and in_channels attributes that are used in the pipeline.
|
372 |
+
unet.config = self.unet.config
|
373 |
+
unet.in_channels = self.unet.in_channels
|
374 |
+
self.unet = unet
|
375 |
+
|
376 |
+
if release_vae:
|
377 |
+
self.vae = None
|
378 |
|
379 |
# input_subj_image_obj: an Image object.
|
380 |
def generate_id_prompt_embeds(self, prompt, negative_prompt, input_subj_image_obj, device, calc_uncond=True):
|