Ejemplo n.º 1
0
        public static async Task ConvertNcnnModel(string modelPath)
        {
            string modelName = Path.GetFileName(modelPath);

            ncnnDir = Path.Combine(Config.Get("modelPath"), ".ncnn");
            Directory.CreateDirectory(ncnnDir);
            string outPath = Path.Combine(ncnnDir, Path.ChangeExtension(modelName, null));

            Logger.Log("Checking for NCNN model: " + outPath);
            if (IOUtils.GetAmountOfFiles(outPath, false) < 2)
            {
                Logger.Log("Running model converter...");
                DialogForm dialog = new DialogForm("Converting ESRGAN model to NCNN format...");
                await RunConverter(modelPath);

                string moveFrom = Path.Combine(Config.Get("esrganPath"), Path.ChangeExtension(modelName, null));
                Logger.Log("Moving " + moveFrom + " to " + outPath);
                await IOUtils.CopyDir(moveFrom, outPath, "*", true);

                Directory.Delete(moveFrom, true);
                dialog.Close();
            }
            else
            {
                Logger.Log("NCNN Model is cached - Skipping conversion.");
            }
            ESRGAN.currentNcnnModel = outPath;
        }
Ejemplo n.º 2
0
        public static async Task Init()
        {
            if (!IsEnabled())
            {
                return;
            }
            string shippedPath = Installer.path;

            IOUtils.TryDeleteIfExists(Path.Combine(shippedPath, "py", "utils"));
            await IOUtils.CopyDir(Path.Combine(shippedPath, "utils"), Path.Combine(shippedPath, "py", "utils"));
        }
Ejemplo n.º 3
0
        public static async Task Init()
        {
            if (!IsEnabled())
            {
                return;
            }
            string shippedPath = Installer.path;

            IOUtils.TryDeleteIfExists(Path.Combine(shippedPath, "py", "utils"));
            await IOUtils.CopyDir(Path.Combine(shippedPath, "utils"), Path.Combine(shippedPath, "py", "utils"));

            File.Copy(Path.Combine(shippedPath, "esrlupscale.py"), Path.Combine(shippedPath, "py", "esrlupscale.py"), true);
            File.Copy(Path.Combine(shippedPath, "esrlmodel.py"), Path.Combine(shippedPath, "py", "esrlmodel.py"), true);
            File.Copy(Path.Combine(shippedPath, "esrlrrdbnet.py"), Path.Combine(shippedPath, "py", "esrlrrdbnet.py"), true);
        }
Ejemplo n.º 4
0
        public static async Task CopyImagesTo(string path)
        {
            Program.lastOutputDir = path;
            Program.mainForm.AfterFirstUpscale();
            if (overwriteMode == Overwrite.Yes)
            {
                Logger.Log("Overwrite mode - removing suffix from filenames");
                IOUtils.ReplaceInFilenamesDir(Paths.imgOutPath, "-" + GetLastModelName(), "");
            }
            else
            {
                Logger.Log("Overwrite is off - keeping suffix.");
            }
            await IOUtils.CopyDir(Paths.imgOutPath, path);

            await Task.Delay(1);

            IOUtils.ClearDir(Paths.imgInPath);
            IOUtils.ClearDir(Paths.imgOutPath);
        }
Ejemplo n.º 5
0
        public static async Task ConvertNcnnModel(string modelPath)
        {
            try
            {
                string modelName = Path.GetFileName(modelPath);
                ncnnDir = Path.Combine(Config.Get("modelPath"), ".ncnn");
                Directory.CreateDirectory(ncnnDir);
                string outPath = Path.Combine(ncnnDir, Path.ChangeExtension(modelName, null));
                Logger.Log("Checking for NCNN model: " + outPath);
                if (IOUtils.GetAmountOfFiles(outPath, false) < 2)
                {
                    Logger.Log("Running model converter...");
                    DialogForm dialog = new DialogForm("Converting ESRGAN model to NCNN format...");
                    await RunConverter(modelPath);

                    if (lastNcnnOutput.Contains("Error:"))
                    {
                        throw new Exception(lastNcnnOutput.SplitIntoLines().Where(x => x.Contains("Error:")).First());
                    }

                    string moveFrom = Path.Combine(Paths.esrganPath, Path.ChangeExtension(modelName, null));
                    Logger.Log("Moving " + moveFrom + " to " + outPath);
                    await IOUtils.CopyDir(moveFrom, outPath, "*", true);

                    Directory.Delete(moveFrom, true);
                    dialog.Close();
                }
                else
                {
                    Logger.Log("NCNN Model is cached - Skipping conversion.");
                }

                ESRGAN.currentNcnnModel = outPath;
            }
            catch (Exception e)
            {
                Logger.ErrorMessage("Failed to convert Pytorch model to NCNN format! It might be incompatible.", e);
            }
        }
Ejemplo n.º 6
0
        static async Task CopyCompatibleImagesToTemp(bool move = false)
        {
            IOUtils.ClearDir(Paths.imgOutPath);
            Logger.Log("currentInDir: " + currentInDir + ", imgInPath: " + Paths.imgInPath);

            if (currentInDir == Paths.imgInPath)    // Skip if we are directly upscaling the img-in folder
            {
                return;
            }

            Logger.Log($"Clearing '{Paths.imgInPath}'");
            IOUtils.ClearDir(Paths.imgInPath);

            if (multiImgMode)
            {
                await CopyImages(currentInFiles);
            }
            else
            {
                await IOUtils.CopyDir(currentInDir, Paths.imgInPath, "*", false, true);
            }
        }