adaface-neurips commited on
Commit
bd5559e
Β·
1 Parent(s): ad6476f

Reorganize bisenet code location, add comments, remove dead code

Browse files
Files changed (37) hide show
  1. {models/BiSeNet β†’ BiSeNet}/6.jpg +0 -0
  2. {models/BiSeNet β†’ BiSeNet}/__init__.py +0 -0
  3. {models/BiSeNet β†’ BiSeNet}/evaluate.py +1 -1
  4. {models/BiSeNet β†’ BiSeNet}/face_dataset.py +0 -0
  5. {models/BiSeNet β†’ BiSeNet}/hair.png +0 -0
  6. {models/BiSeNet β†’ BiSeNet}/logger.py +0 -0
  7. {models/BiSeNet β†’ BiSeNet}/loss.py +0 -0
  8. {models/BiSeNet β†’ BiSeNet}/makeup.py +0 -0
  9. {models/BiSeNet β†’ BiSeNet}/makeup/116_1.png +0 -0
  10. {models/BiSeNet β†’ BiSeNet}/makeup/116_3.png +0 -0
  11. {models/BiSeNet β†’ BiSeNet}/makeup/116_lip_ori.png +0 -0
  12. {models/BiSeNet β†’ BiSeNet}/makeup/116_ori.png +0 -0
  13. {models/BiSeNet β†’ BiSeNet}/model.py +1 -1
  14. {models/BiSeNet β†’ BiSeNet}/modules/__init__.py +0 -0
  15. {models/BiSeNet β†’ BiSeNet}/modules/bn.py +0 -0
  16. {models/BiSeNet β†’ BiSeNet}/modules/deeplab.py +0 -0
  17. {models/BiSeNet β†’ BiSeNet}/modules/dense.py +0 -0
  18. {models/BiSeNet β†’ BiSeNet}/modules/functions.py +0 -0
  19. {models/BiSeNet β†’ BiSeNet}/modules/misc.py +0 -0
  20. {models/BiSeNet β†’ BiSeNet}/modules/residual.py +0 -0
  21. {models/BiSeNet β†’ BiSeNet}/modules/src/checks.h +0 -0
  22. {models/BiSeNet β†’ BiSeNet}/modules/src/inplace_abn.cpp +0 -0
  23. {models/BiSeNet β†’ BiSeNet}/modules/src/inplace_abn.h +0 -0
  24. {models/BiSeNet β†’ BiSeNet}/modules/src/inplace_abn_cpu.cpp +0 -0
  25. {models/BiSeNet β†’ BiSeNet}/modules/src/inplace_abn_cuda.cu +0 -0
  26. {models/BiSeNet β†’ BiSeNet}/modules/src/inplace_abn_cuda_half.cu +0 -0
  27. {models/BiSeNet β†’ BiSeNet}/modules/src/utils/checks.h +0 -0
  28. {models/BiSeNet β†’ BiSeNet}/modules/src/utils/common.h +0 -0
  29. {models/BiSeNet β†’ BiSeNet}/modules/src/utils/cuda.cuh +0 -0
  30. {models/BiSeNet β†’ BiSeNet}/optimizer.py +0 -0
  31. {models/BiSeNet β†’ BiSeNet}/prepropess_data.py +0 -0
  32. {models/BiSeNet β†’ BiSeNet}/resnet.py +0 -0
  33. {models/BiSeNet β†’ BiSeNet}/test.py +1 -1
  34. {models/BiSeNet β†’ BiSeNet}/train.py +2 -2
  35. {models/BiSeNet β†’ BiSeNet}/transform.py +0 -0
  36. app.py +9 -15
  37. pipline_ConsistentID.py +5 -7
{models/BiSeNet β†’ BiSeNet}/6.jpg RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/__init__.py RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/evaluate.py RENAMED
@@ -2,7 +2,7 @@
2
  # -*- encoding: utf-8 -*-
3
 
4
  from logger import setup_logger
5
- from model import BiSeNet
6
  from face_dataset import FaceMask
