added multi-threaded additional upscaler
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -17,7 +17,6 @@ import time
|
|||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import itertools
|
|
||||||
|
|
||||||
|
|
||||||
# Loading the config file to get user preferred temp path
|
# Loading the config file to get user preferred temp path
|
||||||
@@ -138,7 +137,7 @@ class Handler:
|
|||||||
if ( not useSpecialModeSS ):
|
if ( not useSpecialModeSS ):
|
||||||
self.superScaler( self.tmppath, threads, quality_setting, self.os_type, model )
|
self.superScaler( self.tmppath, threads, quality_setting, self.os_type, model )
|
||||||
else:
|
else:
|
||||||
self.specialSuperScaler( )
|
self.specialSuperScaler( self.tmppath, threads, quality_setting, model )
|
||||||
else:
|
else:
|
||||||
raise Exception( 'ERROR upscaling. scalerEngine invalid' );
|
raise Exception( 'ERROR upscaling. scalerEngine invalid' );
|
||||||
|
|
||||||
@@ -194,9 +193,62 @@ class Handler:
|
|||||||
os.system( self.command );
|
os.system( self.command );
|
||||||
|
|
||||||
|
|
||||||
def specialSuperScaler ():
|
def specialSuperScaler ( self, tmppath, threads, quality_setting, model ):
|
||||||
|
self.fileList = os.listdir( tmppath )
|
||||||
|
self.fileList.pop( 0 )
|
||||||
|
self.fileList.sort()
|
||||||
|
if ( threads > multiprocessing.cpu_count() * 2 ):
|
||||||
|
self.threads = multiprocessing.cpu_count() * 2;
|
||||||
|
else:
|
||||||
|
self.threads = threads
|
||||||
|
|
||||||
|
self.fileCount = len( self.fileList ) // self.threads
|
||||||
|
self.spareFiles = len( self.fileList ) % self.threads
|
||||||
|
|
||||||
|
self.cmdList = [];
|
||||||
|
|
||||||
|
for t in range( threads ):
|
||||||
|
try:
|
||||||
|
os.mkdir( f'{tmppath}{t}' )
|
||||||
|
except FileExistsError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
self.base = t * self.fileCount;
|
||||||
|
print( self.base );
|
||||||
|
if ( self.os_type == 'win32' ):
|
||||||
|
for j in range( self.fileCount ):
|
||||||
|
os.rename( f'{tmppath}{self.fileList[ self.base + j ] }', f'{tmppath}{ t }\\{self.fileList[ self.base + j ] }' )
|
||||||
|
elif ( self.os_type == 'linux' ):
|
||||||
|
for j in range( self.fileCount ):
|
||||||
|
os.rename( f'{tmppath}{self.fileList[ self.base + j ] }', f'{tmppath}{ t }/{self.fileList[ self.base + j ] }' )
|
||||||
|
|
||||||
|
self.cmdList.append( ( tmppath, t, quality_setting, model, self.os_type ) )
|
||||||
|
|
||||||
|
print( self.threads * self.fileCount );
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.mkdir( f'{tmppath}{self.threads + 1}' )
|
||||||
|
except FileExistsError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if ( self.os_type == 'win32' ):
|
||||||
|
for k in range( self.spareFiles ):
|
||||||
|
os.rename( f'{tmppath}{self.fileList[ self.threads * self.fileCount + k ] }', f'{tmppath}{ t }\\{self.fileList[ self.threads * self.fileCount + k ] }' )
|
||||||
|
elif ( self.os_type == 'linux' ):
|
||||||
|
for k in range( self.spareFiles ):
|
||||||
|
os.rename( f'{tmppath}{self.fileList[ self.threads * self.fileCount + k ] }', f'{tmppath}{ self.threads + 1 }/{self.fileList[ self.threads * self.fileCount + k ] }' )
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.mkdir( f'{tmppath}sc' )
|
||||||
|
except FileExistsError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
self.pool_ss = multiprocessing.Pool( self.threads )
|
||||||
|
self.pool_ss.starmap( specialScalerEngine, self.cmdList );
|
||||||
|
self.pool_ss.close();
|
||||||
|
self.pool_ss.join();
|
||||||
|
|
||||||
|
specialScalerEngine( tmppath, t, quality_setting, model, self.os_type )
|
||||||
|
|
||||||
def fsrScaler ( self, tmppath, filepath, threads, fsrpath, quality_setting, sharpening, scaling, filetype ):
|
def fsrScaler ( self, tmppath, filepath, threads, fsrpath, quality_setting, sharpening, scaling, filetype ):
|
||||||
# Locate Images and assemble FSR-Command
|
# Locate Images and assemble FSR-Command
|
||||||
@@ -306,6 +358,15 @@ class Handler:
|
|||||||
self.pool.join();
|
self.pool.join();
|
||||||
|
|
||||||
|
|
||||||
|
def specialScalerEngine ( tmppath, tNumber, quality_setting, model, os_type ):
|
||||||
|
if ( os_type == 'win32' ):
|
||||||
|
command = f'realesrgan-ncnn-vulkan -i {tmppath}{tNumber} -o {tmppath}sc -s {quality_setting} -n {model}'
|
||||||
|
elif ( os_type == 'linux' ):
|
||||||
|
command = f'wine ./bin/lib/realesrgan-ncnn-vulkan.exe -i {tmppath}{tNumber} -o {tmppath}sc -s {quality_setting} -n {model}'
|
||||||
|
sub = subprocess.Popen( command, shell=True );
|
||||||
|
sub.wait();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def upscalerEngine ( files, fsrpath, quality_setting, number, maxlength, os_type ):
|
def upscalerEngine ( files, fsrpath, quality_setting, number, maxlength, os_type ):
|
||||||
files = files;
|
files = files;
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ if __name__ == '__main__':
|
|||||||
if ( args.model in availableModels ):
|
if ( args.model in availableModels ):
|
||||||
model = args.model;
|
model = args.model;
|
||||||
else:
|
else:
|
||||||
print( 'Invalid argument for model. Can be: realesr-animevideov3 | realesrgan-x4plus | realesrgan-x4plus-anime | realesrnet-x4plus' )
|
print( 'Invalid argument for model. Can be: realesr-animevideov3 | realesrgan-x4plus-anime' )
|
||||||
go2 = False;
|
go2 = False;
|
||||||
|
|
||||||
if ( args.noscaling ):
|
if ( args.noscaling ):
|
||||||
@@ -74,7 +74,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
if ( args.sharpening != None ):
|
if ( args.sharpening != None ):
|
||||||
if ( float( args.sharpening ) > 1 ):
|
if ( float( args.sharpening ) > 1 ):
|
||||||
print( 'Invalid argument for Sharpening, please specify value between 0 and 1!' )
|
print( 'Invalid argument for Sharpening, please specify a value between 0 and 1!' )
|
||||||
go3 = False;
|
go3 = False;
|
||||||
|
|
||||||
if ( args.filetype != None ):
|
if ( args.filetype != None ):
|
||||||
|
|||||||
Reference in New Issue
Block a user