mirror of
https://github.com/k4yt3x/video2x.git
synced 2026-05-18 09:17:31 +08:00
2.6.0 complete redesign of configuration file, with lots of enhancements
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
Name: Waifu2x Caffe Driver
|
||||
Author: K4YT3X
|
||||
Date Created: Feb 24, 2018
|
||||
Last Modified: March 4, 2019
|
||||
Last Modified: March 9, 2019
|
||||
|
||||
Description: This class controls waifu2x
|
||||
engine
|
||||
@@ -23,33 +23,70 @@ class Waifu2xCaffe:
|
||||
the upscale function.
|
||||
"""
|
||||
|
||||
def __init__(self, waifu2x_path, method, model_type):
|
||||
self.waifu2x_path = waifu2x_path
|
||||
self.method = method
|
||||
self.model_type = model_type
|
||||
def __init__(self, waifu2x_settings, process, model_dir):
|
||||
self.waifu2x_settings = waifu2x_settings
|
||||
self.waifu2x_settings['process'] = process
|
||||
self.waifu2x_settings['model_dir'] = model_dir
|
||||
|
||||
# arguments passed through command line overwrites config file values
|
||||
self.process = process
|
||||
self.model_dir = model_dir
|
||||
self.print_lock = threading.Lock()
|
||||
|
||||
def upscale(self, folderin, folderout, width, height):
|
||||
def upscale(self, input_folder, output_folder, scale_ratio, scale_width, scale_height):
|
||||
"""This is the core function for WAIFU2X class
|
||||
|
||||
Arguments:
|
||||
folderin {string} -- source folder path
|
||||
folderout {string} -- output folder path
|
||||
input_folder {string} -- source folder path
|
||||
output_folder {string} -- output folder path
|
||||
width {int} -- output video width
|
||||
height {int} -- output video height
|
||||
"""
|
||||
|
||||
# overwrite config file settings
|
||||
self.waifu2x_settings['input_path'] = input_folder
|
||||
self.waifu2x_settings['output_path'] = output_folder
|
||||
|
||||
if scale_ratio:
|
||||
self.waifu2x_settings['scale_ratio'] = scale_ratio
|
||||
elif scale_width and scale_height:
|
||||
self.waifu2x_settings['scale_width'] = scale_width
|
||||
self.waifu2x_settings['scale_height'] = scale_height
|
||||
|
||||
# Print thread start message
|
||||
self.print_lock.acquire()
|
||||
Avalon.debug_info('[upscaler] Thread {} started'.format(threading.current_thread().name))
|
||||
self.print_lock.release()
|
||||
|
||||
"""
|
||||
# Create string for execution
|
||||
# execute = ['{}'.format(self.waifu2x_path), '-p', self.method, '-I', 'png', '-i', '\"{}\"'.format(folderin), '-e', 'png', '-o', folderout, '-w', str(width), '-h', str(height), '-n', '3', '-m', 'noise_scale', '-y', self.model_type]
|
||||
execute = '\"{}\" -p {} -I png -i \"{}\" -e png -o {} -w {} -h {} -n 3 -m noise_scale -y {}'.format(
|
||||
self.waifu2x_path, self.method, folderin, folderout, width, height, self.model_type)
|
||||
print('Executing: {}'.format(execute))
|
||||
subprocess.run(execute, shell=True, check=True)
|
||||
self.waifu2x_path, self.process, input_folder, output_folder, width, height, self.model_dir)
|
||||
"""
|
||||
|
||||
execute = []
|
||||
|
||||
for key in self.waifu2x_settings.keys():
|
||||
|
||||
value = self.waifu2x_settings[key]
|
||||
|
||||
# The key doesn't need to be passed in this case
|
||||
if key == 'waifu2x_caffe_path':
|
||||
execute.append(str(value))
|
||||
|
||||
# Null or None means that leave this option out (keep default)
|
||||
elif value is None or value is False:
|
||||
continue
|
||||
|
||||
else:
|
||||
if len(key) == 1:
|
||||
execute.append('-{}'.format(key))
|
||||
else:
|
||||
execute.append('--{}'.format(key))
|
||||
execute.append(str(value))
|
||||
|
||||
Avalon.debug_info('Executing: {}'.format(execute))
|
||||
subprocess.run(execute, check=True)
|
||||
|
||||
# Print thread exiting message
|
||||
self.print_lock.acquire()
|
||||
|
||||
Reference in New Issue
Block a user