7
 
8
  import torch
 
2
  # -*- encoding: utf-8 -*-
3
 
4
  from logger import setup_logger
5
+ import BiSeNet
6
  from face_dataset import FaceMask
7
 
8
  import torch
{models/BiSeNet β†’ BiSeNet}/face_dataset.py RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/hair.png RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/logger.py RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/loss.py RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/makeup.py RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/makeup/116_1.png RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/makeup/116_3.png RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/makeup/116_lip_ori.png RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/makeup/116_ori.png RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/model.py RENAMED
@@ -7,7 +7,7 @@ import torch.nn as nn
7
  import torch.nn.functional as F
8
  import torchvision
9
 
10
- from models.BiSeNet.resnet import Resnet18
11
  # from modules.bn import InPlaceABNSync as BatchNorm2d
12
 
13
 
 
7
  import torch.nn.functional as F
8
  import torchvision
9
 
10
+ from BiSeNet.resnet import Resnet18
11
  # from modules.bn import InPlaceABNSync as BatchNorm2d
12
 
13
 
{models/BiSeNet β†’ BiSeNet}/modules/__init__.py RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/modules/bn.py RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/modules/deeplab.py RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/modules/dense.py RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/modules/functions.py RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/modules/misc.py RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/modules/residual.py RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/modules/src/checks.h RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/modules/src/inplace_abn.cpp RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/modules/src/inplace_abn.h RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/modules/src/inplace_abn_cpu.cpp RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/modules/src/inplace_abn_cuda.cu RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/modules/src/inplace_abn_cuda_half.cu RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/modules/src/utils/checks.h RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/modules/src/utils/common.h RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/modules/src/utils/cuda.cuh RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/optimizer.py RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/prepropess_data.py RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/resnet.py RENAMED
File without changes
{models/BiSeNet β†’ BiSeNet}/test.py RENAMED
@@ -2,7 +2,7 @@
2
  # -*- encoding: utf-8 -*-
3
 
4
  from logger import setup_logger
5
- from model import BiSeNet
6
 
7
  import torch
8
 
 
2
  # -*- encoding: utf-8 -*-
3
 
4
  from logger import setup_logger
5
+ import BiSeNet
6
 
7
  import torch
8
 
{models/BiSeNet β†’ BiSeNet}/train.py RENAMED
@@ -1,8 +1,8 @@
1
  #!/usr/bin/python
2
  # -*- encoding: utf-8 -*-
3
 
4
- from logger import setup_logger
5
- from model import BiSeNet
6
  from face_dataset import FaceMask
7
  from loss import OhemCELoss
8
  from evaluate import evaluate
 
1
  #!/usr/bin/python
2
  # -*- encoding: utf-8 -*-
3
 
4
+ from logger import setup_logger
5
+ import BiSeNet
6
  from face_dataset import FaceMask
7
  from loss import OhemCELoss
8
  from evaluate import evaluate
{models/BiSeNet β†’ BiSeNet}/transform.py RENAMED
File without changes
app.py CHANGED
@@ -5,26 +5,22 @@ import glob
5
  import spaces
6
  import numpy as np
7
 
8
- from datetime import datetime
9
  from PIL import Image
10
  from diffusers.utils import load_image
11
  from diffusers import EulerDiscreteScheduler
12
  from pipline_ConsistentID import ConsistentIDPipeline
 
 
 
 
 
 
13
 
14
- # zero = torch.Tensor([0]).cuda()
15
- # print(zero.device) # <-- 'cpu' πŸ€”
16
- # device = zero.device # "cuda"
17
- device = "cuda"
18
-
19
- # Gets the absolute path of the current script
20
- script_directory = os.path.dirname(os.path.realpath(__file__))
21
-
22
- # download ConsistentID checkpoint to cache
23
- base_model_path = "SG161222/Realistic_Vision_V4.0_noVAE"
24
 
25
  ### Load base model
