/DarkFusion

machine learning

Primary LanguagePython

UltraDarkFusion GUI

UltraDarkFusion

An advanced GUI application tailored for object detection, image processing, and computer vision. It simplifies workflows for collection, labeling, dataset management, model training, and visualization of real-time inferences.

Features

  • Annotation Tools: Customizable bounding box annotation with YOLO format conversion.
  • Dataset Management: Tools for duplicate removal, image splitting, and dataset preparation.
  • Image Augmentation: Apply effects such as motion blur, noise, and lighting adjustments.
  • Framework Integration: Compatible with Darknet and Ultralytics frameworks.
  • Model Training: In-built training capabilities for Ultralytics and Darknet models.
  • Visualization: Automatic labeling and visualization using pre-trained .weights or .pt files for efficient model evaluation.
  • Performance Metrics: Analytics to monitor and optimize training progress.
  • Hardware Acceleration: Support for CUDA, OpenCL, and CPU backends.
  • Customizable UI: Themes, styling, and user-defined shortcuts.
  • Video Processing: Download YouTube videos, extract frames, or collect images from the screen directly.
  • Segment Anything: Correct bounding boxes to fit around your objects.
  • Grounding-DINO: Label anything in your classes.txt.
  • TensorRT Support: Support for .engine on Ultralytics YOLOv8.

UltraDarkFusion is designed to be modular, enabling easy integration of new algorithms and streamlining the process from dataset preparation to model training.

🚀 Getting Started with Installation

Before diving into the code, let's set up your environment with the necessary build tools. Open up a command prompt and execute the following commands to download Git and CMake. These are essential tools for version control and building the project, respectively Install Git and cmake close the terminal after your done this allows it to refresh otherwise you may recieve and error.

Installation Guide

There are two options for installing UltraDarkFusion - Option #1 "OpenCL without CUDA" is the simplier of the two but you may see a slight reduction in performance, Option #2 "DNN with CUDA" is more complex to setup but will likely perform slightly better. Both options require you to install darknet and it requires you to install CUDA and cuDNN. Be advised that if you want the installation to go smoothly, you MUST use the exact versions as shown below and the exact folder structure as shown below. You may customize your installation but you will need to make complex modifications to it.

Installation Option 1: OpenCL without CUDA

This guide outlines the installation of UltraDarkFusion without opencv_cuda.

Preperation

winget install git.git
winget install Kitware.CMake
winget install Microsoft.VisualStudio.2022.Community

