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
5d12ec82
Unverified
Commit
5d12ec82
authored
Oct 09, 2022
by
DepFA
Committed by
GitHub
Oct 09, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add encoder and decoder classes
parent
969bd825
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
0 deletions
+21
-0
textual_inversion.py
modules/textual_inversion/textual_inversion.py
+21
-0
No files found.
modules/textual_inversion/textual_inversion.py
View file @
5d12ec82
...
@@ -16,6 +16,27 @@ import json
...
@@ -16,6 +16,27 @@ 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
class
EmbeddingEncoder
(
json
.
JSONEncoder
):
def
default
(
self
,
obj
):
if
isinstance
(
obj
,
torch
.
Tensor
):
return
{
'EMBEDDINGTENSOR'
:
obj
.
cpu
()
.
detach
()
.
numpy
()
.
tolist
()}
return
json
.
JSONEncoder
.
default
(
self
,
o
)
class
EmbeddingDecoder
(
json
.
JSONDecoder
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
json
.
JSONDecoder
.
__init__
(
self
,
object_hook
=
self
.
object_hook
,
*
args
,
**
kwargs
)
def
object_hook
(
self
,
d
):
if
'EMBEDDINGTENSOR'
in
d
:
return
torch
.
from_numpy
(
np
.
array
(
d
[
'EMBEDDINGTENSOR'
]))
return
d
def
embeddingToB64
(
data
):
d
=
json
.
dumps
(
data
,
cls
=
EmbeddingEncoder
)
return
base64
.
b64encode
(
d
.
encode
())
def
EmbeddingFromB64
(
data
):
d
=
base64
.
b64decode
(
data
)
return
json
.
loads
(
d
,
cls
=
EmbeddingDecoder
)
class
Embedding
:
class
Embedding
:
def
__init__
(
self
,
vec
,
name
,
step
=
None
):
def
__init__
(
self
,
vec
,
name
,
step
=
None
):
...
...
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