Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
S
stable-diffusion-webui
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
stable-diffusion-webui
Commits
5ef0baf5
Commit
5ef0baf5
authored
Oct 04, 2022
by
AUTOMATIC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add support for gelbooru tags in filenames for textual inversion
parent
2865ef4b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
3 deletions
+8
-3
dataset.py
modules/textual_inversion/dataset.py
+5
-2
preprocess.py
modules/textual_inversion/preprocess.py
+3
-1
No files found.
modules/textual_inversion/dataset.py
View file @
5ef0baf5
...
@@ -9,6 +9,9 @@ from torchvision import transforms
...
@@ -9,6 +9,9 @@ from torchvision import transforms
import
random
import
random
import
tqdm
import
tqdm
from
modules
import
devices
from
modules
import
devices
import
re
re_tag
=
re
.
compile
(
r"[a-zA-Z][_\w\d()]+"
)
class
PersonalizedBase
(
Dataset
):
class
PersonalizedBase
(
Dataset
):
...
@@ -38,8 +41,8 @@ class PersonalizedBase(Dataset):
...
@@ -38,8 +41,8 @@ class PersonalizedBase(Dataset):
image
=
image
.
resize
((
self
.
width
,
self
.
height
),
PIL
.
Image
.
BICUBIC
)
image
=
image
.
resize
((
self
.
width
,
self
.
height
),
PIL
.
Image
.
BICUBIC
)
filename
=
os
.
path
.
basename
(
path
)
filename
=
os
.
path
.
basename
(
path
)
filename_tokens
=
os
.
path
.
splitext
(
filename
)[
0
]
.
replace
(
'_'
,
'-'
)
.
replace
(
' '
,
'-'
)
.
split
(
'-'
)
filename_tokens
=
os
.
path
.
splitext
(
filename
)[
0
]
filename_tokens
=
[
token
for
token
in
filename_tokens
if
token
.
isalpha
()]
filename_tokens
=
re_tag
.
findall
(
filename_tokens
)
npimage
=
np
.
array
(
image
)
.
astype
(
np
.
uint8
)
npimage
=
np
.
array
(
image
)
.
astype
(
np
.
uint8
)
npimage
=
(
npimage
/
127.5
-
1.0
)
.
astype
(
np
.
float32
)
npimage
=
(
npimage
/
127.5
-
1.0
)
.
astype
(
np
.
float32
)
...
...
modules/textual_inversion/preprocess.py
View file @
5ef0baf5
...
@@ -26,7 +26,9 @@ def preprocess(process_src, process_dst, process_flip, process_split, process_ca
...
@@ -26,7 +26,9 @@ def preprocess(process_src, process_dst, process_flip, process_split, process_ca
if
process_caption
:
if
process_caption
:
caption
=
"-"
+
shared
.
interrogator
.
generate_caption
(
image
)
caption
=
"-"
+
shared
.
interrogator
.
generate_caption
(
image
)
else
:
else
:
caption
=
""
caption
=
filename
caption
=
os
.
path
.
splitext
(
caption
)[
0
]
caption
=
os
.
path
.
basename
(
caption
)
image
.
save
(
os
.
path
.
join
(
dst
,
f
"{index:05}-{subindex[0]}{caption}.png"
))
image
.
save
(
os
.
path
.
join
(
dst
,
f
"{index:05}-{subindex[0]}{caption}.png"
))
subindex
[
0
]
+=
1
subindex
[
0
]
+=
1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment