Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
5841990b
Commit
5841990b
authored
Oct 09, 2022
by
DepFA
Committed by
GitHub
Oct 09, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update textual_inversion.py
parent
050a6a79
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
3 deletions
+22
-3
modules/textual_inversion/textual_inversion.py
modules/textual_inversion/textual_inversion.py
+22
-3
No files found.
modules/textual_inversion/textual_inversion.py
View file @
5841990b
...
...
@@ -7,6 +7,9 @@ import tqdm
import
html
import
datetime
from
PIL
import
Image
,
PngImagePlugin
import
base64
from
io
import
BytesIO
from
modules
import
shared
,
devices
,
sd_hijack
,
processing
,
sd_models
import
modules.textual_inversion.dataset
...
...
@@ -80,7 +83,15 @@ class EmbeddingDatabase:
def
process_file
(
path
,
filename
):
name
=
os
.
path
.
splitext
(
filename
)[
0
]
data
=
torch
.
load
(
path
,
map_location
=
"cpu"
)
data
=
[]
if
filename
.
upper
()
.
endswith
(
'.PNG'
):
embed_image
=
Image
.
open
(
path
)
if
'sd-embedding'
in
embed_image
.
text
:
embeddingData
=
base64
.
b64decode
(
embed_image
.
text
[
'sd-embedding'
])
data
=
torch
.
load
(
BytesIO
(
embeddingData
),
map_location
=
"cpu"
)
else
:
data
=
torch
.
load
(
path
,
map_location
=
"cpu"
)
# textual inversion embeddings
if
'string_to_param'
in
data
:
...
...
@@ -156,7 +167,7 @@ def create_embedding(name, num_vectors_per_token, init_text='*'):
return
fn
def
train_embedding
(
embedding_name
,
learn_rate
,
data_root
,
log_directory
,
steps
,
create_image_every
,
save_embedding_every
,
template_file
):
def
train_embedding
(
embedding_name
,
learn_rate
,
data_root
,
log_directory
,
steps
,
create_image_every
,
save_embedding_every
,
template_file
,
save_image_with_stored_embedding
):
assert
embedding_name
,
'embedding not selected'
shared
.
state
.
textinfo
=
"Initializing textual inversion training..."
...
...
@@ -244,7 +255,15 @@ def train_embedding(embedding_name, learn_rate, data_root, log_directory, steps,
image
=
processed
.
images
[
0
]
shared
.
state
.
current_image
=
image
image
.
save
(
last_saved_image
)
if
save_image_with_stored_embedding
:
info
=
PngImagePlugin
.
PngInfo
()
info
.
add_text
(
"sd-embedding"
,
base64
.
b64encode
(
open
(
last_saved_file
,
'rb'
)
.
read
()))
image
.
save
(
last_saved_image
,
"PNG"
,
pnginfo
=
info
)
else
:
image
.
save
(
last_saved_image
)
last_saved_image
+=
f
", prompt: {text}"
...
...
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