Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Cog predictor to use a set of default target images #131

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions predict.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os
from glob import glob
import cog
import tempfile
from pathlib import Path
Expand All @@ -16,6 +18,12 @@
from insightface_func.face_detect_crop_single import Face_detect_crop as Face_detect_crop_single


TARGET_OPTIONS_DIR = "cog-targets"

def list_target_options():
return [os.path.basename(p).split(".")[0] for p in glob(f"{TARGET_OPTIONS_DIR}/*.jpg")]


class Predictor(cog.Predictor):
def setup(self):
self.transformer_Arcface = transforms.Compose([
Expand All @@ -24,10 +32,11 @@ def setup(self):
])

@cog.input("source", type=Path, help="source image")
@cog.input("target", type=Path, help="target image")
@cog.input("target", type=str, options=list_target_options(), help="target image")
@cog.input("mode", type=str, options=['single', 'all'], default='all',
help="swap a single face (the one with highest confidence by face detection) or all faces in the target image")
def predict(self, source, target, mode='all'):
target_path = f"{TARGET_OPTIONS_DIR}/{target}.jpg"

app = Face_detect_crop_multi(name='antelope', root='./insightface_func/models')

Expand All @@ -39,7 +48,7 @@ def predict(self, source, target, mode='all'):
options = TestOptions()
options.initialize()
opt = options.parser.parse_args(["--Arc_path", 'arcface_model/arcface_checkpoint.tar', "--pic_a_path", str(source),
"--pic_b_path", str(target), "--isTrain", False, "--no_simswaplogo"])
"--pic_b_path", target_path, "--isTrain", False, "--no_simswaplogo"])

str_ids = opt.gpu_ids.split(',')
opt.gpu_ids = []
Expand Down