Пример #1
0
        private static bool CutVideoToFrames(string videosPath, string savePath)
        {
            FancyWriter.WriteHeader("Video to frames cutting");
            var exeFolderPath = Path.Combine(buildFolderPath, "FrameCut", "Debug");
            var exePath       = Path.Combine(buildFolderPath, exeFolderPath, "FrameCut.exe");

            if (!CheckForVideos(videosPath) || !File.Exists(exePath))
            {
                FancyWriter.WriteSlow("Either your folder with videos is invalid, or your tools path. Please reconsider reconfiguring.");
                return(false);
            }
            Directory.SetCurrentDirectory(savePath);
            var myProcess = new Process();
            var info      = new ProcessStartInfo(exePath, videosPath + "/")
            {
                UseShellExecute = true
            };

            myProcess.StartInfo = info;
            myProcess.Start();
            //string error = myProcess.StandardError.ReadToEnd();
            myProcess.WaitForExit();
            //            var frames = Directory.GetFiles(exeFolderPath).Where(c => c.EndsWith(".jpg"));
            //            ushort p = 0;
            //            foreach (var frame in frames)
            //            {
            //                FancyWriter.UpdateStatus("Copying frames... ", p, (ushort)frames.Count(), true);
            //                File.Copy(Path.Combine(exeFolderPath, frame), Path.Combine(savePath, frame));
            //                p++;
            //            }

            return(true);
        }
Пример #2
0
        private static bool GenerateTrainValidFiles()
        {
            FancyWriter.WriteHeader("Generating train.txt and valid.txt");
            Directory.SetCurrentDirectory(Path.Combine(databaseWorkspaceFolderPath, "Database", "Current", "Configs"));
            var exeFolderPath = Path.Combine(buildFolderPath, "TrainValidFiles", "Debug");
            var exePath       = Path.Combine(buildFolderPath, exeFolderPath, "TrainValidFiles.exe");

            if (!File.Exists(exePath))
            {
                FancyWriter.WriteSlow("Either your folder with videos is invalid, or your tools path. Please reconsider reconfiguring.");
                return(false);
            }
            var myProcess = new Process();
            var info      = new ProcessStartInfo(exePath, Path.Combine(databaseWorkspaceFolderPath, "Database", "Current", "logoData") + "/")
            {
                UseShellExecute = true
            };

            myProcess.StartInfo = info;
            myProcess.Start();
            //string error = myProcess.StandardError.ReadToEnd();
            myProcess.WaitForExit();
            FancyWriter.WriteSlow("Generation completed.");
            return(true);
        }
Пример #3
0
        private static bool CropImages(string dataDir)
        {
            FancyWriter.WriteHeader("Cropping for validation");
            if (!Directory.Exists(dataDir))
            {
                FancyWriter.WriteSlow("Your data directory does not exist");
                return(false);
            }
            var exeFolderPath = Path.Combine(buildFolderPath, "cropImage", "Debug");
            var exePath       = Path.Combine(buildFolderPath, exeFolderPath, "cropImage.exe"); //TODO make cross platform

            if (!File.Exists(exePath))
            {
                FancyWriter.WriteSlow("Your tools path is invalid. Please reconsider reconfiguring.");
                return(false);
            }
            var cropFolder = Path.Combine(dataDir, "cropedImg");

            Directory.CreateDirectory(cropFolder);
            var classesFile = Path.Combine(darknetFolderPath, "data", "obj.names");

            if (!File.Exists(classesFile))
            {
                return(false);
            }

            var objects = File.ReadAllLines(classesFile);

            foreach (var o in objects)
            {
                Directory.CreateDirectory(Path.Combine(cropFolder, o));
            }
            Directory.SetCurrentDirectory(dataDir);
            //Start application
            var myProcess = new Process();
            var info      = new ProcessStartInfo(exePath,
                                                 dataDir + "/")
            {
                UseShellExecute = true
            };

            myProcess.StartInfo = info;
            myProcess.Start();
            myProcess.WaitForExit();

            //string error = myProcess.S
            return(true);
        }
Пример #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");
            }
        }
Пример #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
        }
Пример #6
0
        private static bool DataParserParse(string framesPath, string gtFilePath, string rectMode, uint width,
                                            uint height, string txtSavePath, string combinedSavePath, string curDir)
        {
            FancyWriter.WriteHeader("GT Parsing");
            var exeFolderPath = Path.Combine(buildFolderPath, "DarkLabelDataParser", "Debug");
            var exePath       = Path.Combine(buildFolderPath, exeFolderPath, "DarkLabelDataParser.exe"); //TODO make cross platform

            if (!File.Exists(exePath))
            {
                FancyWriter.WriteSlow("Your tools path is invalid. Please reconsider reconfiguring.");
                return(false);
            }
            if (!File.Exists(gtFilePath))
            {
                FancyWriter.WriteSlow("Your gtFile path is invalid. Please check.");
                return(false);
            }
            Directory.SetCurrentDirectory(txtSavePath);
            var myProcess = new Process();
            var info      = new ProcessStartInfo(exePath,
                                                 framesPath + "/ " + gtFilePath + " " + rectMode + " " + width + " " + height)
            {
                UseShellExecute = true
            };

            myProcess.StartInfo = info;
            myProcess.Start();
            //string error = myProcess.StandardError.ReadToEnd();
            myProcess.WaitForExit();
            Console.WriteLine("Parsing finished. Copying files to same directory.");

            var frames = Directory.GetFiles(Directory.GetCurrentDirectory()).Where(c => c.EndsWith(".txt")).ToList();

            Directory.SetCurrentDirectory(curDir);
            ushort p = 0;

            foreach (var frame in frames)
            {
                FancyWriter.UpdateStatus("Copying txt files... ", p, (ushort)frames.Count(), true);
                var pathToSaveTo = Path.Combine(combinedSavePath, Path.GetFileName(frame));
                if (!File.Exists(pathToSaveTo))
                {
                    File.Copy(frame, pathToSaveTo);
                }
                p++;
            }
            Directory.SetCurrentDirectory(framesPath);
            frames = Directory.GetFiles(framesPath).Where(c => c.EndsWith(".jpg")).ToList();
            Directory.SetCurrentDirectory(curDir);
            p = 0;
            foreach (var frame in frames)
            {
                FancyWriter.UpdateStatus("Copying jpg files... ", p, (ushort)frames.Count(), true);
                var pathToSaveTo = Path.Combine(combinedSavePath, Path.GetFileName(frame));
                if (!File.Exists(pathToSaveTo))
                {
                    File.Copy(frame, pathToSaveTo);
                }
                p++;
            }
            return(true);
        }