Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix make_captions_by_git, improve image generation scripts #872

Merged
merged 5 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix network_merge, add regional mask as color code
  • Loading branch information
kohya-ss committed Oct 9, 2023
commit 3e81bd6b6729bf8b553b30cbce23e21698287039
21 changes: 18 additions & 3 deletions gen_img_diffusers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2372,7 2372,7 @@ def __getattr__(self, item):
elif args.network_merge_n_models:
network_merge = args.network_merge_n_models
else:
network_merge = None
network_merge = 0

for i, network_module in enumerate(args.network_module):
print("import network module:", network_module)
Expand Down Expand Up @@ -2724,9 2724,18 @@ def resize_images(imgs, size):

size = None
for i, network in enumerate(networks):
if i < 3:
if (i < 3 and args.network_regional_mask_max_color_codes is None) or i < args.network_regional_mask_max_color_codes:
np_mask = np.array(mask_images[0])
np_mask = np_mask[:, :, i]

if args.network_regional_mask_max_color_codes:
# カラーコードでマスクを指定する
ch0 = (i 1) & 1
ch1 = ((i 1) >> 1) & 1
ch2 = ((i 1) >> 2) & 1
np_mask = np.all(np_mask == np.array([ch0, ch1, ch2]) * 255, axis=2)
np_mask = np_mask.astype(np.uint8) * 255
else:
np_mask = np_mask[:, :, i]
size = np_mask.shape
else:
np_mask = np.full(size, 255, dtype=np.uint8)
Expand Down Expand Up @@ -3386,6 3395,12 @@ def setup_parser() -> argparse.ArgumentParser:
parser.add_argument(
"--network_pre_calc", action="store_true", help="pre-calculate network for generation / ネットワークのあらかじめ計算して生成する"
)
parser.add_argument(
"--network_regional_mask_max_color_codes",
type=int,
default=None,
help="max color codes for regional mask (default is None, mask by channel) / regional maskの最大色数(デフォルトはNoneでチャンネルごとのマスク)",
)
parser.add_argument(
"--textual_inversion_embeddings",
type=str,
Expand Down
21 changes: 18 additions & 3 deletions sdxl_gen_img.py
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 1543,7 @@ def __getattr__(self, item):
elif args.network_merge_n_models:
network_merge = args.network_merge_n_models
else:
network_merge = None
network_merge = 0
print(f"network_merge: {network_merge}")

for i, network_module in enumerate(args.network_module):
Expand Down Expand Up @@ -1877,9 1877,18 @@ def resize_images(imgs, size):

size = None
for i, network in enumerate(networks):
if i < 3:
if (i < 3 and args.network_regional_mask_max_color_codes is None) or i < args.network_regional_mask_max_color_codes:
np_mask = np.array(mask_images[0])
np_mask = np_mask[:, :, i]

if args.network_regional_mask_max_color_codes:
# カラーコードでマスクを指定する
ch0 = (i 1) & 1
ch1 = ((i 1) >> 1) & 1
ch2 = ((i 1) >> 2) & 1
np_mask = np.all(np_mask == np.array([ch0, ch1, ch2]) * 255, axis=2)
np_mask = np_mask.astype(np.uint8) * 255
else:
np_mask = np_mask[:, :, i]
size = np_mask.shape
else:
np_mask = np.full(size, 255, dtype=np.uint8)
Expand Down Expand Up @@ -2635,6 2644,12 @@ def setup_parser() -> argparse.ArgumentParser:
parser.add_argument(
"--network_pre_calc", action="store_true", help="pre-calculate network for generation / ネットワークのあらかじめ計算して生成する"
)
parser.add_argument(
"--network_regional_mask_max_color_codes",
type=int,
default=None,
help="max color codes for regional mask (default is None, mask by channel) / regional maskの最大色数(デフォルトはNoneでチャンネルごとのマスク)",
)
parser.add_argument(
"--textual_inversion_embeddings",
type=str,
Expand Down