mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-07-06 13:02:15 -07:00
added option 'Choose image for the preview history? (y/n skip:'
This commit is contained in:
parent
9e05e58ac4
commit
836693d64f
6 changed files with 81 additions and 8 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -31,7 +31,11 @@ class InteractBase(object):
|
||||||
self.mouse_events = {}
|
self.mouse_events = {}
|
||||||
self.key_events = {}
|
self.key_events = {}
|
||||||
self.pg_bar = None
|
self.pg_bar = None
|
||||||
|
self.focus_wnd_name = None
|
||||||
|
|
||||||
|
def is_support_windows(self):
|
||||||
|
return False
|
||||||
|
|
||||||
def is_colab(self):
|
def is_colab(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -40,7 +44,10 @@ class InteractBase(object):
|
||||||
|
|
||||||
def on_create_window (self, wnd_name):
|
def on_create_window (self, wnd_name):
|
||||||
raise NotImplemented
|
raise NotImplemented
|
||||||
|
|
||||||
|
def on_destroy_window (self, wnd_name):
|
||||||
|
raise NotImplemented
|
||||||
|
|
||||||
def on_show_image (self, wnd_name, img):
|
def on_show_image (self, wnd_name, img):
|
||||||
raise NotImplemented
|
raise NotImplemented
|
||||||
|
|
||||||
|
@ -66,17 +73,39 @@ class InteractBase(object):
|
||||||
if wnd_name not in self.named_windows:
|
if wnd_name not in self.named_windows:
|
||||||
#we will show window only on first show_image
|
#we will show window only on first show_image
|
||||||
self.named_windows[wnd_name] = 0
|
self.named_windows[wnd_name] = 0
|
||||||
|
self.focus_wnd_name = wnd_name
|
||||||
else: print("named_window: ", wnd_name, " already created.")
|
else: print("named_window: ", wnd_name, " already created.")
|
||||||
|
|
||||||
def destroy_all_windows(self):
|
def destroy_all_windows(self):
|
||||||
if len( self.named_windows ) != 0:
|
if len( self.named_windows ) != 0:
|
||||||
self.on_destroy_all_windows()
|
self.on_destroy_all_windows()
|
||||||
self.named_windows = {}
|
self.named_windows = {}
|
||||||
self.capture_mouse_windows = {}
|
self.capture_mouse_windows = {}
|
||||||
self.capture_keys_windows = {}
|
self.capture_keys_windows = {}
|
||||||
self.mouse_events = {}
|
self.mouse_events = {}
|
||||||
self.key_events = {}
|
self.key_events = {}
|
||||||
|
self.focus_wnd_name = None
|
||||||
|
|
||||||
|
def destroy_window(self, wnd_name):
|
||||||
|
if wnd_name in self.named_windows:
|
||||||
|
self.on_destroy_window(wnd_name)
|
||||||
|
self.named_windows.pop(wnd_name)
|
||||||
|
|
||||||
|
if wnd_name == self.focus_wnd_name:
|
||||||
|
self.focus_wnd_name = list(self.named_windows.keys())[-1] if len( self.named_windows ) != 0 else None
|
||||||
|
|
||||||
|
if wnd_name in self.capture_mouse_windows:
|
||||||
|
self.capture_mouse_windows.pop(wnd_name)
|
||||||
|
|
||||||
|
if wnd_name in self.capture_keys_windows:
|
||||||
|
self.capture_keys_windows.pop(wnd_name)
|
||||||
|
|
||||||
|
if wnd_name in self.mouse_events:
|
||||||
|
self.mouse_events.pop(wnd_name)
|
||||||
|
|
||||||
|
if wnd_name in self.key_events:
|
||||||
|
self.key_events.pop(wnd_name)
|
||||||
|
|
||||||
def show_image(self, wnd_name, img):
|
def show_image(self, wnd_name, img):
|
||||||
if wnd_name in self.named_windows:
|
if wnd_name in self.named_windows:
|
||||||
if self.named_windows[wnd_name] == 0:
|
if self.named_windows[wnd_name] == 0:
|
||||||
|
@ -248,12 +277,18 @@ class InteractBase(object):
|
||||||
|
|
||||||
|
|
||||||
class InteractDesktop(InteractBase):
|
class InteractDesktop(InteractBase):
|
||||||
|
|
||||||
|
def is_support_windows(self):
|
||||||
|
return True
|
||||||
|
|
||||||
def on_destroy_all_windows(self):
|
def on_destroy_all_windows(self):
|
||||||
cv2.destroyAllWindows()
|
cv2.destroyAllWindows()
|
||||||
|
|
||||||
def on_create_window (self, wnd_name):
|
def on_create_window (self, wnd_name):
|
||||||
cv2.namedWindow(wnd_name)
|
cv2.namedWindow(wnd_name)
|
||||||
|
|
||||||
|
def on_destroy_window (self, wnd_name):
|
||||||
|
cv2.destroyWindow(wnd_name)
|
||||||
|
|
||||||
def on_show_image (self, wnd_name, img):
|
def on_show_image (self, wnd_name, img):
|
||||||
cv2.imshow (wnd_name, img)
|
cv2.imshow (wnd_name, img)
|
||||||
|
@ -305,14 +340,16 @@ class InteractDesktop(InteractBase):
|
||||||
time.sleep(sleep_time)
|
time.sleep(sleep_time)
|
||||||
|
|
||||||
if has_capture_keys and ord_key != -1:
|
if has_capture_keys and ord_key != -1:
|
||||||
for wnd_name in self.capture_keys_windows:
|
self.add_key_event ( self.focus_wnd_name, ord_key, False, False, shift_pressed)
|
||||||
self.add_key_event (wnd_name, ord_key, False, False, shift_pressed)
|
|
||||||
|
|
||||||
def on_wait_any_key(self):
|
def on_wait_any_key(self):
|
||||||
cv2.waitKey(0)
|
cv2.waitKey(0)
|
||||||
|
|
||||||
class InteractColab(InteractBase):
|
class InteractColab(InteractBase):
|
||||||
|
|
||||||
|
def is_support_windows(self):
|
||||||
|
return False
|
||||||
|
|
||||||
def is_colab(self):
|
def is_colab(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -323,6 +360,9 @@ class InteractColab(InteractBase):
|
||||||
def on_create_window (self, wnd_name):
|
def on_create_window (self, wnd_name):
|
||||||
pass
|
pass
|
||||||
#clear_output()
|
#clear_output()
|
||||||
|
|
||||||
|
def on_destroy_window (self, wnd_name):
|
||||||
|
pass
|
||||||
|
|
||||||
def on_show_image (self, wnd_name, img):
|
def on_show_image (self, wnd_name, img):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -85,6 +85,11 @@ class ModelBase(object):
|
||||||
else:
|
else:
|
||||||
self.options['write_preview_history'] = self.options.get('write_preview_history', False)
|
self.options['write_preview_history'] = self.options.get('write_preview_history', False)
|
||||||
|
|
||||||
|
if self.iter == 0 and self.options['write_preview_history'] and io.is_support_windows():
|
||||||
|
choose_preview_history = io.input_bool("Choose image for the preview history? (y/n skip:%s) : " % (yn_str[False]) , False)
|
||||||
|
else:
|
||||||
|
choose_preview_history = False
|
||||||
|
|
||||||
if ask_target_iter:
|
if ask_target_iter:
|
||||||
if (self.iter == 0 or ask_override):
|
if (self.iter == 0 or ask_override):
|
||||||
self.options['target_iter'] = max(0, io.input_int("Target iteration (skip:unlimited/default) : ", 0))
|
self.options['target_iter'] = max(0, io.input_int("Target iteration (skip:unlimited/default) : ", 0))
|
||||||
|
@ -168,7 +173,35 @@ class ModelBase(object):
|
||||||
raise ValueError('training data generator is not subclass of SampleGeneratorBase')
|
raise ValueError('training data generator is not subclass of SampleGeneratorBase')
|
||||||
|
|
||||||
if (self.sample_for_preview is None) or (self.iter == 0):
|
if (self.sample_for_preview is None) or (self.iter == 0):
|
||||||
self.sample_for_preview = self.generate_next_sample()
|
|
||||||
|
if self.iter == 0:
|
||||||
|
if choose_preview_history and io.is_support_windows():
|
||||||
|
wnd_name = "[p] - next. [enter] - confirm."
|
||||||
|
io.named_window(wnd_name)
|
||||||
|
io.capture_keys(wnd_name)
|
||||||
|
choosed = False
|
||||||
|
while not choosed:
|
||||||
|
self.sample_for_preview = self.generate_next_sample()
|
||||||
|
preview = self.get_static_preview()
|
||||||
|
io.show_image( wnd_name, (preview*255).astype(np.uint8) )
|
||||||
|
|
||||||
|
while True:
|
||||||
|
key_events = io.get_key_events(wnd_name)
|
||||||
|
key, chr_key, ctrl_pressed, alt_pressed, shift_pressed = key_events[-1] if len(key_events) > 0 else (0,0,False,False,False)
|
||||||
|
if key == ord('\n') or key == ord('\r'):
|
||||||
|
choosed = True
|
||||||
|
break
|
||||||
|
elif key == ord('p'):
|
||||||
|
break
|
||||||
|
|
||||||
|
try:
|
||||||
|
io.process_messages(0.1)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
choosed = True
|
||||||
|
|
||||||
|
io.destroy_window(wnd_name)
|
||||||
|
else:
|
||||||
|
self.sample_for_preview = self.generate_next_sample()
|
||||||
|
|
||||||
model_summary_text = []
|
model_summary_text = []
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue