deduplicate code

This commit is contained in:
sat3ll 2019-07-10 01:34:56 +01:00
parent eda5d70773
commit 5a2b387b9d

View File

@ -70,56 +70,34 @@ class Waifu2xNcnnVulkan:
'gpu': '-g' 'gpu': '-g'
} }
# waifu2x_ncnn_vulkan does not accept an arbitrary scale ratio, max is 2 for raw_frame in os.listdir(input_directory):
if scale_ratio == 1: execute = [self.waifu2x_settings['waifu2x_ncnn_vulkan_path']]
for raw_frame in os.listdir(input_directory): for key in self.waifu2x_settings.keys():
execute = [self.waifu2x_settings['waifu2x_ncnn_vulkan_path']] value = self.waifu2x_settings[key]
for key in self.waifu2x_settings.keys(): if key == 'waifu2x_ncnn_vulkan_path':
value = self.waifu2x_settings[key] continue
if key == 'waifu2x_ncnn_vulkan_path': elif key == 'input':
continue execute.append(waifu2x_ncnn_vulkan_opt_flag[key])
elif key == 'input': execute.append(os.path.join(input_directory, raw_frame))
execute.append(waifu2x_ncnn_vulkan_opt_flag[key]) elif key == 'output':
execute.append(os.path.join(input_directory, raw_frame)) execute.append(waifu2x_ncnn_vulkan_opt_flag[key])
elif key == 'output': execute.append(os.path.join(output_directory, raw_frame))
execute.append(waifu2x_ncnn_vulkan_opt_flag[key]) elif key == 'scale-ratio':
execute.append(os.path.join(output_directory, raw_frame)) execute.append(waifu2x_ncnn_vulkan_opt_flag[key])
elif key == 'scale-ratio': # waifu2x_ncnn_vulkan does not accept an arbitrary scale ratio, max is 2
execute.append(waifu2x_ncnn_vulkan_opt_flag[key]) if scale_ratio == 1:
execute.append('1') execute.append('1')
# 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])
execute.append(str(value))
Avalon.debug_info(f'Executing: {execute}')
subprocess.run(execute, check=True, stderr=subprocess.DEVNULL)
else:
for raw_frame in os.listdir(input_directory):
execute = [self.waifu2x_settings['waifu2x_ncnn_vulkan_path']]
for key in self.waifu2x_settings.keys():
value = self.waifu2x_settings[key]
if key == 'waifu2x_ncnn_vulkan_path':
continue
elif key == 'input':
execute.append(waifu2x_ncnn_vulkan_opt_flag[key])
execute.append(os.path.join(input_directory, raw_frame))
elif key == 'output':
execute.append(waifu2x_ncnn_vulkan_opt_flag[key])
execute.append(os.path.join(output_directory, raw_frame))
elif key == 'scale-ratio':
execute.append(waifu2x_ncnn_vulkan_opt_flag[key])
execute.append('2') execute.append('2')
elif value is None or value is False: # allow upper if cases to take precedence
continue elif value is None or value is False:
else: continue
execute.append(waifu2x_ncnn_vulkan_opt_flag[key]) else:
execute.append(str(value)) execute.append(waifu2x_ncnn_vulkan_opt_flag[key])
execute.append(str(value))
Avalon.debug_info(f'Executing: {execute}') Avalon.debug_info(f'Executing: {execute}')
subprocess.run(execute, check=True, stderr=subprocess.DEVNULL) subprocess.run(execute, check=True, stderr=subprocess.DEVNULL)
# print thread exiting message # print thread exiting message
self.print_lock.acquire() self.print_lock.acquire()