Skip to content

Commit

Permalink
BUGFIX: Nn_blocks upscale (#909)
Browse files Browse the repository at this point in the history
  • Loading branch information
kvrooman authored and torzdf committed Oct 25, 2019
1 parent 5d9e0a2 commit bb26afd
Show file tree
Hide file tree
Showing 61 changed files with 3,244 additions and 1,367 deletions.
6 changes: 3 additions & 3 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ignore-patterns=

# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the
# number of processors available to use.
jobs=1
jobs=0

# Control the amount of potential inferred values when inferring a single
# object. This can help the performance when dealing with large functions or
Expand Down Expand Up @@ -477,10 +477,10 @@ notes=FIXME,
[DESIGN]

# Maximum number of arguments for function / method.
max-args=5
max-args=10

# Maximum number of attributes for a class (see R0902).
max-attributes=7
max-attributes=10

# Maximum number of boolean expressions in an if statement.
max-bool-expr=5
Expand Down
58 changes: 37 additions & 21 deletions _travis/simple_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import os
from os.path import join as pathjoin, expanduser

fail_count = 0
test_count = 0
FAIL_COUNT = 0
TEST_COUNT = 0
_COLORS = {
"FAIL": "\033[1;31m",
"OK": "\033[1;32m",
Expand All @@ -26,55 +26,63 @@


def print_colored(text, color="OK", bold=False):
# This might not work on windows,
# altho travis runs windows stuff in git bash, so it might ?
""" Print colored text
This might not work on windows,
although travis runs windows stuff in git bash, so it might ?
"""
color = _COLORS.get(color, color)
print("%s%s%s%s" % (
color, "" if not bold else _COLORS["BOLD"], text, _COLORS["ENDC"]
))


def print_ok(text):
""" Print ok in colored text """
print_colored(text, "OK", True)


def print_fail(text):
""" Print fail in colored text """
print_colored(text, "FAIL", True)


def print_status(text):
""" Print status in colored text """
print_colored(text, "STATUS", True)


def run_test(name, cmd):
global fail_count, test_count
""" run a test """
global FAIL_COUNT, TEST_COUNT # pylint:disable=global-statement
print_status("[?] running %s" % name)
print("Cmd: %s" % " ".join(cmd))
test_count += 1
TEST_COUNT += 1
try:
check_call(cmd)
print_ok("[+] Test success")
return True
except CalledProcessError as e:
print_fail("[-] Test failed with %s" % e)
fail_count += 1
except CalledProcessError as err:
print_fail("[-] Test failed with %s" % err)
FAIL_COUNT += 1
return False


def download_file(url, filename): # TODO: retry
""" Download a file from given url """
if os.path.isfile(filename):
print_status("[?] '%s' already cached as '%s'" % (url, filename))
return filename
try:
print_status("[?] Downloading '%s' to '%s'" % (url, filename))
video, _ = urlretrieve(url, filename)
return video
except urllib.error.URLError as e:
print_fail("[-] Failed downloading: %s" % e)
except urllib.error.URLError as err:
print_fail("[-] Failed downloading: %s" % err)
return None


def extract_args(detector, aligner, in_path, out_path, args=None):
""" Extraction command """
py_exe = sys.executable
_extract_args = "%s faceswap.py extract -i %s -o %s -D %s -A %s" % (
py_exe, in_path, out_path, detector, aligner
Expand All @@ -84,16 +92,18 @@ def extract_args(detector, aligner, in_path, out_path, args=None):
return _extract_args.split()


def train_args(model, model_path, faces, alignments, iterations=5, bs=8, extra_args=""):
def train_args(model, model_path, faces, alignments, iterations=5, batchsize=8, extra_args=""):
""" Train command """
py_exe = sys.executable
args = "%s faceswap.py train -A %s -ala %s -B %s -alb %s -m %s -t %s -bs %i -it %s %s" % (
py_exe, faces, alignments, faces,
alignments, model_path, model, bs, iterations, extra_args
alignments, model_path, model, batchsize, iterations, extra_args
)
return args.split()


def convert_args(in_path, out_path, model_path, writer, args=None):
""" Convert command """
py_exe = sys.executable
conv_args = "%s faceswap.py convert -i %s -o %s -m %s -w %s" % (
py_exe, in_path, out_path, model_path, writer
Expand All @@ -104,14 +114,16 @@ def convert_args(in_path, out_path, model_path, writer, args=None):


def sort_args(in_path, out_path, sortby="face", groupby="hist", method="rename"):
""" Sort command """
py_exe = sys.executable
_sort_args = "%s tools.py sort -i %s -o %s -s %s -fp %s -g %s -k" % (
py_exe, in_path, out_path, sortby, method, groupby
)
return _sort_args.split()


if __name__ == '__main__':
def main():
""" Main testing script """
vid_src = "https://faceswap.dev/data/test.mp4"
img_src = "https://archive.org/download/GPN-2003-00070/GPN-2003-00070.jpg"
base_dir = pathjoin(expanduser("~"), "cache", "tests")
Expand All @@ -136,7 +148,7 @@ def sort_args(in_path, out_path, sortby="face", groupby="hist", method="rename")
if not img_path:
print_fail("[-] Aborting")
exit(1)
img_extract = run_test(
run_test(
"Extraction images with cv2-dnn detector and cv2-dnn aligner.",
extract_args("Cv2-Dnn", "Cv2-Dnn", img_base, pathjoin(img_base, "faces"))
)
Expand All @@ -154,7 +166,7 @@ def sort_args(in_path, out_path, sortby="face", groupby="hist", method="rename")
"Rename sorted faces.",
(
py_exe, "tools.py", "alignments", "-j", "rename",
"-a", pathjoin(vid_base, "test_alignments.json"),
"-a", pathjoin(vid_base, "test_alignments.fsa"),
"-fc", pathjoin(vid_base, "faces_sorted"),
)
)
Expand All @@ -163,7 +175,7 @@ def sort_args(in_path, out_path, sortby="face", groupby="hist", method="rename")
"Train lightweight model for 1 iteration with WTL.",
train_args(
"lightweight", pathjoin(vid_base, "model"),
pathjoin(vid_base, "faces"), pathjoin(vid_base, "test_alignments.json"),
pathjoin(vid_base, "faces"), pathjoin(vid_base, "test_alignments.fsa"),
iterations=1, extra_args="-wl"
)
)
Expand All @@ -172,7 +184,7 @@ def sort_args(in_path, out_path, sortby="face", groupby="hist", method="rename")
"Train lightweight model for 5 iterations WITHOUT WTL.",
train_args(
"lightweight", pathjoin(vid_base, "model"),
pathjoin(vid_base, "faces"), pathjoin(vid_base, "test_alignments.json")
pathjoin(vid_base, "faces"), pathjoin(vid_base, "test_alignments.fsa")
)
)

Expand All @@ -193,9 +205,13 @@ def sort_args(in_path, out_path, sortby="face", groupby="hist", method="rename")
)
)

