Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Overbill1683
Stable Diffusion Webui
提交
04c745ea
S
Stable Diffusion Webui
项目概览
Overbill1683
/
Stable Diffusion Webui
10 个月 前同步成功
通知
1736
Star
81
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
S
Stable Diffusion Webui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
04c745ea
编写于
10月 10, 2022
作者:
A
alg-wiki
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Custom Width and Height
上级
4ee7519f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
26 addition
and
23 deletion
+26
-23
modules/textual_inversion/dataset.py
modules/textual_inversion/dataset.py
+3
-4
modules/textual_inversion/preprocess.py
modules/textual_inversion/preprocess.py
+10
-9
modules/textual_inversion/textual_inversion.py
modules/textual_inversion/textual_inversion.py
+5
-6
modules/ui.py
modules/ui.py
+8
-4
未找到文件。
modules/textual_inversion/dataset.py
浏览文件 @
04c745ea
...
...
@@ -15,13 +15,12 @@ re_tag = re.compile(r"[a-zA-Z][_\w\d()]+")
class
PersonalizedBase
(
Dataset
):
def
__init__
(
self
,
data_root
,
size
,
repeats
,
flip_p
=
0.5
,
placeholder_token
=
"*"
,
model
=
None
,
device
=
None
,
template_file
=
None
):
def
__init__
(
self
,
data_root
,
width
,
height
,
repeats
,
flip_p
=
0.5
,
placeholder_token
=
"*"
,
model
=
None
,
device
=
None
,
template_file
=
None
):
self
.
placeholder_token
=
placeholder_token
self
.
size
=
size
self
.
width
=
size
self
.
height
=
size
self
.
width
=
width
self
.
height
=
height
self
.
flip
=
transforms
.
RandomHorizontalFlip
(
p
=
flip_p
)
self
.
dataset
=
[]
...
...
modules/textual_inversion/preprocess.py
浏览文件 @
04c745ea
...
...
@@ -7,8 +7,9 @@ import tqdm
from
modules
import
shared
,
images
def
preprocess
(
process_src
,
process_dst
,
process_size
,
process_flip
,
process_split
,
process_caption
):
size
=
process_size
def
preprocess
(
process_src
,
process_dst
,
process_width
,
process_height
,
process_flip
,
process_split
,
process_caption
):
width
=
process_width
height
=
process_height
src
=
os
.
path
.
abspath
(
process_src
)
dst
=
os
.
path
.
abspath
(
process_dst
)
...
...
@@ -55,23 +56,23 @@ def preprocess(process_src, process_dst, process_size, process_flip, process_spl
is_wide
=
ratio
<
1
/
1.35
if
process_split
and
is_tall
:
img
=
img
.
resize
((
size
,
size
*
img
.
height
//
img
.
width
))
img
=
img
.
resize
((
width
,
height
*
img
.
height
//
img
.
width
))
top
=
img
.
crop
((
0
,
0
,
size
,
size
))
top
=
img
.
crop
((
0
,
0
,
width
,
height
))
save_pic
(
top
,
index
)
bot
=
img
.
crop
((
0
,
img
.
height
-
size
,
size
,
img
.
height
))
bot
=
img
.
crop
((
0
,
img
.
height
-
height
,
width
,
img
.
height
))
save_pic
(
bot
,
index
)
elif
process_split
and
is_wide
:
img
=
img
.
resize
((
size
*
img
.
width
//
img
.
height
,
size
))
img
=
img
.
resize
((
width
*
img
.
width
//
img
.
height
,
height
))
left
=
img
.
crop
((
0
,
0
,
size
,
size
))
left
=
img
.
crop
((
0
,
0
,
width
,
height
))
save_pic
(
left
,
index
)
right
=
img
.
crop
((
img
.
width
-
size
,
0
,
img
.
width
,
size
))
right
=
img
.
crop
((
img
.
width
-
width
,
0
,
img
.
width
,
height
))
save_pic
(
right
,
index
)
else
:
img
=
images
.
resize_image
(
1
,
img
,
size
,
size
)
img
=
images
.
resize_image
(
1
,
img
,
width
,
height
)
save_pic
(
img
,
index
)
shared
.
state
.
nextjob
()
...
...
modules/textual_inversion/textual_inversion.py
浏览文件 @
04c745ea
...
...
@@ -6,7 +6,6 @@ import torch
import
tqdm
import
html
import
datetime
import
math
from
modules
import
shared
,
devices
,
sd_hijack
,
processing
,
sd_models
...
...
@@ -157,7 +156,7 @@ def create_embedding(name, num_vectors_per_token, init_text='*'):
return
fn
def
train_embedding
(
embedding_name
,
learn_rate
,
data_root
,
log_directory
,
training_
size
,
steps
,
num_repeats
,
create_image_every
,
save_embedding_every
,
template_file
):
def
train_embedding
(
embedding_name
,
learn_rate
,
data_root
,
log_directory
,
training_
width
,
training_height
,
steps
,
num_repeats
,
create_image_every
,
save_embedding_every
,
template_file
):
assert
embedding_name
,
'embedding not selected'
shared
.
state
.
textinfo
=
"Initializing textual inversion training..."
...
...
@@ -183,7 +182,7 @@ def train_embedding(embedding_name, learn_rate, data_root, log_directory, traini
shared
.
state
.
textinfo
=
f
"Preparing dataset from
{
html
.
escape
(
data_root
)
}
..."
with
torch
.
autocast
(
"cuda"
):
ds
=
modules
.
textual_inversion
.
dataset
.
PersonalizedBase
(
data_root
=
data_root
,
size
=
training_size
,
repeats
=
num_repeats
,
placeholder_token
=
embedding_name
,
model
=
shared
.
sd_model
,
device
=
devices
.
device
,
template_file
=
template_file
)
ds
=
modules
.
textual_inversion
.
dataset
.
PersonalizedBase
(
data_root
=
data_root
,
width
=
training_width
,
height
=
training_height
,
repeats
=
num_repeats
,
placeholder_token
=
embedding_name
,
model
=
shared
.
sd_model
,
device
=
devices
.
device
,
template_file
=
template_file
)
hijack
=
sd_hijack
.
model_hijack
...
...
@@ -227,7 +226,7 @@ def train_embedding(embedding_name, learn_rate, data_root, log_directory, traini
loss
.
backward
()
optimizer
.
step
()
epoch_num
=
math
.
floor
(
embedding
.
step
/
epoch_len
)
epoch_num
=
embedding
.
step
//
epoch_len
epoch_step
=
embedding
.
step
-
(
epoch_num
*
epoch_len
)
+
1
pbar
.
set_description
(
f
"[Epoch
{
epoch_num
}
:
{
epoch_step
}
/
{
epoch_len
}
]loss:
{
losses
.
mean
():.
7
f
}
"
)
...
...
@@ -243,8 +242,8 @@ def train_embedding(embedding_name, learn_rate, data_root, log_directory, traini
sd_model
=
shared
.
sd_model
,
prompt
=
text
,
steps
=
20
,
height
=
training_size
,
width
=
training_size
,
height
=
training_height
,
width
=
training_width
,
do_not_save_grid
=
True
,
do_not_save_samples
=
True
,
)
...
...
modules/ui.py
浏览文件 @
04c745ea
...
...
@@ -1029,7 +1029,8 @@ def create_ui(wrap_gradio_gpu_call):
process_src
=
gr
.
Textbox
(
label
=
'Source directory'
)
process_dst
=
gr
.
Textbox
(
label
=
'Destination directory'
)
process_size
=
gr
.
Slider
(
minimum
=
64
,
maximum
=
2048
,
step
=
64
,
label
=
"Size (width and height)"
,
value
=
512
)
process_width
=
gr
.
Slider
(
minimum
=
64
,
maximum
=
2048
,
step
=
64
,
label
=
"Width"
,
value
=
512
)
process_height
=
gr
.
Slider
(
minimum
=
64
,
maximum
=
2048
,
step
=
64
,
label
=
"Height"
,
value
=
512
)
with
gr
.
Row
():
process_flip
=
gr
.
Checkbox
(
label
=
'Create flipped copies'
)
...
...
@@ -1050,7 +1051,8 @@ def create_ui(wrap_gradio_gpu_call):
dataset_directory
=
gr
.
Textbox
(
label
=
'Dataset directory'
,
placeholder
=
"Path to directory with input images"
)
log_directory
=
gr
.
Textbox
(
label
=
'Log directory'
,
placeholder
=
"Path to directory where to write outputs"
,
value
=
"textual_inversion"
)
template_file
=
gr
.
Textbox
(
label
=
'Prompt template file'
,
value
=
os
.
path
.
join
(
script_path
,
"textual_inversion_templates"
,
"style_filewords.txt"
))
training_size
=
gr
.
Slider
(
minimum
=
64
,
maximum
=
2048
,
step
=
64
,
label
=
"Size (width and height)"
,
value
=
512
)
training_width
=
gr
.
Slider
(
minimum
=
64
,
maximum
=
2048
,
step
=
64
,
label
=
"Width"
,
value
=
512
)
training_height
=
gr
.
Slider
(
minimum
=
64
,
maximum
=
2048
,
step
=
64
,
label
=
"Height"
,
value
=
512
)
steps
=
gr
.
Number
(
label
=
'Max steps'
,
value
=
100000
,
precision
=
0
)
num_repeats
=
gr
.
Number
(
label
=
'Number of repeats for a single input image per epoch'
,
value
=
100
,
precision
=
0
)
create_image_every
=
gr
.
Number
(
label
=
'Save an image to log directory every N steps, 0 to disable'
,
value
=
500
,
precision
=
0
)
...
...
@@ -1095,7 +1097,8 @@ def create_ui(wrap_gradio_gpu_call):
inputs
=
[
process_src
,
process_dst
,
process_size
,
process_width
,
process_height
,
process_flip
,
process_split
,
process_caption
,
...
...
@@ -1114,7 +1117,8 @@ def create_ui(wrap_gradio_gpu_call):
learn_rate
,
dataset_directory
,
log_directory
,
training_size
,
training_width
,
training_height
,
steps
,
num_repeats
,
create_image_every
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录