26
  pipe = ConsistentIDPipeline.from_pretrained(
27
- base_model_path,
28
  torch_dtype=torch.float16,
29
  safety_checker=None, # use_safetensors=True,
30
  variant="fp16"
@@ -33,11 +29,10 @@ pipe = ConsistentIDPipeline.from_pretrained(
33
  ### Load consistentID_model checkpoint
34
  pipe.load_ConsistentID_model(
35
  consistentID_weight_path="./models/ConsistentID-v1.bin",
36
- bise_net_weight_path="./models/face_parsing.pth",
37
  )
38
  pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
39
 
40
-
41
  @spaces.GPU
42
  def process(selected_template_images, custom_image, prompt,
43
  negative_prompt, prompt_selected, model_selected_tab,
@@ -94,7 +89,6 @@ def process(selected_template_images, custom_image, prompt,
94
  return np.array(images)
95
 
96
  # Gets the templates
97
- script_directory = os.path.dirname(os.path.realpath(__file__))
98
  preset_template = glob.glob("./images/templates/*.png")
99
  preset_template = preset_template + glob.glob("./images/templates/*.jpg")
100
 
 
5
  import spaces
6
  import numpy as np
7
 
 
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
 
19
+ device = f"cuda:{args.gpu}"
 
 
 
 
 
 
 
 
 
20
 
21
  ### Load base model
22
  pipe = ConsistentIDPipeline.from_pretrained(
23
+ args.base_model_path,
24
  torch_dtype=torch.float16,
25
  safety_checker=None, # use_safetensors=True,
26
  variant="fp16"
 
29
  ### Load consistentID_model checkpoint
30
  pipe.load_ConsistentID_model(
31
  consistentID_weight_path="./models/ConsistentID-v1.bin",
32
+ bise_net_weight_path="./models/BiSeNet_pretrained_for_ConsistentID.pth",
33
  )
34
  pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
35
 
 
36
  @spaces.GPU
37
  def process(selected_template_images, custom_image, prompt,
38
  negative_prompt, prompt_selected, model_selected_tab,
 
89
  return np.array(images)
90
 
91
  # Gets the templates
 
92
  preset_template = glob.glob("./images/templates/*.png")
93
  preset_template = preset_template + glob.glob("./images/templates/*.jpg")
94
 
pipline_ConsistentID.py CHANGED
@@ -12,7 +12,7 @@ from huggingface_hub.utils import validate_hf_hub_args
12
  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 _get_model_file
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
@@ -21,7 +21,7 @@ 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 models.BiSeNet.model import BiSeNet
25
  import os
26
 
27
  PipelineImageInput = Union[
@@ -310,12 +310,10 @@ class ConsistentIDPipeline(StableDiffusionPipeline):
310
  max_text_length=330
311
  if len(self.tokenizer(prompt_face, max_length=self.tokenizer.model_max_length,
312
  padding="max_length", truncation=False, return_tensors="pt").input_ids[0]) != 77:
 
 
313
  prompt_face = "Detail: " + face_caption_align + " Caption:" + prompt
314
-
315
- if len(face_caption) > max_text_length:
316
- prompt_face = prompt
317
- face_caption_align = ""
318
-
319
  # Remove "<|facial|>" from prompt_face.
320
  # augmented_prompt: 'A person, police officer, half body shot Detail:
321
  # The person has one nose , two ears , two eyes , and a mouth , '
 
12
  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
 
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[
 
310
  max_text_length=330
311
  if len(self.tokenizer(prompt_face, max_length=self.tokenizer.model_max_length,
312
  padding="max_length", truncation=False, return_tensors="pt").input_ids[0]) != 77:
313
+ # Put face_caption_align at the beginning of the prompt, so that the original prompt is truncated,
314
+ # but the face_caption_align is well kept.
315
  prompt_face = "Detail: " + face_caption_align + " Caption:" + prompt
316
+
 
 
 
 
317
  # Remove "<|facial|>" from prompt_face.
318
  # augmented_prompt: 'A person, police officer, half body shot Detail:
319
  # The person has one nose , two ears , two eyes , and a mouth , '