Skip to content

Commit

Permalink
Alignments tool: Remove extract-large and add large option
Browse files Browse the repository at this point in the history
  • Loading branch information
torzdf committed Sep 26, 2019
1 parent c2e54bb commit 46efae3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
4 changes: 1 addition & 3 deletions tools/alignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ def get_dest_format(self):

def process(self):
""" Main processing function of the Align tool """
if self.args.job.startswith("extract"):
job = Extract
elif self.args.job == "update-hashes":
if self.args.job == "update-hashes":
job = UpdateHashes
elif self.args.job.startswith("remove-"):
job = RemoveAlignments
Expand Down
34 changes: 18 additions & 16 deletions tools/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def get_argument_list(self):
"opts": ("-j", "--job"),
"action": Radio,
"type": str,
"choices": ("draw", "extract", "extract-large", "manual", "merge",
"missing-alignments", "missing-frames", "legacy", "leftover-faces",
"multi-faces", "no-faces", "reformat", "remove-faces", "remove-frames",
"rename", "sort-x", "sort-y", "spatial", "update-hashes"),
"choices": ("draw", "extract", "manual", "merge", "missing-alignments",
"missing-frames", "legacy", "leftover-faces", "multi-faces", "no-faces",
"reformat", "remove-faces", "remove-frames", "rename", "sort-x", "sort-y",
"spatial", "update-hashes"),
"required": True,
"help": "R|Choose which action you want to perform. "
"NB: All actions require an alignments file (-a) to be passed in."
Expand All @@ -45,10 +45,6 @@ def get_argument_list(self):
"alignment data. This is a lot quicker than re-detecting faces. Can pass in "
"the '-een' (--extract-every-n) parameter to only extract every nth frame." +
frames_and_faces_dir + align_eyes +
"\nL|'extract-large': - Extract all faces that have not been upscaled. Useful "
"for excluding low-res images from a training set.. Can pass in the '-een' "
"(--extract-every-n) parameter to only extract every nth frame." +
frames_and_faces_dir + align_eyes +
"\nL|'manual': Manually view and edit landmarks." + frames_dir +
"\nL|'merge': Merge multiple alignment files into one. Specify a space "
"separated list of alignments files with the -a flag. Optionally specify a "
Expand Down Expand Up @@ -140,26 +136,32 @@ def get_argument_list(self):
"default": 1,
"rounding": 1,
"group": "extract",
"help": "Extract every 'nth' frame. This option will skip frames "
"when extracting faces. For example a value of 1 will "
"extract faces from every frame, a value of 10 will extract "
"faces from every 10th frame. (extract only)"})
"help": "[Extract only] Extract every 'nth' frame. This option will "
"skip frames when extracting faces. For example a value of "
"1 will extract faces from every frame, a value of 10 will "
"extract faces from every 10th frame."})
argument_list.append({"opts": ("-sz", "--size"),
"type": int,
"action": Slider,
"min_max": (128, 512),
"default": 256,
"group": "extract",
"rounding": 64,
"help": "The output size of extracted faces. (extract only)"})
"help": "[Extract only] The output size of extracted faces."})
argument_list.append({"opts": ("-ae", "--align-eyes"),
"action": "store_true",
"dest": "align_eyes",
"group": "extract",
"default": False,
"help": "Perform extra alignment to ensure "
"left/right eyes are at the same "
"height. (Extract only)"})
"help": "[Extract only] Perform extra alignment to ensure "
"left/right eyes are at the same height."})
argument_list.append({"opts": ("-l", "--large"),
"action": "store_true",
"group": "extract",
"default": False,
"help": "[Extract only] Only extract faces that have not been "
"upscaled to the required size (`-sz`, `--size). Useful "
"for excluding low-res images from a training set."})
argument_list.append({"opts": ("-dm", "--disable-monitor"),
"action": "store_true",
"group": "manual tool",
Expand Down
9 changes: 4 additions & 5 deletions tools/lib_alignments/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,8 @@ class Extract():
Alignment data """
def __init__(self, alignments, arguments):
logger.debug("Initializing %s: (arguments: %s)", self.__class__.__name__, arguments)
self.alignments = alignments
self.arguments = arguments
self.type = arguments.job.replace("extract-", "")
self.alignments = alignments
self.faces_dir = arguments.faces_dir
self.frames = Frames(arguments.frames_dir)
self.extracted_faces = ExtractedFaces(self.frames,
Expand Down Expand Up @@ -375,7 +374,7 @@ def export_faces(self):

extracted_faces += self.output_faces(frame)

if extracted_faces != 0 and self.type != "large":
if extracted_faces != 0 and not self.arguments.large:
self.alignments.save()
logger.info("%s face(s) extracted", extracted_faces)

Expand All @@ -390,7 +389,7 @@ def output_faces(self, frame):

for idx, face in enumerate(faces):
output = "{}_{}{}".format(frame_name, str(idx), extension)
if self.type == "large":
if self.arguments.large:
self.frames.save_image(self.faces_dir, output, face.aligned_face)
else:
output = os.path.join(self.faces_dir, output)
Expand All @@ -404,7 +403,7 @@ def output_faces(self, frame):
def select_valid_faces(self, frame):
""" Return valid faces for extraction """
faces = self.extracted_faces.get_faces_in_frame(frame)
if self.type != "large":
if not self.arguments.large:
valid_faces = faces
else:
sizes = self.extracted_faces.get_roi_size_for_frame(frame)
Expand Down

0 comments on commit 46efae3

Please sign in to comment.