update waifu2x_ncnn_vulkan to new options

This commit is contained in:
sat3ll 2019-07-10 01:26:53 +01:00
parent 8b845e35b3
commit eda5d70773
3 changed files with 56 additions and 30 deletions

View File

@ -40,12 +40,14 @@
"input": null "input": null
}, },
"waifu2x_ncnn_vulkan": { "waifu2x_ncnn_vulkan": {
"waifu2x_ncnn_vulkan_path": "C:\\Users\\K4YT3X\\AppData\\Local\\video2x\\waifu2x-ncnn-vulkan\\waifu2x.exe", "waifu2x_ncnn_vulkan_path": "C:\\Users\\K4YT3X\\AppData\\Local\\video2x\\waifu2x-ncnn-vulkan\\waifu2x-ncnn-vulkan.exe",
"input": null, "input": null,
"output": null, "output": null,
"noise-level": 2, "noise-level": 2,
"scale-ratio": null, "scale-ratio": null,
"block-size": 400 "tile-size": 400,
"model-path": null,
"gpu": 0
}, },
"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

@ -196,15 +196,13 @@ class Video2xSetup:
if self.driver == 'all': if self.driver == 'all':
template_dict['waifu2x_caffe']['waifu2x_caffe_path'] = os.path.join(local_app_data, 'video2x', 'waifu2x-caffe', 'waifu2x-caffe-cui.exe') template_dict['waifu2x_caffe']['waifu2x_caffe_path'] = os.path.join(local_app_data, 'video2x', 'waifu2x-caffe', 'waifu2x-caffe-cui.exe')
template_dict['waifu2x_converter']['waifu2x_converter_path'] = os.path.join(local_app_data, 'video2x', 'waifu2x-converter-cpp') template_dict['waifu2x_converter']['waifu2x_converter_path'] = os.path.join(local_app_data, 'video2x', 'waifu2x-converter-cpp')
# TODO: after version 20190611 executable changes to waifu2x-ncnn-vulkan so rename this when it breaks template_dict['waifu2x_ncnn_vulkan']['waifu2x_ncnn_vulkan_path'] = os.path.join(local_app_data, 'video2x', 'waifu2x-ncnn-vulkan', 'waifu2x-ncnn-vulkan.exe')
template_dict['waifu2x_ncnn_vulkan']['waifu2x_ncnn_vulkan_path'] = os.path.join(local_app_data, 'video2x', 'waifu2x-ncnn-vulkan', 'waifu2x.exe')
elif self.driver == 'waifu2x_caffe': elif self.driver == 'waifu2x_caffe':
template_dict['waifu2x_caffe']['waifu2x_caffe_path'] = os.path.join(local_app_data, 'video2x', 'waifu2x-caffe', 'waifu2x-caffe-cui.exe') template_dict['waifu2x_caffe']['waifu2x_caffe_path'] = os.path.join(local_app_data, 'video2x', 'waifu2x-caffe', 'waifu2x-caffe-cui.exe')
elif self.driver == 'waifu2x_converter': elif self.driver == 'waifu2x_converter':
template_dict['waifu2x_converter']['waifu2x_converter_path'] = os.path.join(local_app_data, 'video2x', 'waifu2x-converter-cpp') template_dict['waifu2x_converter']['waifu2x_converter_path'] = os.path.join(local_app_data, 'video2x', 'waifu2x-converter-cpp')
elif self.driver == 'waifu2x_ncnn_vulkan': elif self.driver == 'waifu2x_ncnn_vulkan':
# TODO: after version 20190611 executable changes to waifu2x-ncnn-vulkan so rename this when it breaks template_dict['waifu2x_ncnn_vulkan']['waifu2x_ncnn_vulkan_path'] = os.path.join(local_app_data, 'video2x', 'waifu2x-ncnn-vulkan', 'waifu2x-ncnn-vulkan.exe')
template_dict['waifu2x_ncnn_vulkan']['waifu2x_ncnn_vulkan_path'] = os.path.join(local_app_data, 'video2x', 'waifu2x-ncnn-vulkan', 'waifu2x.exe')
template_dict['ffmpeg']['ffmpeg_path'] = os.path.join(local_app_data, 'video2x', 'ffmpeg-latest-win64-static', 'bin') template_dict['ffmpeg']['ffmpeg_path'] = os.path.join(local_app_data, 'video2x', 'ffmpeg-latest-win64-static', 'bin')
template_dict['video2x']['video2x_cache_directory'] = None template_dict['video2x']['video2x_cache_directory'] = None

View File

@ -50,47 +50,73 @@ class Waifu2xNcnnVulkan:
try: try:
# overwrite config file settings # overwrite config file settings
self.waifu2x_settings['input_path'] = input_directory self.waifu2x_settings['input'] = input_directory
self.waifu2x_settings['output_path'] = output_directory self.waifu2x_settings['output'] = output_directory
# 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 accepts arguments in a positional manner # waifu2x_ncnn_vulkan does not have long-opts, we'll have a dictionary that maps "our" config long-opt
# See: https://github.com/nihui/waifu2x_ncnn_vulkan#usage # names to their short opts
# waifu2x_ncnn_vulkan.exe [input image] [output png] [noise=-1/0/1/2/3] [scale=1/2] [blocksize=400] waifu2x_ncnn_vulkan_opt_flag = {
# noise = noise level, large value means strong denoise effect, -1=no effect 'input': '-i',
# scale = scale level, 1=no scale, 2=upscale 2x 'output': '-o',
# blocksize = tile size, use smaller value to reduce GPU memory usage, default is 400 'noise-level': '-n',
'scale-ratio': '-s',
'tile-size': '-t',
'model-path': '-m',
'gpu': '-g'
}
# waifu2x_ncnn_vulkan does not accept an arbitrary scale ratio, max is 2 # waifu2x_ncnn_vulkan does not accept an arbitrary scale ratio, max is 2
if scale_ratio == 1: if scale_ratio == 1:
for raw_frame in os.listdir(input_directory): for raw_frame in os.listdir(input_directory):
command = [
os.path.join(input_directory, raw_frame),
os.path.join(output_directory, raw_frame),
str(self.waifu2x_settings['noise-level']),
'1',
str(self.waifu2x_settings['block-size'])
]
execute = [self.waifu2x_settings['waifu2x_ncnn_vulkan_path']] execute = [self.waifu2x_settings['waifu2x_ncnn_vulkan_path']]
execute.extend(command) 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('1')
# 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])
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)
else: else:
for raw_frame in os.listdir(input_directory): for raw_frame in os.listdir(input_directory):
command = [
os.path.join(input_directory, raw_frame),
os.path.join(output_directory, raw_frame),
str(self.waifu2x_settings['noise-level']),
'2',
str(self.waifu2x_settings['block-size'])
]
execute = [self.waifu2x_settings['waifu2x_ncnn_vulkan_path']] execute = [self.waifu2x_settings['waifu2x_ncnn_vulkan_path']]
execute.extend(command) 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')
elif value is None or value is False:
continue
else:
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)