Note: It's crucial to install Visual Studio before CUDA. If you change your Visual Studio version later, you'll need to reinstall CUDA.

  • click on the "Windows Start" menu and run "Visual Studio Installer"
  • click on Modify
  • select Desktop Development With C++
  • select python development
  • click on Modify in the bottom-right corner, and then click on Yes
  • After installation, A system restart is required. ```

Installation

  1. Clone UltraDarkFusion Repository:

    cd C:/
    git clone https://github.com/lordofkillz/DarkFusion.git
    cd DarkFusion
    mkdir anaconda
  2. Install Weights:

  3. Download Anaconda:

  4. Run the Anaconda Installer:

    • Locate the downloaded Anaconda installer executable (.exe) file and run it.
    • During installation, make sure to set the installation path to c:\DarkFusion\anaconda.
  5. Execute fusion_install.bat:

    • Once Anaconda is installed, locate the fusion_install.bat file in your DarkFusion directory and right-click on it.
    • Choose "Run as administrator" to execute the script.
  6. Install Darknet:

    • There are various verions of Darknet available - at the time this readme was written, the HANK-AI/Darknet version was the most active and is the suggested version. You can elect to use a different version, but your setup might be more complex

    Darknet Options

Disclaimer: UltraDarkFusion may not fully support all versions of Darknet for visual UI output, although all versions are suitable for training. This is due to variances in output formats across different Darknet versions.

  • In Darknet by Hank-AI, there are various steps in the "Windows CMake Method that are redundant with steps in this installation:
    • you will not need to instal Git again
    • You will not need to install CMAKE again
    • You will not need to install Microsoft Visual Studio 2022 Community again
    • You will not need to modify your Visual Studio to include "Desktop Development with C++" again
    • You WILL need to install NSIS
    • Use CUDA Version 11.8.0_522.06_windows - Download it here.
    • Use cuDNN version 8.7.0.84_cuda10 - NVIDIA Developer.
      • Note: cuDNN versions prior to 9 do not have an excutable installer, you must manually move the files into the right directories and manually add the environment variables path
        • The folder you extract to should look exactly like this: C:\Program Files\NVIDIA\CUDNN\v8.x
        • Your system environment path should look like this:
        • Variable Name: Path
        • C:\Program Files\NVIDIA\CUDNN\v8.x\bin

Installation Option 2: DNN with CUDA

Preperation

Before proceeding with the installation, it's essential to assess your existing development environment. If you have a functioning setup with OpenCV and CUDA support, along with PyTorch, please consult the requirements.txt file for a list of required packages—install only the necessary ones.

Caution: It's recommended to run the program using OpenCL as there isn't a significant performance boost when utilizing .weights and .cfg files on CUDA, and the setup can be challenging. While PyTorch is installed and all .pt files are utilizing CUDA from PyTorch, compiling with opencv_cuda can be quite intricate.

Prerequisites: Clean Your PC

To ensure a smooth installation process when setting up OpenCV with CUDA support, follow these actions:

  1. Uninstall Python: Remove any existing Python installations from the Control Panel.

  2. Delete Python Cache: Navigate to %USERPROFILE%\AppData\Local\Programs\python and remove python.

  3. Remove CUDA 11.x: Uninstall all versions of CUDA 11.x from the Control Panel. If the folder C:\Program Files\NVIDIA GPU Computing Toolkit remains, delete it.

  4. Update NVIDIA Drivers: Either update your GeForce Experience Game Driver or visit NVIDIA's driver download page.

  5. Ensure you have at least 30 GB of free space for the installation.

    winget install git.git
    winget install Kitware.CMake
    winget install Microsoft.VisualStudio.2022.Community

    Note: It's crucial to install Visual Studio before CUDA. If you change your Visual Studio version later, you'll need to reinstall CUDA.

    • click on the "Windows Start" menu and run "Visual Studio Installer"
    • click on Modify
    • select Desktop Development With C++
    • select python development
    • click on Modify in the bottom-right corner, and then click on Yes
    • After installation, A system restart is required. ```

Installation

  1. Clone UltraDarkFusion Repository: Warning: If a different version of OpenCV and contrib are already installed in your environment, ensure they are updated to match the required version for UltraDarkFusion.

    Begin by navigating to your desired installation directory (e.g., C:/) using the command prompt. Following that, execute the commands below to clone the UltraDarkFusion repository and the specified versions of OpenCV and contrib:

    cd C:/
    git clone https://github.com/lordofkillz/DarkFusion.git
    cd DarkFusion
    git clone --branch 4.7.0 https://github.com/opencv/opencv.git opencv-4.7.0
    git clone --branch 4.7.0 https://github.com/opencv/opencv_contrib.git opencv_contrib-4.7.0
    mkdir anaconda build install 
  2. Install Weights:

  3. Download Anaconda:

  4. Run the Anaconda Installer:

    • Locate the downloaded Anaconda installer executable (.exe) file and run it. During installation, make sure to set the installation path to c:\DarkFusion\anaconda.
  5. Execute fusion_install.bat:

    • Once Anaconda is installed, locate the fusion_install.bat file in your UltraDarkFusion directory and right-click on it. Choose "Run as administrator" to execute the script.
  6. Install Darknet:

    • There are various verions of Darknet available - at the time this readme was written, the HANK-AI/Darknet version was the most active and is the suggested version. You can elect to use a different version, but your setup might be more complex

    Darknet Options

