diff --git a/bin/upscaler.py b/bin/upscaler.py index a02af87..fe72569 100644 --- a/bin/upscaler.py +++ b/bin/upscaler.py @@ -150,7 +150,8 @@ class Upscaler: self.upscaler_exceptions = [] # initialize waifu2x driver - if self.waifu2x_driver != 'waifu2x_caffe' and self.waifu2x_driver != 'waifu2x_converter' and self.waifu2x_driver != 'waifu2x-ncnn-vulkan': + drivers = ['waifu2x_caffe', 'waifu2x_converter', 'waifu2x_ncnn_vulkan'] + if self.waifu2x_driver not in drivers: raise Exception(f'Unrecognized waifu2x driver: {self.waifu2x_driver}') # it's easier to do multi-threading with waifu2x_converter @@ -247,7 +248,7 @@ class Upscaler: if len(self.upscaler_exceptions) != 0: raise(self.upscaler_exceptions[0]) - elif self.waifu2x_driver == 'waifu2x-ncnn-vulkan': + elif self.waifu2x_driver == 'waifu2x_ncnn_vulkan': # create a container for all upscaler threads upscaler_threads = [] diff --git a/bin/video2x.json b/bin/video2x.json index 5a048ff..219d2d6 100644 --- a/bin/video2x.json +++ b/bin/video2x.json @@ -39,8 +39,8 @@ "output": null, "input": null }, - "waifu2x-ncnn-vulkan": { - "waifu2x-ncnn-vulkan_path": "C:\\Users\\kobalt\\AppData\\Local\\video2x\\waifu2x-ncnn-vulkan\\waifu2x.exe", + "waifu2x_ncnn_vulkan": { + "waifu2x_ncnn_vulkan_path": "C:\\Users\\kobalt\\AppData\\Local\\video2x\\waifu2x-ncnn-vulkan\\waifu2x.exe", "block-size": 400, "scale-ratio": null, "noise-level": 2, diff --git a/bin/video2x.py b/bin/video2x.py index dcb42ee..c6b138c 100644 --- a/bin/video2x.py +++ b/bin/video2x.py @@ -82,7 +82,7 @@ def process_arguments(): # upscaler options upscaler_options = parser.add_argument_group('Upscaler Options') upscaler_options.add_argument('-m', '--method', help='upscaling method', action='store', default='gpu', choices=['cpu', 'gpu', 'cudnn']) - upscaler_options.add_argument('-d', '--driver', help='waifu2x driver', action='store', default='waifu2x_caffe', choices=['waifu2x_caffe', 'waifu2x_converter', 'waifu2x-ncnn-vulkan']) + upscaler_options.add_argument('-d', '--driver', help='waifu2x driver', action='store', default='waifu2x_caffe', choices=['waifu2x_caffe', 'waifu2x_converter', 'waifu2x_ncnn_vulkan']) upscaler_options.add_argument('-y', '--model_dir', help='directory containing model JSON files', action='store') upscaler_options.add_argument('-t', '--threads', help='number of threads to use for upscaling', action='store', type=int, default=1) upscaler_options.add_argument('-c', '--config', help='video2x config file location', action='store', default=os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), 'video2x.json')) @@ -203,9 +203,9 @@ def absolutify_paths(config): if not re.match('^[a-z]:', config['waifu2x_converter']['waifu2x_converter_path'], re.IGNORECASE): config['waifu2x_converter']['waifu2x_converter_path'] = os.path.join(current_directory, config['waifu2x_converter']['waifu2x_converter_path']) - # check waifu2x-ncnn-vulkan path - if not re.match('^[a-z]:', config['waifu2x-ncnn-vulkan']['waifu2x-ncnn-vulkan_path'], re.IGNORECASE): - config['waifu2x-ncnn-vulkan']['waifu2x-ncnn-vulkan_path'] = os.path.join(current_directory, config['waifu2x-ncnn-vulkan']['waifu2x-ncnn-vulkan_path']) + # check waifu2x_ncnn_vulkan path + if not re.match('^[a-z]:', config['waifu2x_ncnn_vulkan']['waifu2x_ncnn_vulkan_path'], re.IGNORECASE): + config['waifu2x_ncnn_vulkan']['waifu2x_ncnn_vulkan_path'] = os.path.join(current_directory, config['waifu2x_ncnn_vulkan']['waifu2x_ncnn_vulkan_path']) # check ffmpeg path if not re.match('^[a-z]:', config['ffmpeg']['ffmpeg_path'], re.IGNORECASE): @@ -248,11 +248,11 @@ if not args.input: if not args.output: Avalon.error('You must specify output video file/directory path') exit(1) -if (args.driver == 'waifu2x_converter' or args.driver == 'waifu2x-ncnn-vulkan') and args.width and args.height: - Avalon.error('Waifu2x Converter CPP / waifu2x-ncnn-vulkan accepts only scaling ratio') +if (args.driver == 'waifu2x_converter' or args.driver == 'waifu2x_ncnn_vulkan') and args.width and args.height: + Avalon.error('Waifu2x Converter CPP / waifu2x_ncnn_vulkan accepts only scaling ratio') exit(1) -if args.driver == 'waifu2x-ncnn-vulkan' and (args.ratio > 2 or not args.ratio.is_integer()): - Avalon.error('scale ratio must be 2 or 1 for waifu2x-ncnn-vulkan') +if args.driver == 'waifu2x_ncnn_vulkan' and (args.ratio > 2 or not args.ratio.is_integer()): + Avalon.error('scale ratio must be 2 or 1 for waifu2x_ncnn_vulkan') exit(1) if (args.width or args.height) and args.ratio: Avalon.error('You can only specify either scaling ratio or output width and height') @@ -281,12 +281,12 @@ elif args.driver == 'waifu2x_converter': Avalon.error('Specified waifu2x-converter-cpp directory doesn\'t exist') Avalon.error('Please check the configuration file settings') raise FileNotFoundError(waifu2x_settings['waifu2x_converter_path']) -elif args.driver == 'waifu2x-ncnn-vulkan': - waifu2x_settings = config['waifu2x-ncnn-vulkan'] - if not os.path.isfile(waifu2x_settings['waifu2x-ncnn-vulkan_path']): - Avalon.error('Specified waifu2x-ncnn-vulkan directory doesn\'t exist') +elif args.driver == 'waifu2x_ncnn_vulkan': + waifu2x_settings = config['waifu2x_ncnn_vulkan'] + if not os.path.isfile(waifu2x_settings['waifu2x_ncnn_vulkan_path']): + Avalon.error('Specified waifu2x_ncnn_vulkan directory doesn\'t exist') Avalon.error('Please check the configuration file settings') - raise FileNotFoundError(waifu2x_settings['waifu2x-ncnn-vulkan_path']) + raise FileNotFoundError(waifu2x_settings['waifu2x_ncnn_vulkan_path']) # read FFmpeg configuration ffmpeg_settings = config['ffmpeg'] diff --git a/bin/video2x_setup.py b/bin/video2x_setup.py index eb20638..bec061e 100644 --- a/bin/video2x_setup.py +++ b/bin/video2x_setup.py @@ -23,7 +23,7 @@ Installation Details: - ffmpeg: %LOCALAPPDATA%\\video2x\\ffmpeg - waifu2x-caffe: %LOCALAPPDATA%\\video2x\\waifu2x-caffe - waifu2x-cpp-converter: %LOCALAPPDATA%\\video2x\\waifu2x-converter-cpp -- waifu2x-ncnn-vulkan: %LOCALAPPDATA%\\video2x\\waifu2x-ncnn-vulkan +- waifu2x_ncnn_vulkan: %LOCALAPPDATA%\\video2x\\waifu2x-ncnn-vulkan """ import argparse @@ -50,7 +50,7 @@ def process_arguments(): # video options general_options = parser.add_argument_group('General Options') - general_options.add_argument('-d', '--driver', help='driver to download and configure', action='store', choices=['all', 'waifu2x_caffe', 'waifu2x_converter', 'waifu2x-ncnn-vulkan'], default='all') + general_options.add_argument('-d', '--driver', help='driver to download and configure', action='store', choices=['all', 'waifu2x_caffe', 'waifu2x_converter', 'waifu2x_ncnn_vulkan'], default='all') # parse arguments return parser.parse_args() @@ -84,7 +84,7 @@ class Video2xSetup: self._install_waifu2x_caffe() elif self.driver == 'waifu2x_converter': self._install_waifu2x_converter_cpp() - elif self.driver == 'waifu2x-ncnn-vulkan': + elif self.driver == 'waifu2x_ncnn_vulkan': self._install_waifu2x_ncnn_vulkan() print('\nGenerating Video2X configuration file') @@ -197,14 +197,14 @@ class Video2xSetup: 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') # 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.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': 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': 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.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['video2x']['video2x_cache_directory'] = None diff --git a/bin/waifu2x_ncnn_vulkan.py b/bin/waifu2x_ncnn_vulkan.py index 1e8555e..888e0ce 100644 --- a/bin/waifu2x_ncnn_vulkan.py +++ b/bin/waifu2x_ncnn_vulkan.py @@ -7,7 +7,7 @@ Name: Waifu2x NCNN Vulkan Driver Author: K4YT3X, SAT3LL Description: This class is a high-level wrapper -for waifu2x-ncnn-vulkan. +for waifu2x_ncnn_vulkan. """ from avalon_framework import Avalon import subprocess @@ -28,9 +28,9 @@ class Waifu2xNcnnVulkan: # arguments passed through command line overwrites config file values - # waifu2x-ncnn-vulkan can't find its own model directory if its not in the current dir + # waifu2x_ncnn_vulkan can't find its own model directory if its not in the current dir # so change to it - os.chdir(os.path.join(self.waifu2x_settings['waifu2x-ncnn-vulkan_path'], '..')) + os.chdir(os.path.join(self.waifu2x_settings['waifu2x_ncnn_vulkan_path'], '..')) self.print_lock = threading.Lock() @@ -53,14 +53,14 @@ class Waifu2xNcnnVulkan: Avalon.debug_info(f'[upscaler] Thread {threading.current_thread().name} started') self.print_lock.release() - # waifu2x-ncnn-vulkan accepts arguments in a positional manner - # See: https://github.com/nihui/waifu2x-ncnn-vulkan#usage - # waifu2x-ncnn-vulkan.exe [input image] [output png] [noise=-1/0/1/2/3] [scale=1/2] [blocksize=400] + # waifu2x_ncnn_vulkan accepts arguments in a positional manner + # See: https://github.com/nihui/waifu2x_ncnn_vulkan#usage + # waifu2x_ncnn_vulkan.exe [input image] [output png] [noise=-1/0/1/2/3] [scale=1/2] [blocksize=400] # noise = noise level, large value means strong denoise effect, -1=no effect # scale = scale level, 1=no scale, 2=upscale 2x # blocksize = tile size, use smaller value to reduce GPU memory usage, default is 400 - # 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: for raw_frame in os.listdir(input_directory): command = [ @@ -70,7 +70,7 @@ class Waifu2xNcnnVulkan: '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) Avalon.debug_info(f'Executing: {execute}') @@ -84,7 +84,7 @@ class Waifu2xNcnnVulkan: '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) Avalon.debug_info(f'Executing: {execute}')