From f42a8ab71ff72e3d135cc1aa792f71430e68ec6d Mon Sep 17 00:00:00 2001 From: k4yt3x Date: Sat, 3 Aug 2019 21:29:13 -0400 Subject: [PATCH] fixed waifu2x-ncnn-vulkan argument errors --- bin/video2x.json | 18 ++++++------- bin/waifu2x_ncnn_vulkan.py | 53 +++++++++----------------------------- 2 files changed, 21 insertions(+), 50 deletions(-) diff --git a/bin/video2x.json b/bin/video2x.json index 68bf067..19a3b5d 100644 --- a/bin/video2x.json +++ b/bin/video2x.json @@ -41,15 +41,15 @@ }, "waifu2x_ncnn_vulkan": { "waifu2x_ncnn_vulkan_path": "C:\\Users\\K4YT3X\\AppData\\Local\\video2x\\waifu2x-ncnn-vulkan\\waifu2x-ncnn-vulkan.exe", - "input": null, - "output": null, - "noise-level": 2, - "scale-ratio": null, - "tile-size": 200, - "model-path": null, - "gpu": 0, - "load-proc-save_threads": null, - "verbose": null + "v": null, + "i": null, + "o": null, + "n": 2, + "s": 2, + "t": 400, + "m": "models-cunet", + "g": 0, + "j": "1:2:2" }, "ffmpeg": { "ffmpeg_path": "C:\\Users\\K4YT3X\\AppData\\Local\\video2x\\ffmpeg-latest-win64-static\\bin", diff --git a/bin/waifu2x_ncnn_vulkan.py b/bin/waifu2x_ncnn_vulkan.py index 1620ca6..ca8054e 100644 --- a/bin/waifu2x_ncnn_vulkan.py +++ b/bin/waifu2x_ncnn_vulkan.py @@ -52,28 +52,15 @@ class Waifu2xNcnnVulkan: try: # overwrite config file settings - self.waifu2x_settings['input'] = input_directory - self.waifu2x_settings['output'] = output_directory + self.waifu2x_settings['i'] = input_directory + self.waifu2x_settings['o'] = output_directory + self.waifu2x_settings['s'] = scale_ratio # print thread start message self.print_lock.acquire() Avalon.debug_info(f'[upscaler] Thread {threading.current_thread().name} started') 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 # initialize the list with waifu2x binary path as the first element execute = [str(self.waifu2x_settings['waifu2x_ncnn_vulkan_path'])] @@ -82,41 +69,25 @@ class Waifu2xNcnnVulkan: 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 - - 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: - 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)) 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 self.print_lock.acquire() Avalon.debug_info(f'[upscaler] Thread {threading.current_thread().name} exiting') self.print_lock.release() - return 0 + # return command execution return code + return completed_command.returncode except Exception as e: upscaler_exceptions.append(e)