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
03694e1f
Commit
03694e1f
authored
Oct 09, 2022
by
DepFA
Committed by
GitHub
Oct 09, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add embedding load and save from b64 json
parent
fa0c5eb8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
9 deletions
+21
-9
modules/textual_inversion/textual_inversion.py
modules/textual_inversion/textual_inversion.py
+21
-9
No files found.
modules/textual_inversion/textual_inversion.py
View file @
03694e1f
...
@@ -7,9 +7,11 @@ import tqdm
...
@@ -7,9 +7,11 @@ import tqdm
import
html
import
html
import
datetime
import
datetime
from
PIL
import
Image
,
PngImagePlugin
from
PIL
import
Image
,
PngImagePlugin
from
..images
import
captionImge
import
numpy
as
np
import
base64
import
base64
from
io
import
BytesIO
import
json
from
modules
import
shared
,
devices
,
sd_hijack
,
processing
,
sd_models
from
modules
import
shared
,
devices
,
sd_hijack
,
processing
,
sd_models
import
modules.textual_inversion.dataset
import
modules.textual_inversion.dataset
...
@@ -87,9 +89,9 @@ class EmbeddingDatabase:
...
@@ -87,9 +89,9 @@ class EmbeddingDatabase:
if
filename
.
upper
()
.
endswith
(
'.PNG'
):
if
filename
.
upper
()
.
endswith
(
'.PNG'
):
embed_image
=
Image
.
open
(
path
)
embed_image
=
Image
.
open
(
path
)
if
'sd-embedding'
in
embed_image
.
text
:
if
'sd-
ti-
embedding'
in
embed_image
.
text
:
embeddingData
=
base64
.
b64decode
(
embed_image
.
text
[
'sd
-embedding'
])
data
=
embeddingFromB64
(
embed_image
.
text
[
'sd-ti
-embedding'
])
data
=
torch
.
load
(
BytesIO
(
embeddingData
),
map_location
=
"cpu"
)
name
=
data
.
get
(
'name'
,
name
)
else
:
else
:
data
=
torch
.
load
(
path
,
map_location
=
"cpu"
)
data
=
torch
.
load
(
path
,
map_location
=
"cpu"
)
...
@@ -258,12 +260,22 @@ def train_embedding(embedding_name, learn_rate, data_root, log_directory, steps,
...
@@ -258,12 +260,22 @@ def train_embedding(embedding_name, learn_rate, data_root, log_directory, steps,
if
save_image_with_stored_embedding
:
if
save_image_with_stored_embedding
:
info
=
PngImagePlugin
.
PngInfo
()
info
=
PngImagePlugin
.
PngInfo
()
info
.
add_text
(
"sd-embedding"
,
base64
.
b64encode
(
open
(
last_saved_file
,
'rb'
)
.
read
())
)
data
=
torch
.
load
(
last_saved_file
)
i
mage
.
save
(
last_saved_image
,
"PNG"
,
pnginfo
=
info
)
i
nfo
.
add_text
(
"sd-ti-embedding"
,
embeddingToB64
(
data
)
)
else
:
image
.
save
(
last_saved_image
)
pre_lines
=
[((
255
,
207
,
175
),
"<{}>"
.
format
(
data
.
get
(
'name'
,
'???'
)))]
caption_checkpoint_hash
=
data
.
get
(
'sd_checkpoint'
,
'UNK'
)
caption_checkpoint_hash
=
caption_checkpoint_hash
.
upper
()
if
caption_checkpoint_hash
else
'UNK'
caption_stepcount
=
data
.
get
(
'step'
,
0
)
caption_stepcount
=
caption_stepcount
if
caption_stepcount
else
0
post_lines
=
[((
240
,
223
,
175
),
"Trained against checkpoint [{}] for {} steps"
.
format
(
caption_checkpoint_hash
,
caption_stepcount
))]
captioned_image
=
captionImge
(
image
,
prelines
=
pre_lines
,
postlines
=
post_lines
)
captioned_image
.
save
(
last_saved_image
,
"PNG"
,
pnginfo
=
info
)
else
:
image
.
save
(
last_saved_image
)
last_saved_image
+=
f
", prompt: {text}"
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