From ab8199e2430509d744a547eb278dc4667c632f3a Mon Sep 17 00:00:00 2001 From: torzdf <36920800+torzdf@users.noreply.github.com> Date: Wed, 3 Apr 2024 15:30:46 +0100 Subject: [PATCH] linting + typing --- tools/alignments/alignments.py | 4 ++-- tools/alignments/jobs.py | 2 +- tools/alignments/jobs_faces.py | 8 ++++---- tools/alignments/jobs_frames.py | 4 ++-- tools/alignments/media.py | 4 ++-- tools/manual/detected_faces.py | 2 +- tools/manual/faceviewer/viewport.py | 2 +- tools/manual/frameviewer/control.py | 2 +- tools/mask/mask_generate.py | 2 +- tools/mask/mask_import.py | 2 +- tools/model/model.py | 8 ++++---- tools/sort/sort_methods_aligned.py | 2 +- 12 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tools/alignments/alignments.py b/tools/alignments/alignments.py index 8017d149c6..eca95982ec 100644 --- a/tools/alignments/alignments.py +++ b/tools/alignments/alignments.py @@ -18,7 +18,7 @@ logger = logging.getLogger(__name__) -class Alignments(): # pylint:disable=too-few-public-methods +class Alignments(): """ The main entry point for Faceswap's Alignments Tool. This tool is part of the Faceswap Tools suite and should be called from the ``python tools.py alignments`` command. @@ -239,7 +239,7 @@ def process(self): self._run_process(args) -class _Alignments(): # pylint:disable=too-few-public-methods +class _Alignments(): """ The main entry point for Faceswap's Alignments Tool. This tool is part of the Faceswap Tools suite and should be called from the ``python tools.py alignments`` command. diff --git a/tools/alignments/jobs.py b/tools/alignments/jobs.py index 2dfdc9a75b..2642ebaaaa 100644 --- a/tools/alignments/jobs.py +++ b/tools/alignments/jobs.py @@ -418,7 +418,7 @@ def reindex_faces(self) -> int: return reindexed -class Spatial(): # pylint:disable=too-few-public-methods +class Spatial(): """ Apply spatial temporal filtering to landmarks Parameters diff --git a/tools/alignments/jobs_faces.py b/tools/alignments/jobs_faces.py index 3dae491e5d..ac2205f89c 100644 --- a/tools/alignments/jobs_faces.py +++ b/tools/alignments/jobs_faces.py @@ -25,7 +25,7 @@ logger = logging.getLogger(__name__) -class FromFaces(): # pylint:disable=too-few-public-methods +class FromFaces(): """ Scan a folder of Faceswap Extracted Faces and re-create the associated alignments file(s) Parameters @@ -222,7 +222,7 @@ def _save_alignments(self, aln.save() -class Rename(): # pylint:disable=too-few-public-methods +class Rename(): """ Rename faces in a folder to match their filename as stored in an alignments file. Parameters @@ -319,7 +319,7 @@ def _rename_faces(self, filename_mappings: list[tuple[str, str]]) -> int: return rename_count -class RemoveFaces(): # pylint:disable=too-few-public-methods +class RemoveFaces(): """ Remove items from alignments file. Parameters @@ -407,7 +407,7 @@ def _update_png_headers(self) -> None: logger.info("%s Extracted face(s) had their header information updated", len(to_update)) -class FaceToFile(): # pylint:disable=too-few-public-methods +class FaceToFile(): """ Updates any optional/missing keys in the alignments file with any data that has been populated in a PNGHeader. Includes masks and identity fields. diff --git a/tools/alignments/jobs_frames.py b/tools/alignments/jobs_frames.py index 62ce578df1..8f7efb9b85 100644 --- a/tools/alignments/jobs_frames.py +++ b/tools/alignments/jobs_frames.py @@ -25,7 +25,7 @@ logger = logging.getLogger(__name__) -class Draw(): # pylint:disable=too-few-public-methods +class Draw(): """ Draws annotations onto original frames and saves into a sub-folder next to the original frames. @@ -171,7 +171,7 @@ def _annotate_pose(cls, image: np.ndarray, face: DetectedFace) -> None: cv2.line(image, tuple(center), tuple(points[2]), (0, 0, 255), 2) -class Extract(): # pylint:disable=too-few-public-methods +class Extract(): """ Re-extract faces from source frames based on Alignment data Parameters diff --git a/tools/alignments/media.py b/tools/alignments/media.py index a68da7835c..eee258c8f1 100644 --- a/tools/alignments/media.py +++ b/tools/alignments/media.py @@ -245,8 +245,8 @@ def save_image(output_folder: str, output_file = os.path.splitext(output_file)[0] + ".png" logger.trace("Saving image: '%s'", output_file) # type: ignore if metadata: - encoded_image = cv2.imencode(".png", image)[1] - encoded_image = png_write_meta(encoded_image.tobytes(), metadata) + encoded = cv2.imencode(".png", image)[1] + encoded_image = png_write_meta(encoded.tobytes(), metadata) with open(output_file, "wb") as out_file: out_file.write(encoded_image) else: diff --git a/tools/manual/detected_faces.py b/tools/manual/detected_faces.py index 0f9cf1cc1b..29d187f86c 100644 --- a/tools/manual/detected_faces.py +++ b/tools/manual/detected_faces.py @@ -248,7 +248,7 @@ def _get_alignments(self, alignments_path: str, input_location: str) -> Alignmen return retval -class _DiskIO(): # pylint:disable=too-few-public-methods +class _DiskIO(): """ Handles the loading of :class:`~lib.align.DetectedFaces` from the alignments file into :class:`DetectedFaces` and the saving of this data (in the opposite direction) to an alignments file. diff --git a/tools/manual/faceviewer/viewport.py b/tools/manual/faceviewer/viewport.py index 0ca4818d8f..8b52ac2812 100644 --- a/tools/manual/faceviewer/viewport.py +++ b/tools/manual/faceviewer/viewport.py @@ -636,7 +636,7 @@ def _shift(self): return True -class HoverBox(): # pylint:disable=too-few-public-methods +class HoverBox(): """ Handle the current mouse location when over the :class:`Viewport`. Highlights the face currently underneath the cursor and handles actions when clicking diff --git a/tools/manual/frameviewer/control.py b/tools/manual/frameviewer/control.py index 2112ad174f..8230f24b00 100644 --- a/tools/manual/frameviewer/control.py +++ b/tools/manual/frameviewer/control.py @@ -157,7 +157,7 @@ def goto_last_frame(self): self._globals.tk_transport_index.set(frame_count - 1) -class BackgroundImage(): # pylint:disable=too-few-public-methods +class BackgroundImage(): """ The background image of the canvas """ def __init__(self, canvas): self._canvas = canvas diff --git a/tools/mask/mask_generate.py b/tools/mask/mask_generate.py index 4b09172ce6..a1a7f628ef 100644 --- a/tools/mask/mask_generate.py +++ b/tools/mask/mask_generate.py @@ -21,7 +21,7 @@ logger = logging.getLogger(__name__) -class MaskGenerator: # pylint:disable=too-few-public-methods +class MaskGenerator: """ Uses faceswap's extract pipeline to generate masks and update them into the alignments file and/or extracted face PNG Headers diff --git a/tools/mask/mask_import.py b/tools/mask/mask_import.py index 48262c6299..e9a0f4beac 100644 --- a/tools/mask/mask_import.py +++ b/tools/mask/mask_import.py @@ -26,7 +26,7 @@ logger = logging.getLogger(__name__) -class Import: # pylint:disable=too-few-public-methods +class Import: """ Import masks from disk into an Alignments file Parameters diff --git a/tools/model/model.py b/tools/model/model.py index d179d8d9ae..0cb3a033b3 100644 --- a/tools/model/model.py +++ b/tools/model/model.py @@ -23,7 +23,7 @@ logger = logging.getLogger(__name__) -class Model(): # pylint:disable=too-few-public-methods +class Model(): """ Tool to perform actions on a model file. Parameters @@ -105,7 +105,7 @@ def process(self) -> None: self._job.process() -class Inference(): # pylint:disable=too-few-public-methods +class Inference(): """ Save an inference model from a trained Faceswap model. Parameters @@ -153,7 +153,7 @@ def process(self) -> None: inference.save(self._output_file) -class NaNScan(): # pylint:disable=too-few-public-methods +class NaNScan(): """ Tool to scan for NaN and Infs in model weights. Parameters @@ -245,7 +245,7 @@ def process(self) -> None: self._parse_output(errors) -class Restore(): # pylint:disable=too-few-public-methods +class Restore(): """ Restore a model from backup. Parameters diff --git a/tools/sort/sort_methods_aligned.py b/tools/sort/sort_methods_aligned.py index ecf6dd4af4..34275efbdd 100644 --- a/tools/sort/sort_methods_aligned.py +++ b/tools/sort/sort_methods_aligned.py @@ -22,7 +22,7 @@ logger = logging.getLogger(__name__) -class SortAlignedMetric(SortMethod): # pylint:disable=too-few-public-methods +class SortAlignedMetric(SortMethod): """ Sort by comparison of metrics stored in an Aligned Face objects. This is a parent class for sort by aligned metrics methods. Individual methods should inherit from this class