if fail_count == 0:
print_ok("[+] Failed %i/%i tests." % (fail_count, test_count))
if FAIL_COUNT == 0:
print_ok("[+] Failed %i/%i tests." % (FAIL_COUNT, TEST_COUNT))
exit(0)
else:
print_fail("[-] Failed %i/%i tests." % (fail_count, test_count))
print_fail("[-] Failed %i/%i tests." % (FAIL_COUNT, TEST_COUNT))
exit(1)


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions docs/full/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ faceswap

lib
plugins
tools
7 changes: 7 additions & 0 deletions docs/full/plugins.extract.mask._base.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins.extract.mask._base module
======================================

.. automodule:: plugins.extract.mask._base
:members:
:undoc-members:
:show-inheritance:
17 changes: 17 additions & 0 deletions docs/full/plugins.extract.mask.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins.extract.mask package
==============================

Submodules
----------

.. toctree::

plugins.extract.mask._base

Module contents
---------------

.. automodule:: plugins.extract.mask
:members:
:undoc-members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/full/plugins.extract.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Subpackages

plugins.extract.align
plugins.extract.detect
plugins.extract.mask

Submodules
----------
Expand Down
7 changes: 7 additions & 0 deletions docs/full/plugins.plugin_loader.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins.plugin\_loader module
=============================

.. automodule:: plugins.plugin_loader
:members:
:undoc-members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/full/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Subpackages
.. toctree::

plugins.extract
plugins.plugin_loader

Module contents
---------------
Expand Down
7 changes: 7 additions & 0 deletions docs/full/tools.mask.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tools.mask module
======================================

.. automodule:: tools.mask
:members:
:undoc-members:
:show-inheritance:
17 changes: 17 additions & 0 deletions docs/full/tools.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
tools package
=============

Subpackages
-----------

.. toctree::

tools.mask

Module contents
---------------

.. automodule:: tools
:members:
:undoc-members:
:show-inheritance:
2 changes: 1 addition & 1 deletion lib/aligner.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,5 @@ def get_matrix_scaling(mat):

def get_align_mat(face):
""" Return the alignment Matrix """
mat_umeyama = umeyama(np.array(face.landmarks_xy[17:]), True)[0:2]
mat_umeyama = umeyama(face.landmarks_xy[17:], True)[0:2]
return mat_umeyama

0 comments on commit bb26afd

Please sign in to comment.