automatized arguments with pickle

This commit is contained in:
leno3003 2022-03-28 15:54:06 +02:00
parent 9704c5d8f8
commit 688b3e1567
2 changed files with 80 additions and 7 deletions

View file

@ -4,6 +4,7 @@ import sys
import threading import threading
import time import time
import types import types
import pickle
import colorama import colorama
import cv2 import cv2
@ -43,6 +44,14 @@ class InteractBase(object):
self.error_log_line_prefix = '/!\\ ' self.error_log_line_prefix = '/!\\ '
self.process_messages_callbacks = {} self.process_messages_callbacks = {}
self.default_answers = {}
answer_filename = '/home/deepfake/interact_dict.pkl'
try:
with open(answer_filename, 'rb') as file:
self.default_answers = pickle.load(file)
except IOError:
pass
def is_support_windows(self): def is_support_windows(self):
return False return False
@ -210,7 +219,17 @@ class InteractBase(object):
self.key_events[wnd_name] = [] self.key_events[wnd_name] = []
return ar return ar
def input(self, s): def input(self, s, def_ans=" "):
#f = open("/home/deepfake/interact.txt", "a")
#f.write(s + def_ans + "\n")
#f.close()
print("La stringa è: ", s)
if "WARNING " in s:
return "\n"
if s in self.default_answers:
return self.default_value[s]
return input(s) return input(s)
def input_number(self, s, default_value, valid_list=None, show_default_value=True, add_info=None, help_message=None): def input_number(self, s, default_value, valid_list=None, show_default_value=True, add_info=None, help_message=None):
@ -234,7 +253,7 @@ class InteractBase(object):
while True: while True:
try: try:
inp = input(s) inp = self.input(s, str(default_value))
if len(inp) == 0: if len(inp) == 0:
result = default_value result = default_value
break break
@ -286,7 +305,7 @@ class InteractBase(object):
while True: while True:
try: try:
inp = input(s) inp = self.input(s, str(default_value))
if len(inp) == 0: if len(inp) == 0:
raise ValueError("") raise ValueError("")
@ -318,7 +337,7 @@ class InteractBase(object):
while True: while True:
try: try:
inp = input(s) inp = self.input(s, str(default_value))
if len(inp) == 0: if len(inp) == 0:
raise ValueError("") raise ValueError("")
@ -331,7 +350,7 @@ class InteractBase(object):
print ( "y" if default_value else "n" ) print ( "y" if default_value else "n" )
return default_value return default_value
def input_str(self, s, default_value=None, valid_list=None, show_default_value=True, help_message=None): def input_str(self, s, default_value, valid_list=None, show_default_value=True, help_message=None):
if show_default_value and default_value is not None: if show_default_value and default_value is not None:
s = f"[{default_value}] {s}" s = f"[{default_value}] {s}"
@ -354,7 +373,7 @@ class InteractBase(object):
while True: while True:
try: try:
inp = input(s) inp = self.input(s, default_value)
if len(inp) == 0: if len(inp) == 0:
if default_value is None: if default_value is None:
@ -388,7 +407,7 @@ class InteractBase(object):
def input_process(self, stdin_fd, sq, str): def input_process(self, stdin_fd, sq, str):
sys.stdin = os.fdopen(stdin_fd) sys.stdin = os.fdopen(stdin_fd)
try: try:
inp = input (str) inp = self.input (str)
sq.put (True) sq.put (True)
except: except:
sq.put (False) sq.put (False)
@ -399,6 +418,9 @@ class InteractBase(object):
p.daemon = True p.daemon = True
p.start() p.start()
t = time.time() t = time.time()
if 'Override' in self.default_answers:
return True
inp = False inp = False
while True: while True:
if not sq.empty(): if not sq.empty():

51
interact_dict.py Normal file
View file

@ -0,0 +1,51 @@
import pickle
dictionary = {
'[png] Output image format ( png/jpg ?:help ) : ' : 'png',
' : ' : '0',
'Override' : '0',
' Press enter in 2 seconds to override model settings. ' : '\n',
'[0] Which GPU indexes to choose? : ' : '0',
'[wf] Face type ( f/wf/head ?:help ) : ' : 'wf',
'[0] Max number of faces from image ( ?:help ) : ' : '0',
'[512] Image size ( 256-2048 ?:help ) : ' : '512',
'[90] Jpeg quality ( 1-100 ?:help ) : ' : '90',
'[n] Write debug images to aligned_debug? ( y/n ) : ' : 'False',
'[y] Continue extraction? ( y/n ?:help ) : ' : 'True',
'[2] Autobackup every N hour ( 0..24 ?:help ) : ' : '2',
'[n] Write preview history ( y/n ?:help ) : ' : 'False',
'[83000] Target iteration : ' : '83000',
'[n] Flip SRC faces randomly ( y/n ?:help ) : ' : 'False',
'[n] Flip DST faces randomly ( y/n ?:help ) : ' : 'False',
'[4] Batch_size ( ?:help ) : ' : '4',
'[n] Eyes and mouth priority ( y/n ?:help ) : ' : 'False',
'[y] Uniform yaw distribution of samples ( y/n ?:help ) : ' : 'True',
'[n] Blur out mask ( y/n ?:help ) : ' : 'False',
'[y] Place models and optimizer on GPU ( y/n ?:help ) : ' : 'True',
'[y] Use AdaBelief optimizer? ( y/n ?:help ) : ' : 'True',
'[n] Use learning rate dropout ( n/y/cpu ?:help ) : ' : 'n',
'[y] Enable random warp of samples ( y/n ?:help ) : ' : 'True',
'[0.0] Random hue/saturation/light intensity ( 0.0 .. 0.3 ?:help ) : ' : '0.0',
'[0.0] GAN power ( 0.0 .. 5.0 ?:help ) : ' : '0.0',
'[0.0] Face style power ( 0.0..100.0 ?:help ) : ' : '0.0',
'[0.0] Background style power ( 0.0..100.0 ?:help ) : ' : '0.0',
'[lct] Color transfer for src faceset ( none/rct/lct/mkl/idt/sot ?:help ) : ' : 'lct',
'[n] Enable gradient clipping ( y/n ?:help ) : ' : 'False',
'[n] Enable pretraining mode ( y/n ?:help ) : ' : 'False',
'[n] Use interactive merger? ( y/n ) : ' : 'False',
'[1] 2 : ' : '1',
'[1] 3 : ' : '1',
'[0] Choose erode mask modifier ( -400..400 ) : ' : '0',
'[0] Choose blur mask modifier ( 0..400 ) : ' : '0',
'[0] Choose motion blur power ( 0..100 ) : ' : '0',
'[0] Choose output face scale modifier ( -50..50 ) : ' : '0',
'[0] 1 ( ?:help ) : ' : '0',
'[0] Choose super resolution power ( 0..100 ?:help ) : ' : '0',
'[0] Choose image degrade by denoise power ( 0..500 ) : ' : '0',
'[0] Choose image degrade by bicubic rescale power ( 0..100 ) : ' : '0',
'[0] Degrade color power of final image ( 0..100 ) : ' : '0',
'[8] Number of workers? ( 1-8 ?:help ) : ' : '8',
'[16] Bitrate of output file in MB/s : ' : '16',
}
with open('interact_dict.pkl', 'wb') as handle:
pickle.dump(dictionary, handle, protocol=pickle.HIGHEST_PROTOCOL)