Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit 5b4d023

Browse files
committed
added 5.XSeg) data_dst/data_src mask for XSeg trainer - remove.bat
removes labeled xseg polygons from the extracted frames
1 parent b6b3936 commit 5b4d023

File tree

3 files changed

+69
-17
lines changed

3 files changed

+69
-17
lines changed

DFLIMG/DFLJPG.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ def get_image_to_face_mat(self):
245245
return None
246246
def set_image_to_face_mat(self, image_to_face_mat): self.dfl_dict['image_to_face_mat'] = image_to_face_mat
247247

248+
def has_seg_ie_polys(self):
249+
return self.dfl_dict.get('seg_ie_polys',None) is not None
250+
248251
def get_seg_ie_polys(self):
249252
d = self.dfl_dict.get('seg_ie_polys',None)
250253
if d is not None:
@@ -266,6 +269,9 @@ def set_seg_ie_polys(self, seg_ie_polys):
266269

267270
self.dfl_dict['seg_ie_polys'] = seg_ie_polys
268271

272+
def has_xseg_mask(self):
273+
return self.dfl_dict.get('xseg_mask',None) is not None
274+
269275
def get_xseg_mask(self):
270276
mask_buf = self.dfl_dict.get('xseg_mask',None)
271277
if mask_buf is None:

main.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,7 @@ def process_xsegapply(arguments):
278278
p.set_defaults (func=process_xsegapply)
279279

280280

281-
p = xseg_parser.add_parser( "remove", help="Remove XSeg from the extracted faces.")
282-
281+
p = xseg_parser.add_parser( "remove", help="Remove applied XSeg masks from the extracted faces.")
283282
def process_xsegremove(arguments):
284283
osex.set_process_lowest_prio()
285284
from mainscripts import XSegUtil
@@ -288,6 +287,15 @@ def process_xsegremove(arguments):
288287
p.set_defaults (func=process_xsegremove)
289288

290289

290+
p = xseg_parser.add_parser( "remove_labels", help="Remove XSeg labels from the extracted faces.")
291+
def process_xsegremovelabels(arguments):
292+
osex.set_process_lowest_prio()
293+
from mainscripts import XSegUtil
294+
XSegUtil.remove_xseg_labels (Path(arguments.input_dir) )
295+
p.add_argument('--input-dir', required=True, action=fixPathAction, dest="input_dir")
296+
p.set_defaults (func=process_xsegremovelabels)
297+
298+
291299
p = xseg_parser.add_parser( "fetch", help="Copies faces containing XSeg polygons in <input_dir>_xseg dir.")
292300

293301
def process_xsegfetch(arguments):

mainscripts/XSegUtil.py

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,7 @@ def apply_xseg(input_path, model_path):
5454
dflimg.set_xseg_mask(mask)
5555
dflimg.save()
5656

57-
def remove_xseg(input_path):
58-
if not input_path.exists():
59-
raise ValueError(f'{input_path} not found. Please ensure it exists.')
60-
61-
images_paths = pathex.get_image_paths(input_path, return_Path_class=True)
62-
63-
for filepath in io.progress_bar_generator(images_paths, "Processing"):
64-
dflimg = DFLIMG.load(filepath)
65-
if dflimg is None or not dflimg.has_data():
66-
io.log_info(f'{filepath} is not a DFLIMG')
67-
continue
68-
69-
dflimg.set_xseg_mask(None)
70-
dflimg.save()
57+
7158

7259
def fetch_xseg(input_path):
7360
if not input_path.exists():
@@ -93,4 +80,55 @@ def fetch_xseg(input_path):
9380
files_copied += 1
9481
shutil.copy ( str(filepath), str(output_path / filepath.name) )
9582

96-
io.log_info(f'Files copied: {files_copied}')
83+
io.log_info(f'Files copied: {files_copied}')
84+
85+
def remove_xseg(input_path):
86+
if not input_path.exists():
87+
raise ValueError(f'{input_path} not found. Please ensure it exists.')
88+
89+
io.log_info(f'Processing folder {input_path}')
90+
io.log_info('!!! WARNING : APPLIED XSEG MASKS WILL BE REMOVED FROM THE FRAMES !!!')
91+
io.log_info('!!! WARNING : APPLIED XSEG MASKS WILL BE REMOVED FROM THE FRAMES !!!')
92+
io.log_info('!!! WARNING : APPLIED XSEG MASKS WILL BE REMOVED FROM THE FRAMES !!!')
93+
io.input_str('Press enter to continue.')
94+
95+
images_paths = pathex.get_image_paths(input_path, return_Path_class=True)
96+
97+
files_processed = 0
98+
for filepath in io.progress_bar_generator(images_paths, "Processing"):
99+
dflimg = DFLIMG.load(filepath)
100+
if dflimg is None or not dflimg.has_data():
101+
io.log_info(f'{filepath} is not a DFLIMG')
102+
continue
103+
104+
if dflimg.has_xseg_mask():
105+
dflimg.set_xseg_mask(None)
106+
dflimg.save()
107+
files_processed += 1
108+
io.log_info(f'Files processed: {files_processed}')
109+
110+
def remove_xseg_labels(input_path):
111+
if not input_path.exists():
112+
raise ValueError(f'{input_path} not found. Please ensure it exists.')
113+
114+
io.log_info(f'Processing folder {input_path}')
115+
io.log_info('!!! WARNING : LABELED XSEG POLYGONS WILL BE REMOVED FROM THE FRAMES !!!')
116+
io.log_info('!!! WARNING : LABELED XSEG POLYGONS WILL BE REMOVED FROM THE FRAMES !!!')
117+
io.log_info('!!! WARNING : LABELED XSEG POLYGONS WILL BE REMOVED FROM THE FRAMES !!!')
118+
io.input_str('Press enter to continue.')
119+
120+
images_paths = pathex.get_image_paths(input_path, return_Path_class=True)
121+
122+
files_processed = 0
123+
for filepath in io.progress_bar_generator(images_paths, "Processing"):
124+
dflimg = DFLIMG.load(filepath)
125+
if dflimg is None or not dflimg.has_data():
126+
io.log_info(f'{filepath} is not a DFLIMG')
127+
continue
128+
129+
if dflimg.has_seg_ie_polys():
130+
dflimg.set_seg_ie_polys(None)
131+
dflimg.save()
132+
files_processed += 1
133+
134+
io.log_info(f'Files processed: {files_processed}')

0 commit comments

Comments
 (0)