4.0.0 new argument parsing mechanism and project structure

This commit is contained in:
k4yt3x
2020-05-04 17:12:41 -04:00
parent 88299d404a
commit 89860f22cb
7 changed files with 223 additions and 107 deletions

View File

@@ -4,13 +4,14 @@
Name: SRMD NCNN Vulkan Driver
Creator: K4YT3X
Date Created: April 26, 2020
Last Modified: April 26, 2020
Last Modified: May 4, 2020
Description: This class is a high-level wrapper
for srmd_ncnn_vulkan.
"""
# built-in imports
import argparse
import os
import shlex
import subprocess
@@ -20,7 +21,7 @@ import threading
from avalon_framework import Avalon
class SrmdNcnnVulkan:
class WrapperMain:
"""This class communicates with SRMD NCNN Vulkan engine
An object will be created for this class, containing information
@@ -40,6 +41,22 @@ class SrmdNcnnVulkan:
self.print_lock = threading.Lock()
@staticmethod
def parse_arguments(arguments):
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, add_help=False)
parser.add_argument('--help', action='help', help='show this help message and exit')
parser.add_argument('-v', action='store_true', help='verbose output')
# parser.add_argument('-i', type=pathlib.Path, help='input image path (jpg/png) or directory')
# parser.add_argument('-o', type=pathlib.Path, help='output image path (png) or directory')
parser.add_argument('-n', type=int, choices=range(-1, 11), help='denoise level')
parser.add_argument('-s', type=int, choices=range(2, 5), help='upscale ratio')
parser.add_argument('-t', type=int, help='tile size (>=32)')
parser.add_argument('-m', type=str, help='srmd model path')
parser.add_argument('-g', type=int, help='gpu device to use')
parser.add_argument('-j', type=str, help='thread count for load/proc/save')
parser.add_argument('-x', action='store_true', help='enable tta mode')
return parser.parse_args(arguments)
def upscale(self, input_directory, output_directory, scale_ratio):
"""This is the core function for SRMD ncnn Vulkan class
@@ -52,7 +69,7 @@ class SrmdNcnnVulkan:
# overwrite config file settings
self.driver_settings['i'] = input_directory
self.driver_settings['o'] = output_directory
self.driver_settings['s'] = int(scale_ratio)
self.driver_settings['s'] = scale_ratio
# list to be executed
# initialize the list with the binary path as the first element
@@ -62,15 +79,18 @@ class SrmdNcnnVulkan:
value = self.driver_settings[key]
# is executable key or null or None means that leave this option out (keep default)
if key == 'path' or value is None or value is False:
# null or None means that leave this option out (keep default)
if value is None or value is False:
continue
else:
if len(key) == 1:
execute.append(f'-{key}')
else:
execute.append(f'--{key}')
execute.append(str(value))
# true means key is an option
if value is not True:
execute.append(str(value))
# return the Popen object of the new process created
self.print_lock.acquire()