Esempio n. 1
0
 private static void ChangeToolBuildFolder()
 {
     FancyWriter.WriteSlow("Please enter new tools build folder");
     buildFolderPath = FancyReader.AwaitDirectory(strings.BuildFolderPrompt);
     File.WriteAllText("bfp.txt", buildFolderPath);
     FancyWriter.WriteSlow("You have selected :" + File.ReadAllText("bfp.txt") +
                           " as your build folder");
 }
Esempio n. 2
0
 private static void ChangeDaknetFolder()
 {
     FancyWriter.WriteSlow("Please enter new Darknet folder");
     darknetFolderPath = FancyReader.AwaitDirectory(strings.DBWorkspacePrompt);
     File.WriteAllText("drk.txt", darknetFolderPath);
     FancyWriter.WriteSlow("You have selected :" + File.ReadAllText("drk.txt") +
                           " as your darknet build folder");
 }
Esempio n. 3
0
        private static void Main()
        {
            //    Console.OutputEncoding = Encoding.UTF8;

            FancyWriter.WriteSlow("Hello World!");
            FancyWriter.WriteSlow(strings.Intro);
            if (FancyReader.AwaitConfirmation())
            {
                FancyWriter.WriteSlow("Loading configurations...");
                // You can new up an instance
                //Load path
                if (File.Exists("bfp.txt"))
                {
                    buildFolderPath = File.ReadAllText("bfp.txt");
                    Console.WriteLine("Your tools build path: " + buildFolderPath);
                }
                else
                {
                    buildFolderPath = FancyReader.AwaitDirectory(strings.BuildFolderPrompt);
                    File.WriteAllText("bfp.txt", buildFolderPath);
                    FancyWriter.WriteSlow("You have selected :" + File.ReadAllText("bfp.txt") +
                                          " as your build folder");
                }

                if (File.Exists("dbw.txt"))
                {
                    databaseWorkspaceFolderPath = File.ReadAllText("dbw.txt");
                    Console.WriteLine("Your database workspace path: " + databaseWorkspaceFolderPath);
                }
                else
                {
                    databaseWorkspaceFolderPath = FancyReader.AwaitDirectory(strings.DBWorkspacePrompt);
                    File.WriteAllText("dbw.txt", databaseWorkspaceFolderPath);
                    FancyWriter.WriteSlow("You have selected :" + File.ReadAllText("dbw.txt") +
                                          " as your  database workspace folder");
                }

                if (File.Exists("drk.txt"))
                {
                    darknetFolderPath = File.ReadAllText("drk.txt");
                    Console.WriteLine("Your darknet build path: " + darknetFolderPath);
                }
                else
                {
                    darknetFolderPath = FancyReader.AwaitDirectory(strings.DarknetPathPrompt);
                    File.WriteAllText("drk.txt", darknetFolderPath);
                    FancyWriter.WriteSlow("You have selected :" + File.ReadAllText("drk.txt") +
                                          " as your darknet build folder");
                }
                while (!Run())
                {
                }
            }
        }
Esempio n. 4
0
        private static void BackupDB()
        {   //The way backup may work:
            //We backup our current database, which will be located in workspace.
            //After backup is made, we can then add additions to the current database
            //And then transfer our current database to training build folder.
            FancyWriter.WriteHeader("Database backup");
            if (FancyReader.AwaitConfirmation(
                    "Are you sure to continue? This action could take a really long time if your database is huge."))
            {
                var date             = DateTime.Now.ToString("yyyy-MM-dd_hh_mm");
                var backupDir        = Path.Combine("Backup", date);
                var currentDir       = "Current";
                var logoBackupDir    = Path.Combine(backupDir, "logoData");
                var weightsBackupDir = Path.Combine(backupDir, "weights");
                Directory.SetCurrentDirectory(Path.Combine(databaseWorkspaceFolderPath, "Database"));

                Directory.CreateDirectory(backupDir);
                //                Directory.CreateDirectory(logoBackupDir);
                //                Directory.CreateDirectory(weightsBackupDir);
                Directory.GetDirectories(currentDir).ToList().ForEach(c => CopyDir(c, backupDir));
                FancyWriter.WriteSlow("Backup finished");
            }
        }
