Skip to content

Commit

Permalink
Fixed ncnn-only models not working with esrgan-ncnn
Browse files Browse the repository at this point in the history
  • Loading branch information
n00mkrad committed Aug 22, 2021
1 parent 7a191d8 commit 1b305e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions Code/OS/NcnnUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static async Task ConvertNcnnModel(string modelPath, string filenamePatte
{
if (IsDirNcnnModel(modelPath))
{
ApplyFilenamePattern(modelPath, filenamePattern);
currentNcnnModel = modelPath;
return;
}
Expand Down Expand Up @@ -60,9 +61,7 @@ public static async Task ConvertNcnnModel(string modelPath, string filenamePatte
Logger.Log("NCNN Model is cached - Skipping conversion.");
}

foreach(FileInfo file in IoUtils.GetFileInfosSorted(outPath).Where(f => f.Extension == ".bin" || f.Extension == ".param"))
IoUtils.RenameFile(file.FullName, filenamePattern.Replace("*", $"{file.Name.GetInt()}"));

ApplyFilenamePattern(outPath, filenamePattern);
currentNcnnModel = outPath;
}
catch (Exception e)
Expand All @@ -71,6 +70,12 @@ public static async Task ConvertNcnnModel(string modelPath, string filenamePatte
}
}

static void ApplyFilenamePattern(string path, string pattern)
{
foreach (FileInfo file in IoUtils.GetFileInfosSorted(path).Where(f => f.Extension == ".bin" || f.Extension == ".param"))
IoUtils.RenameFile(file.FullName, pattern.Replace("*", $"{file.Name.GetInt()}"));
}

static async Task RunConverter(string modelPath)
{
lastNcnnOutput = "";
Expand Down
2 changes: 1 addition & 1 deletion Code/UI/PreviewUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static async Task UpscaleImage()

try
{
await Upscale.Run(Paths.imgInPath, Paths.imgOutPath, mdl, false, Config.GetBool("alpha"), PreviewUi.PreviewMode.None);
await Upscale.Run(Paths.imgInPath, Paths.imgOutPath, mdl, false, Config.GetBool("alpha"), PreviewMode.None);
if (Program.canceled) return;
outImg = Upscale.GetOutputImg();
Program.mainForm.SetProgress(100f, "Post-Processing...");
Expand Down

0 comments on commit 1b305e5

Please sign in to comment.