Skip to content

Commit

Permalink
move cugan ncnn to ncnn py
Browse files Browse the repository at this point in the history
  • Loading branch information
TNTwise committed Apr 23, 2024
1 parent 30d835a commit e9a7323
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 10 deletions.
2 changes: 1 addition & 1 deletion modules/CUGAN.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def modelOptions(self):
pass
self.ui.Rife_Model.setEnabled(True)
self.ui.RifeStart.clicked.connect(
lambda: upscale.start_upscale(self, "realcugan-ncnn-vulkan")
lambda: upscale.start_upscale(self, "realcugan-ncnn-python")
)
self.ui.Rife_Times.clear()
self.ui.Rife_Times.currentIndexChanged.connect(self.cuganDenoiseLevel)
Expand Down
22 changes: 22 additions & 0 deletions src/runAI/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,8 @@ def realESRGAN(self):
bool(settings.HalfPrecision),
method=self.main.AI,
threads=int(settings.VRAM),
ncnn_gpu=self.main.ui.gpuIDSpinBox.value(),

)


Expand All @@ -944,6 +946,26 @@ def realESRGAN(self):
bool(settings.HalfPrecision),
method=self.main.AI,
threads=int(settings.VRAM),
ncnn_gpu=self.main.ui.gpuIDSpinBox.value(),
)
if self.main.AI == "realcugan-ncnn-python":
output_file = returnOutputFile(
self.main, self.main.videoName, self.main.encoder
)

#model = os.path.join(f"{settings.ModelDir}","realsr",f"models-{self.main.ui.Rife_Model.currentText()}","x4")

self.main.renderAI = RenderCUDA.Upscaling(
self.main,
self.main.input_file,
output_file,
int(self.main.ui.Rife_Times.currentText()[0]),

half=bool(settings.HalfPrecision),
method=self.main.AI,
threads=int(settings.VRAM),
ncnn_gpu=self.main.ui.gpuIDSpinBox.value(),
cugan_noise=str(self.main.ui.denoiseLevelSpinBox.value())
)

if self.main.AI == "custom-models-ncnn-python":
Expand Down
25 changes: 19 additions & 6 deletions src/torch/RenderCUDA.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
try:
from .rife.rife import *
from .UpscaleImage import UpscaleCUDA
from .UpscaleImageNCNN import UpscaleNCNN

except:
from .UpscaleImageNCNN import UpscaleNCNN
pass
from .UpscaleImageNCNN import UpscaleNCNN, UpscaleCuganNCNN
try:
from src.torch.gmfss.gmfss_fortuna_union import GMFSS
except:
Expand Down Expand Up @@ -299,10 +300,12 @@ def __init__(
input_file,
output_file,
resIncrease,
model_path,
half,
model_path="",
half=True,
method="cuda",
threads=2,
cugan_noise=0,
ncnn_gpu=0
):
super(Upscaling, self).__init__(
main,
Expand All @@ -317,15 +320,25 @@ def __init__(
self.resIncrease = resIncrease
self.threads = threads
self.frame = 0
self.cugan_noise = cugan_noise
self.ncnn_gpu=ncnn_gpu
self.handleModel()
def handleModel(self):
if "cuda" in self.method and "ncnn" not in self.method:
self.upscaleMethod = UpscaleCUDA(
self.originalWidth, self.originalHeight, self.model_path, self.half
)
if "ncnn" in self.method:
if "ncnn" in self.method and not "cugan" in self.method:
self.upscaleMethod = UpscaleNCNN(
model=self.model_path, num_threads=self.threads, scale=self.resIncrease
gpuid=self.ncnn_gpu,model=self.model_path, num_threads=self.threads, scale=self.resIncrease
)
if "cugan" in self.method and "ncnn" in self.method:
self.upscaleMethod = UpscaleCuganNCNN(
gpuid=self.ncnn_gpu,
models_path = os.path.join(f"{thisdir}","models","realcugan","models-se"),
model="models-se",
num_threads=self.threads,
scale=self.resIncrease
)
def procUpscaleThread(self):

Expand Down
17 changes: 14 additions & 3 deletions src/torch/UpscaleImageNCNN.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
import numpy as np
from upscale_ncnn_py import UPSCALE
from realcugan_ncnn_py import Realcugan
import cv2


class UpscaleNCNN:
def __init__(self, model, num_threads, scale):
def __init__(self, model, num_threads, scale, gpuid=0):
self.model = UPSCALE(
gpuid=0, model_str=model, num_threads=num_threads, scale=scale
gpuid=gpuid, model_str=model, num_threads=num_threads, scale=scale
)

def UpscaleImage(self, image):
return self.model.process_cv2(image)


class UpscaleCuganNCNN:
def __init__(self,model="models-se",models_path="",num_threads=2,scale=2, gpuid=0,noise=0):
self.model = Realcugan(gpuid=gpuid,
models_path=models_path,
model=model,
scale=scale,
num_threads=num_threads,
noise=noise)

def UpscaleImage(self,image):
return self.model.process_cv2(image)
if __name__ == "__main__":
from PIL import Image
import matplotlib.pyplot as plt
Expand Down
Binary file modified src/torch/__pycache__/RenderCUDA.cpython-311.pyc
Binary file not shown.

0 comments on commit e9a7323

Please sign in to comment.