Esempio n. 5
0
        private static bool Run()
        {
Start:
            Console.WriteLine();
            FancyWriter.WriteSlow(strings.FirstPrompt);
            var answer = FancyReader.AwaitAnswer();

            switch (answer)
            {
            case "exit":
                goto Exit;

            case "AI setup":
                goto AISetup;

            case "prepare new database":
                goto DBSetup;

            case "add to database":
                goto DBSetup;

            case "change build folder":
                ChangeToolBuildFolder(); break;

            case "change database folder":
                ChangeDBWorkspaceFolder(); break;

            case "change darknet folder":
                ChangeDaknetFolder(); break;

            case "backup current":
                BackupDB();
                break;

            case "transfer new dataset":
                TransferAddition(FancyReader.AwaitDirectory("Please enter the directory of your dataset. Additions/Data . It should contain txt and jpg files."));
                break;

            case "prepare for training":
                GenerateTrainValidFiles();
                break;

            case "test":
                FancyWriter.WriteSlow("Please read the guide on testing");
                OpenFolder(Path.Combine(buildFolderPath, "TestYolo4Video", "Debug"));
                break;
            }
            goto Start;

            #region DatabaseSetupRegion

DBSetup:

            if (!FancyReader.AwaitConfirmation("Have you done this before?"))
            {
                FancyWriter.WriteSlow(strings.DBPrep);
            }
            if (FancyReader.AwaitConfirmation("Are you sure you want to continue? There are a lot of steps for it."))
            {
                Console.WriteLine();
                Console.WriteLine("Creating folder structure...");
                Directory.CreateDirectory(Path.Combine(databaseWorkspaceFolderPath, "Database"));
                Directory.SetCurrentDirectory(Path.Combine(databaseWorkspaceFolderPath, "Database"));
                foreach (var folder in strings.DBFolderTree.Split('\n'))
                {
                    Directory.CreateDirectory(folder);
                }
                Console.WriteLine();
                FancyWriter.WriteHeader("Gather Videos");
                if (!FancyReader.AwaitConfirmation("Have you done this before?"))
                {
                    FancyWriter.WriteSlow(strings.GatherVideosHint);
                }
GatherVideos:
                if (FancyReader.AwaitConfirmation("Have you gathered your videos?"))
                {
                    //TODO possible problems when the user wants to use only frames and not videos.
                    var curDir = "Additions";
                    Directory.SetCurrentDirectory(curDir);
                    var newDir = FancyReader.AwaitAnswer(
                        "Please enter the name for your new databse addition. I suggest using yy_mm_dd format.");
                    var videoDir = Path.Combine(newDir, "Videos");
                    var frameDir = Path.Combine(newDir, "Frames");
                    var gtDir    = Path.Combine(newDir, "GTFiles");
                    var txtDir   = Path.Combine(newDir, "TxtFiles");
                    //Directory containing both frames and txt files
                    var dataDir = Path.Combine(newDir, "Data");
                    Directory.CreateDirectory(videoDir);
                    Directory.CreateDirectory(frameDir);
                    Directory.CreateDirectory(txtDir);
                    Directory.CreateDirectory(dataDir);
                    //TODO Make this cross platform
                    OpenFolder(Path.Combine(databaseWorkspaceFolderPath, "Database", curDir, videoDir));
PasteVideos:
                    FancyWriter.WriteSlow("Paste in all of those videos and nothing else in this new folder.");

                    if (FancyReader.AwaitConfirmation("Have you pasted your videos?"))
                    {
                        if (CheckForVideos(videoDir))
                        {
                            FancyWriter.WriteSlow("We shall proceed with cutting.");
                            if (Directory.GetFiles(frameDir).Length > 0)
                            {
                                if (FancyReader.AwaitConfirmation(
                                        "There are already some cut frames inside frame folder. Do you still want to cut the video? This will overwrite current frames with the same name."))
                                {
                                    if (CutVideoToFrames(
                                            Path.Combine(databaseWorkspaceFolderPath, "Database", curDir, videoDir), frameDir))
                                    {
                                        FancyWriter.WriteSlow("Frames cut. Please inspect frames for any possible glitches.");
                                        Directory.SetCurrentDirectory(Path.Combine(databaseWorkspaceFolderPath, "Database",
                                                                                   curDir));
                                        OpenFolder(frameDir);
                                    }
                                }
                            }

                            {
Marking:
                                Directory.SetCurrentDirectory(Path.Combine(databaseWorkspaceFolderPath, "Database", curDir));
                                FancyWriter.WriteSlow("Now when as we have our frames, we can begin marking them");
                                FancyWriter.WriteSlow("Please open your YoloGuide and follow 'Marking Objects' paragraph.");
SavingGTFiles:
                                FancyWriter.WriteSlow("Save your GT files to ");
                                Directory.CreateDirectory(gtDir);
                                OpenFolder(gtDir);
                                FancyWriter.WriteSlow("Come back to me when you are finished.");
                                if (FancyReader.AwaitConfirmation("Are you finished marking objects?"))
                                {
                                    FancyWriter.WriteSlow("Doing some data parsing...");
                                    FancyWriter.WriteHeader("Data Parsing");
                                    if (Directory.GetFiles(gtDir).All(c => c.EndsWith(".txt")))
                                    {
                                        var files = Directory.GetFiles(gtDir);
                                        FancyWriter.WriteSlow("Please select you latest file from this list, by entering integer.");
                                        var j = 0;
                                        foreach (var file in files)
                                        {
                                            Console.WriteLine("[" + j + "]" + file);
                                            j++;
                                        }

                                        var  gtFile    = files[FancyReader.AwaitPosUInt()];
                                        uint imgWidth  = FancyReader.AwaitPosUInt("Please enter the width of your used video.");
                                        uint imgHeight = FancyReader.AwaitPosUInt("Please enter the height of your used video.");

                                        var rectMode = FancyReader.AwaitAnswer("Please enter rectangle mode you used for marking objects. It can be 'xywh' or 'cxcywh'");
                                        while (rectMode != "xywh" || rectMode != "cxcywh") //This is an odd solution

                                        {
                                            if (rectMode == "xywh" || rectMode == "cxcywh")
                                            {
                                                break;
                                            }
                                            FancyWriter.WriteSlow(rectMode + " - is not a correct answer. Try again.");
                                            rectMode = FancyReader.AwaitAnswer("Please enter rectangle mode you used for marking objects. It can be 'xywh' or 'cxcywh'");
                                        }

                                        Console.WriteLine("Attempting to parse data for txt files.");

                                        if (
                                            DataParserParse(
                                                Path.Combine(databaseWorkspaceFolderPath, "Database", curDir, frameDir), Path.Combine(databaseWorkspaceFolderPath, "Database", curDir, gtFile), rectMode
                                                , imgWidth, imgHeight, txtDir, dataDir, Path.Combine(databaseWorkspaceFolderPath, "Database", curDir)))
                                        {
                                            Directory.SetCurrentDirectory(Path.Combine(databaseWorkspaceFolderPath, "Database", curDir));
                                            FancyWriter.WriteSlow("DataParsing successful! Cropping images for validation. This may take a while...");
                                            if (CropImages(Path.Combine(databaseWorkspaceFolderPath, "Database", curDir, dataDir)))
                                            {
                                                FancyWriter.WriteSlow(
                                                    "Cropping successful! Please carefully inspect all of the cut frames.");
                                                Directory.SetCurrentDirectory(Path.Combine(databaseWorkspaceFolderPath, "Database", curDir));
                                                OpenFolder(dataDir);
                                                if (FancyReader.AwaitConfirmation("Have you finished inspection?"))
                                                {
                                                    if (FancyReader.AwaitConfirmation("Did you find any mistakes?"))
                                                    {
                                                        FancyWriter.WriteSlow(
                                                            "Please fix them and redo these steps again.");
                                                        goto Marking;
                                                    }
                                                    if (FancyReader.AwaitConfirmation("Do you want to augument new dataset? This will increase the quality of the database."))
                                                    {
                                                        Augment(Path.Combine(databaseWorkspaceFolderPath,
                                                                             "Database", curDir, dataDir));
                                                    }
                                                    if (FancyReader.AwaitConfirmation("Do you want to add your new dataset to working('Current') folder?"))
                                                    {
                                                        TransferAddition(Path.Combine(databaseWorkspaceFolderPath,
                                                                                      "Database", curDir, dataDir));
                                                    }
                                                    if (FancyReader.AwaitConfirmation("Do you want to generate train and valid files for your new dataset?"))
                                                    {
                                                        GenerateTrainValidFiles();
                                                        FancyWriter.WriteSlow(
                                                            "Congratulations! You have finished database preparation! For the next step use training command.");
                                                    }
                                                    else
                                                    {
                                                        FancyWriter.WriteSlow(
                                                            "Congratulations! You have finished database preparation! For the next step use training preparation command.");
                                                    }

                                                    FancyWriter.WriteHeader("THE END");
                                                }
                                            }
                                            else
                                            {
                                                FancyWriter.WriteSlow(
                                                    "Cropping failed! ");
                                            }
                                        }
                                        else
                                        {
                                            FancyWriter.WriteSlow("Failed to parse data from gt file. Unfortunately you will have to try again.");
                                        }
                                    }
                                    else
                                    {
                                        FancyWriter.WriteSlow("You did not put GT file in the correct place...");
                                        goto SavingGTFiles;
                                    }
                                }
                            }
                        }
                        else
                        {
                            FancyWriter.WriteSlow("You liar! Do it again!");
                            goto PasteVideos;
                        }
                    }
                }
                else
                {
                    goto GatherVideos;
                }
            }
            goto Start;

            #endregion DatabaseSetupRegion

            #region AISetupRegion

AISetup:
            FancyWriter.WriteSlow(strings.YoloSetup);
            if (FancyReader.AwaitConfirmation())
            {
                OpenUrl(strings.DarkNetGitSite);
            }
            goto Start;

            #endregion AISetupRegion

            #region ExitRegion

Exit:
            FancyWriter.WriteSlow("Do you want to exit?");
            FancyReader.AwaitConfirmation();
            Thread.Sleep(1000);
            return(true);

            #endregion ExitRegion
        }