Disclaimer: UltraDarkFusion may not fully support all versions of Darknet for visual UI output, although all versions are suitable for training. This is due to variances in output formats across different Darknet versions.

  • In Darknet by Hank-AI, there are various steps in the "Windows CMake Method that are redundant with steps in this installation: - you will not need to instal Git again - You will not need to install CMAKE again - You will not need to install Microsoft Visual Studio 2022 Community again - You will not need to modify your Visual Studio to include "Desktop Development with C++" again - You WILL need to install NSIS - Use CUDA Version 11.8.0_522.06_windows - Download it here. - Use cuDNN version 8.7.0.84_cuda10 - NVIDIA Developer.
    • Note: cuDNN versions prior to 9 do not have an excutable installer, you must manually move the files into the right directories and manually add the environment variables path
      • The folder you extract to should look exactly like this: C:\Program Files\NVIDIA\CUDNN\v8.x
      • Your system environment path should look like this:
        • Variable Name: Path
        • C:\Program Files\NVIDIA\CUDNN\v8.x\bin
  1. cuDNN Files:

    • Copy the files you extracted to here C:\Program Files\NVIDIA\CUDNN\v8.x during the installation of Darknet to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8.
  2. (Alternative) cuDNN Files:

    • Download directly from my Google Drive here.
  3. Compile OpenCV with CUDA:

    • Run the cuda.bat script to compile OpenCV with CUDA support.
  4. Install Weights From Shared Google Drive:

    • Download the SAM folder for Grounding DINO and SAM weights. This complete folder can be obtained from the following source: SAM Folder Google Drive. Extract it to c:/darkfusion/ultradarkfusion or you will need to change the source code.

    OPTIONAL download my weights folder collection of mscoco pretrained .weights, .cfg and .pt its https://drive.google.com/file/d/1hMwNzGi2DnA19SbQdoA0OXCYzk8LwOPP/view?usp=sharing

  5. (Alternative) Install Weights From Source:

  6. Installing TensorRT from Source

    • Install TensorRT from source for advanced optimizations. Follow these steps to install TensorRT into the C:\DarkFusion\UltraDarkFusion directory:
      • Download the TensorRT zip file from NVIDIA: TensorRT-8.6.1.6 for Windows 10
      • Extract the contents of the zip file to C:\DarkFusion\UltraDarkFusion.
      • Open a anaconda prompt and change the directory to the TensorRT folder:
        conda activate fusion
        cd C:\DarkFusion\UltraDarkFusion\TensorRT-8.6.1.6
        
        
    • Install the required TensorRT wheels using pip. Make sure to install them in the following order:
      pip install python\tensorrt-8.6.1-cp38-none-win_amd64.whl
      pip install graphsurgeon\graphsurgeon-0.4.6-py2.py3-none-any.whl
      pip install uff\uff-0.6.9-py2.py3-none-any.whl
      pip install onnx_graphsurgeon\onnx_graphsurgeon-0.3.12-py2.py3-none-any.whl
      pip install protobuf==3.20.3
      
    • copy the files from tensorrt-8.6.1.6\lib folder to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin

Ultralytics

Ultralytics is pre-installed as part of this package. For documentation, visit the Ultralytics documentation site.

Running UltraDarkFusion

Recommended: Use Visual Studio Code for a smoother experience with the program.Download it here https://code.visualstudio.com/Download

If you prefer not to use Visual Studio Code:

Open Anaconda Prompt. Activate the fusion environment by running: conda activate fusion Navigate to the UltraDarkFusion directory: cd C:\DarkFusion\UltraDarkFusion Use the Tab key to auto-complete and select UltraDarkFusion_X.py, then press Enter to start the program. For further instructions, refer to the help tab in the program or join the Discord community. or simply just double click the .py


CONTRIBUTIONS AND SUPPORT

A special shoutout to everyone who has contributed to the development and improvement of UltraDarkFusion. Your insights and support have been invaluable.

UltraDarkFusion Discord: Join us for discussions, support, and community updates: https://discord.gg/kGaWChbUtR

Many thanks to all who helped and to all who had input on this. Long call #1 tester, thanks for all your help. see Discord for links to their Discord servers and websites.

Main inspiration was from DarkMark, a Linux-based label maker maintained by Stephane, the current developer for the Hank-AI Darknet repo. DarkMark GitHub: https://github.com/stephanecharette/DarkMark

Label Maker Pro (thanks EAL)! Label Maker Pro Search: https://www.bing.com/search?q=easy+aimlock

Outside of Darknet and Ultralytics, I utilized SAM. See GitHub: SAM - Segment Anything Model: https://github.com/facebookresearch/segment-anything GroundingDINO: https://github.com/IDEA-Research/GroundingDINO for additional tools used in my projects.

DarkFusion