Skip to content

Commit

Permalink
Cache tile size for video upscaling (joey's)
Browse files Browse the repository at this point in the history
  • Loading branch information
N00MKRAD committed Dec 16, 2020
1 parent e261cb2 commit 7500ee4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions Code/Main/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ private async void upscaleBtn_Click(object sender, EventArgs e)
if (Config.GetBool("reloadImageBeforeUpscale"))
ReloadImage();
UpdateResizeMode();
ESRGAN.cacheTiling = (htTabControl.SelectedIndex == 2);
if (htTabControl.SelectedIndex == 0) await PreviewUI.UpscaleImage();
if (htTabControl.SelectedIndex == 1) await BatchUpscaleUI.Run(preprocessMode.SelectedIndex == 0);
if (htTabControl.SelectedIndex == 2) await VideoUpscaleUI.Run(videoPreprocessMode.SelectedIndex == 0);
Expand Down
10 changes: 6 additions & 4 deletions Code/OS/ESRGAN.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ namespace Cupscale.OS
internal class ESRGAN
{
public enum PreviewMode { None, Cutout, FullImage }
public enum Backend { CUDA, CPU, NCNN }
public enum Backend { CUDA, CPU, NCNN };
public static bool cacheTiling = false;

public static async Task DoUpscale(string inpath, string outpath, ModelData mdl, string tilesize, bool alpha, PreviewMode mode, Backend backend, bool showTileProgress = true)
{
Expand Down Expand Up @@ -198,8 +199,7 @@ public static async Task RunJoey(string inpath, string outpath, string modelArg,

string alphaStr = alpha ? $"--alpha_mode {Config.GetInt("joeyAlphaMode")}" : "--alpha_mode 0";

string deviceStr = "";
if (Config.Get("cudaFallback").GetInt() == 1 || Config.Get("cudaFallback").GetInt() == 2) deviceStr = "--cpu";
string deviceStr = (Config.Get("cudaFallback").GetInt() == 1 || Config.Get("cudaFallback").GetInt() == 2) ? "--cpu" : "";

string seamStr = "--seamless ";
switch (Config.Get("seamlessMode").GetInt())
Expand All @@ -210,10 +210,12 @@ public static async Task RunJoey(string inpath, string outpath, string modelArg,
case 4: seamStr += "alpha_pad"; break;
}

string cacheStr = cacheTiling ? "--cache_max_split_depth" : "";

string opt = stayOpen ? "/K" : "/C";

string cmd = $"{opt} cd /D {Paths.esrganPath.Wrap()} & ";
cmd += $"{EmbeddedPython.GetPyCmd()} upscale.py --input {inpath} --output {outpath} {deviceStr} {seamStr} {alphaStr} {modelArg}".TrimWhitespaces();
cmd += $"{EmbeddedPython.GetPyCmd()} upscale.py --input {inpath} --output {outpath} {cacheStr} {deviceStr} {seamStr} {alphaStr} {modelArg}".TrimWhitespaces();

Logger.Log("[CMD] " + cmd);
Process esrganProcess = OSUtils.NewProcess(!showWindow);
Expand Down

0 comments on commit 7500ee4

Please sign in to comment.