fixed waifu2x-ncnn-vulkan argument errors

This commit is contained in:
k4yt3x 2019-08-03 21:29:13 -04:00
parent e3b2624977
commit f42a8ab71f
2 changed files with 21 additions and 50 deletions

View File

@ -41,15 +41,15 @@
}, },
"waifu2x_ncnn_vulkan": { "waifu2x_ncnn_vulkan": {
"waifu2x_ncnn_vulkan_path": "C:\\Users\\K4YT3X\\AppData\\Local\\video2x\\waifu2x-ncnn-vulkan\\waifu2x-ncnn-vulkan.exe", "waifu2x_ncnn_vulkan_path": "C:\\Users\\K4YT3X\\AppData\\Local\\video2x\\waifu2x-ncnn-vulkan\\waifu2x-ncnn-vulkan.exe",
"input": null, "v": null,
"output": null, "i": null,
"noise-level": 2, "o": null,
"scale-ratio": null, "n": 2,
"tile-size": 200, "s": 2,
"model-path": null, "t": 400,
"gpu": 0, "m": "models-cunet",
"load-proc-save_threads": null, "g": 0,
"verbose": null "j": "1:2:2"
}, },
"ffmpeg": { "ffmpeg": {
"ffmpeg_path": "C:\\Users\\K4YT3X\\AppData\\Local\\video2x\\ffmpeg-latest-win64-static\\bin", "ffmpeg_path": "C:\\Users\\K4YT3X\\AppData\\Local\\video2x\\ffmpeg-latest-win64-static\\bin",

View File

@ -52,28 +52,15 @@ class Waifu2xNcnnVulkan:
try: try:
# overwrite config file settings # overwrite config file settings
self.waifu2x_settings['input'] = input_directory self.waifu2x_settings['i'] = input_directory
self.waifu2x_settings['output'] = output_directory self.waifu2x_settings['o'] = output_directory
self.waifu2x_settings['s'] = scale_ratio
# print thread start message # print thread start message
self.print_lock.acquire() self.print_lock.acquire()
Avalon.debug_info(f'[upscaler] Thread {threading.current_thread().name} started') Avalon.debug_info(f'[upscaler] Thread {threading.current_thread().name} started')
self.print_lock.release() self.print_lock.release()
# waifu2x_ncnn_vulkan does not have long-opts, we'll have a dictionary that maps "our" config long-opt
# names to their short opts
waifu2x_ncnn_vulkan_opt_flag = {
'input': '-i',
'output': '-o',
'noise-level': '-n',
'scale-ratio': '-s',
'tile-size': '-t',
'model-path': '-m',
'gpu': '-g',
'load-proc-save_threads': '-j',
'verbose': '-v'
}
# list to be executed # list to be executed
# initialize the list with waifu2x binary path as the first element # initialize the list with waifu2x binary path as the first element
execute = [str(self.waifu2x_settings['waifu2x_ncnn_vulkan_path'])] execute = [str(self.waifu2x_settings['waifu2x_ncnn_vulkan_path'])]
@ -82,41 +69,25 @@ class Waifu2xNcnnVulkan:
value = self.waifu2x_settings[key] value = self.waifu2x_settings[key]
if key == 'waifu2x_ncnn_vulkan_path': # is executable key or null or None means that leave this option out (keep default)
if key == 'waifu2x_ncnn_vulkan_path' or value is None or value is False:
continue continue
elif key == 'input':
execute.append(waifu2x_ncnn_vulkan_opt_flag[key])
execute.append(input_directory)
elif key == 'output':
execute.append(waifu2x_ncnn_vulkan_opt_flag[key])
execute.append(output_directory)
elif key == 'scale-ratio':
execute.append(waifu2x_ncnn_vulkan_opt_flag[key])
# waifu2x_ncnn_vulkan does not accept an arbitrary scale ratio, max is 2
if scale_ratio == 1:
execute.append('1')
else:
execute.append('2')
# allow upper if cases to take precedence
elif value is None or value is False:
continue
else: else:
execute.append(waifu2x_ncnn_vulkan_opt_flag[key]) if len(key) == 1:
execute.append(f'-{key}')
else:
execute.append(f'--{key}')
execute.append(str(value)) execute.append(str(value))
Avalon.debug_info(f'Executing: {execute}') Avalon.debug_info(f'Executing: {execute}')
subprocess.run(execute, check=True, stderr=subprocess.DEVNULL) completed_command = subprocess.run(execute, check=True)
# print thread exiting message # print thread exiting message
self.print_lock.acquire() self.print_lock.acquire()
Avalon.debug_info(f'[upscaler] Thread {threading.current_thread().name} exiting') Avalon.debug_info(f'[upscaler] Thread {threading.current_thread().name} exiting')
self.print_lock.release() self.print_lock.release()
return 0 # return command execution return code
return completed_command.returncode
except Exception as e: except Exception as e:
upscaler_exceptions.append(e) upscaler_exceptions.append(e)