Skip to content

Commit

Permalink
De-Multiprocess Extract (#871)
Browse files Browse the repository at this point in the history
* requirements.txt: - Pin opencv to 4.1.1 (fixes cv2-dnn error)

* lib.face_detect.DetectedFace: change LandmarksXY to landmarks_xy. Add left, right, top, bottom attributes

* lib.model.session: Session manager for loading models into different graphs (for Nvidia + CPU)

* plugins.extract._base: New parent class for all extract plugins

* plugins.extract.pipeline. Remove MultiProcessing. Dynamically limit batchsize for Nvidia cards. Remove loglevel input

* S3FD + FAN plugins. Standardise to Keras version for all backends

* Standardize all extract plugins to new threaded codebase

* Documentation. Start implementing Numpy style docstrings for Sphinx Documentation

* Remove s3fd_amd. Change convert OTF to expect DetectedFace object

* faces_detect - clean up and documentation

* Remove PoolProcess

* Migrate manual tool to new extract workflow

* Remove AMD specific extractor code from cli and plugins

* Sort tool to new extract workflow

* Remove multiprocessing from project

* Remove multiprocessing queues from QueueManager

* Remove multiprocessing support from logger

* Move face_filter to new extraction pipeline

* Alignments landmarksXY > landmarks_xy and legacy handling

* Intercept get_backend for sphinx doc build

# Add Sphinx documentation
  • Loading branch information
torzdf committed Sep 15, 2019
1 parent 23bb80a commit 88352b0
Show file tree
Hide file tree
Showing 51 changed files with 3,058 additions and 3,268 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
!*.nsi
!*.png
!*.py
!*.rst
!*.txt
!.cache
!Dockerfile*
!requirements*
!.install/
!.install/windows
!docs
!docs/full
!config/
!lib/
!lib/*
Expand Down
54 changes: 54 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('../'))
sys.setrecursionlimit(1500)

# -- Project information -----------------------------------------------------

project = 'faceswap'
copyright = '2019, faceswap.dev'
author = 'faceswap.dev'

# The full version, including alpha/beta/rc tags
release = '0.99'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.napoleon', ]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
7 changes: 7 additions & 0 deletions docs/full/lib.faces_detect.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
lib.faces\_detect module
========================

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

Submodules
----------

.. toctree::

lib.model.session

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

.. automodule:: lib.model
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/full/lib.model.session.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
lib.model.session module
========================

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

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

.. toctree::

lib.model
lib.faces_detect

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

.. automodule:: lib
:members:
:undoc-members:
:show-inheritance:
8 changes: 8 additions & 0 deletions docs/full/modules.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
faceswap
========

.. toctree::
:maxdepth: 4

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

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

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

Submodules
----------

.. toctree::

plugins.extract.align._base

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

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

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

Submodules
----------

.. toctree::

plugins.extract.detect._base

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

.. automodule:: plugins.extract.detect
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/full/plugins.extract.pipeline.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins.extract.pipeline module
===============================

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

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

.. toctree::

plugins.extract.align
plugins.extract.detect

Submodules
----------

.. toctree::

plugins.extract._base
plugins.extract.pipeline

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

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

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

.. toctree::

plugins.extract

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

.. automodule:: plugins
:members:
:undoc-members:
:show-inheritance:
21 changes: 21 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.. faceswap documentation master file, created by
sphinx-quickstart on Fri Sep 13 11:28:50 2019.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
faceswap.dev Developer Documentation
====================================

.. toctree::
:maxdepth: 6
:caption: Contents:

full/modules


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
4 changes: 2 additions & 2 deletions lib/aligner.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ def get_matrix_scaling(mat):
def get_align_mat(face, size, should_align_eyes):
""" Return the alignment Matrix """
logger.trace("size: %s, should_align_eyes: %s", size, should_align_eyes)
mat_umeyama = umeyama(np.array(face.landmarks_as_xy[17:]), True)[0:2]
mat_umeyama = umeyama(np.array(face.landmarks_xy[17:]), True)[0:2]

if should_align_eyes is False:
return mat_umeyama

mat_umeyama = mat_umeyama * size

# Convert to matrix
landmarks = np.matrix(face.landmarks_as_xy)
landmarks = np.matrix(face.landmarks_xy)

# cv2 expects points to be in the form
# np.array([ [[x1, y1]], [[x2, y2]], ... ]), we'll expand the dim
Expand Down
28 changes: 28 additions & 0 deletions lib/alignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self, folder, filename="alignments", serializer="json"):
self.file = self.get_location(folder, filename)

self.data = self.load()
self.update_legacy()
logger.debug("Initialized %s", self.__class__.__name__)

# << PROPERTIES >> #
Expand Down Expand Up @@ -272,6 +273,11 @@ def yield_original_index_reverse(image_alignments, number_alignments):

# << LEGACY FUNCTIONS >> #

def update_legacy(self):
""" Update legacy alignments """
if self.has_legacy_landmarksxy():
logger.info("Updating legacy alignments")
self.update_legacy_landmarksxy()
# < Rotation > #
# The old rotation method would rotate the image to find a face, then
# store the rotated landmarks along with a rotation value to tell the
Expand Down Expand Up @@ -361,3 +367,25 @@ def add_face_hashes(self, frame_name, hashes):
abs(count_match), msg, frame_name)
for idx, i_hash in hashes.items():
faces[idx]["hash"] = i_hash

# <landmarks> #
# Landmarks renamed from landmarksXY to landmarks_xy for PEP compliance
def has_legacy_landmarksxy(self):
""" check for legacy landmarksXY keys """
logger.debug("checking legacy landmarksXY")
retval = (any(key == "landmarksXY"
for alignments in self.data.values()
for alignment in alignments
for key in alignment))
logger.debug("legacy landmarksXY: %s", retval)
return retval

def update_legacy_landmarksxy(self):
""" Update landmarksXY to landmarks_xy and save alignments """
update_count = 0
for alignments in self.data.values():
for alignment in alignments:
alignment["landmarks_xy"] = alignment.pop("landmarksXY")
update_count += 1
logger.debug("Updated landmarks_xy: %s", update_count)
self.save()

0 comments on commit 88352b0

Please sign in to comment.