Skip to content

Commit 8a1e729

Browse files
authored
Merge pull request #326 from hehaha68/add_zju_style
Update some features
2 parents f8fa471 + fa6fef7 commit 8a1e729

File tree

138 files changed

+873
-405
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+873
-405
lines changed

app.py

Lines changed: 88 additions & 115 deletions
Large diffs are not rendered by default.

facechain/constants.py

Lines changed: 5 additions & 274 deletions
Large diffs are not rendered by default.

facechain/inference.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def main_diffusion_inference(pos_prompt, neg_prompt,
164164
attr_idx = np.argmax(cnts_trigger)
165165
trigger_styles = ['a boy, children, ', 'a girl, children, ', 'a handsome man, ', 'a beautiful woman, ',
166166
'a mature man, ', 'a mature woman, ']
167-
trigger_style = '<fcsks>, ' + trigger_styles[attr_idx]
167+
trigger_style = '(<fcsks>:10), ' + trigger_styles[attr_idx]
168168
if attr_idx == 2 or attr_idx == 4:
169169
neg_prompt += ', children'
170170

@@ -238,7 +238,7 @@ def main_diffusion_inference_pose(pose_model_path, pose_image,
238238
attr_idx = np.argmax(cnts_trigger)
239239
trigger_styles = ['a boy, children, ', 'a girl, children, ', 'a handsome man, ', 'a beautiful woman, ',
240240
'a mature man, ', 'a mature woman, ']
241-
trigger_style = '<fcsks>, ' + trigger_styles[attr_idx]
241+
trigger_style = '(<fcsks>:10), ' + trigger_styles[attr_idx]
242242
if attr_idx == 2 or attr_idx == 4:
243243
neg_prompt += ', children'
244244

@@ -330,7 +330,7 @@ def main_diffusion_inference_multi(pose_model_path, pose_image,
330330
attr_idx = np.argmax(cnts_trigger)
331331
trigger_styles = ['a boy, children, ', 'a girl, children, ', 'a handsome man, ', 'a beautiful woman, ',
332332
'a mature man, ', 'a mature woman, ']
333-
trigger_style = '<fcsks>, ' + trigger_styles[attr_idx]
333+
trigger_style = '(<fcsks>:10), ' + trigger_styles[attr_idx]
334334
if attr_idx == 2 or attr_idx == 4:
335335
neg_prompt += ', children'
336336

facechain/inference_inpaint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def main_diffusion_inference_inpaint(inpaint_image, strength, output_img_size, p
273273
attr_idx = np.argmax(cnts_trigger)
274274
trigger_styles = ['a boy, children, ', 'a girl, children, ', 'a handsome man, ', 'a beautiful woman, ',
275275
'a mature man, ', 'a mature woman, ']
276-
trigger_style = '<fcsks>, ' + trigger_styles[attr_idx]
276+
trigger_style = '(<fcsks>:10), ' + trigger_styles[attr_idx]
277277
if attr_idx == 2 or attr_idx == 4:
278278
neg_prompt += ', children'
279279

@@ -445,7 +445,7 @@ def main_diffusion_inference_inpaint_multi(inpaint_images, strength, output_img_
445445
attr_idx = np.argmax(cnts_trigger)
446446
trigger_styles = ['a boy, children, ', 'a girl, children, ', 'a handsome man, ', 'a beautiful woman, ',
447447
'a mature man, ', 'a mature woman, ']
448-
trigger_style = '<fcsks>, ' + trigger_styles[attr_idx]
448+
trigger_style = '(<fcsks>:10), ' + trigger_styles[attr_idx]
449449
if attr_idx == 2 or attr_idx == 4:
450450
neg_prompt += ', children'
451451

run_inference.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,39 @@
11
# Copyright (c) Alibaba, Inc. and its affiliates.
22
import os
3-
3+
import json
44
from facechain.inference import GenPortrait
55
import cv2
66
from facechain.utils import snapshot_download
7-
from facechain.constants import neg_prompt, pos_prompt_with_cloth, pos_prompt_with_style, styles, base_models
7+
from facechain.constants import neg_prompt, pos_prompt_with_cloth, pos_prompt_with_style, base_models
88

99

1010
def generate_pos_prompt(style_model, prompt_cloth):
11-
if style_model in base_models[0]['style_list'][:-1] or style_model is None:
12-
pos_prompt = pos_prompt_with_cloth.format(prompt_cloth)
13-
else:
11+
if style_model is not None:
1412
matched = list(filter(lambda style: style_model == style['name'], styles))
1513
if len(matched) == 0:
1614
raise ValueError(f'styles not found: {style_model}')
1715
matched = matched[0]
18-
pos_prompt = pos_prompt_with_style.format(matched['add_prompt_style'])
16+
if matched['model_id'] is None:
17+
pos_prompt = pos_prompt_with_cloth.format(prompt_cloth)
18+
else:
19+
pos_prompt = pos_prompt_with_style.format(matched['add_prompt_style'])
20+
else:
21+
pos_prompt = pos_prompt_with_cloth.format(prompt_cloth)
1922
return pos_prompt
2023

24+
styles = []
25+
for base_model in base_models:
26+
style_in_base = []
27+
folder_path = f"/mnt/workspace/new_facechain/facechain/styles/{base_model['name']}"
28+
files = os.listdir(folder_path)
29+
files.sort()
30+
for file in files:
31+
file_path = os.path.join(folder_path, file)
32+
with open(file_path, "r") as f:
33+
data = json.load(f)
34+
style_in_base.append(data['name'])
35+
styles.append(data)
36+
base_model['style_list'] = style_in_base
2137

2238
use_main_model = True
2339
use_face_swap = True
@@ -28,13 +44,11 @@ def generate_pos_prompt(style_model, prompt_cloth):
2844
pose_image = 'poses/man/pose1.png'
2945
processed_dir = './processed'
3046
num_generate = 5
31-
base_model = 'ly261666/cv_portrait_model'
32-
revision = 'v2.0'
3347
multiplier_style = 0.25
3448
multiplier_human = 0.85
35-
base_model_sub_dir = 'film/film'
3649
train_output_dir = './output'
3750
output_dir = './generated'
51+
base_model = base_models[0]
3852
style = styles[0]
3953
model_id = style['model_id']
4054

@@ -62,8 +76,8 @@ def generate_pos_prompt(style_model, prompt_cloth):
6276
use_face_swap, use_post_process,
6377
use_stylization)
6478

65-
outputs = gen_portrait(processed_dir, num_generate, base_model,
66-
train_output_dir, base_model_sub_dir, revision)
79+
outputs = gen_portrait(processed_dir, num_generate, base_model['model_id'],
80+
train_output_dir, base_model['sub_path'], base_model['revision'])
6781

6882
os.makedirs(output_dir, exist_ok=True)
6983

style_image/Autumn_populus.jpg

34.5 KB

style_image/Bleak_autumn.jpg

31.5 KB

style_image/Cartoon.jpg

41.7 KB

style_image/Cheongsam.jpg

-9.19 KB

style_image/Chinese_New_Year.jpg

32.4 KB

0 commit comments

Comments
 (0)