-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
94 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
cython | ||
dill==0.3.6 | ||
ifnude | ||
insightface==0.7.3 | ||
onnx==1.14.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import glob | ||
import os | ||
from typing import List | ||
from insightface.app.common import Face | ||
from safetensors.torch import save_file, safe_open | ||
import torch | ||
|
||
import modules.scripts as scripts | ||
from modules import scripts | ||
from scripts.faceswaplab_utils.faceswaplab_logging import logger | ||
|
||
|
||
def save_face(face: Face, filename: str) -> None: | ||
tensors = { | ||
"embedding": torch.tensor(face["embedding"]), | ||
"gender": torch.tensor(face["gender"]), | ||
"age": torch.tensor(face["age"]), | ||
} | ||
save_file(tensors, filename) | ||
|
||
|
||
def load_face(filename: str) -> Face: | ||
face = {} | ||
logger.debug("Try to load face from %s", filename) | ||
with safe_open(filename, framework="pt", device="cpu") as f: | ||
logger.debug("File contains %s keys", f.keys()) | ||
for k in f.keys(): | ||
logger.debug("load key %s", k) | ||
face[k] = f.get_tensor(k).numpy() | ||
logger.debug("face : %s", face) | ||
return Face(face) | ||
|
||
|
||
def get_face_checkpoints() -> List[str]: | ||
""" | ||
Retrieve a list of face checkpoint paths. | ||
This function searches for face files with the extension ".safetensors" in the specified directory and returns a list | ||
containing the paths of those files. | ||
Returns: | ||
list: A list of face paths, including the string "None" as the first element. | ||
""" | ||
faces_path = os.path.join( | ||
scripts.basedir(), "models", "faceswaplab", "faces", "*.safetensors" | ||
) | ||
faces = glob.glob(faces_path) | ||
return ["None"] + faces |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters