/ README.md
README.md
  1  # Powerline Unet <img width="696" height="62" alt="powerline3" src="https://github.com/user-attachments/assets/b1d9032a-c58b-45c8-a6b1-9646ced3e920" />
  2  A U-Net model for Power Line image segmentation, generating precise masks for computer vision using drone-based inspections. Built for AI and CV enthusiasts.
  3  
  4  ## Features
  5  
  6  - A partitioning approach to segmentation, to detect all fine powerline conductors
  7  - A custom loss function, a hybrid between two seperate loss functions (BCE and Dice loss)
  8  - Run with bash or command line instructions
  9  - Fine trained model is supplied (hosted on huggingface)
 10  - The output can be used to automate visible fault detections
 11  - Dependencies are specified
 12  
 13  This project addresses a critical automation step in powerline inspections
 14  
 15  > Output masks define the power line pixels,
 16  > serving as the crucial first step in visible 
 17  > fault identification of power line images captured by drones. 
 18  > Eventually, all inspections will be fully automated,
 19  > using this technology to identify weakened 
 20  > conductors caused by issues like
 21  > broken strands, 
 22  > corrosion
 23  > untwisting (bird-caging).
 24  
 25  This project is the result of several years of research and study
 26  part of my honors thesis. 
 27  
 28  <img width="800" height="1000" alt="detection" src="https://github.com/user-attachments/assets/9050aa07-df18-4966-86ed-ad127d5d2f50" />
 29  
 30  ## Installation Instructions:
 31  
 32  - Python 3.10, CUDA 11.7, NVIDIA GPU
 33  - CUDA/cuDNN setup NVIDIA CUDA 11.7 and cuDNN 8.9
 34  - Use this command to install depdendencies:
 35  ```sh
 36      pip install -r requirements.txt
 37  ```
 38  
 39  ## Usage Instructions:
 40  - This project uses the model hockmaAI/PowerlineUNet 
 41   (https://huggingface.co/hockmaAI/PowerlineUNet) hosted on Hugging Face.
 42  - run inference using this command:
 43  ```sh
 44     python src/inference.py --input_path data/inference/in/1.jpg --output_path data/inference/out/1_mask.png
 45  ```
 46  - optional commands (model_path; input_path; output_path)
 47  - output directory is in data/inference/out
 48  
 49  ## Dependencies
 50  - Reference requirements.txt and note any specific versions (eg. numpy<2.0 for compatability)
 51  
 52  ## Model Details
 53  - A 4-layer UNet model with attention gates
 54  - Trained on 32,000,000 parameters
 55  
 56  ## Custom Loss Function
 57  - hybrid function between Binary Cross-Entropy and custom Dice Loss
 58  - Designed to address the significant class imbalance (power line pixels are a low %)
 59  - The model is attentive to foreground pixels.
 60  - BCE contributes 70% to the loss value, while Dice loss contributes 30%.
 61  
 62  ## Sample Data
 63  To get you started, the data/inference/in directory includes sample images. 
 64  Simply place your own images in this directory to run the model.
 65  For academic or research purposes, the full training dataset of 
 66  over 2,000 images is available upon request.
 67  
 68  ## Author:
 69  - GitHub: hockmaAI
 70  - Email: hockma1985@gmail.com
 71  
 72  Contributions are welcome! 
 73  If you have ideas for improving the model, adding features, or enhancing the documentation, 
 74  please feel free to open an issue or submit a pull request.
 75  
 76  
 77  ## Third-Party Licenses and Attributions
 78  
 79  This project uses and adapts code and data from several third-party sources. We are grateful for their contributions to the open-source community.
 80  
 81  ### Mendeley Dataset
 82  - **Description:** Part of the training data was sourced from the Mendeley dataset.
 83  - **Source:** [https://data.mendeley.com/datasets/n6wrv4ry6v/8](https://data.mendeley.com/datasets/n6wrv4ry6v/8)
 84  - **License:** MIT License. A copy of the license is included in this repository.
 85  
 86  ### Focal Phi Loss
 87  - **Description:** This model variant includes the focal phi loss, a custom loss function.
 88  - **Source:** [https://github.com/rubeea/focal_phi_loss_mmsegmentation](https://github.com/rubeea/focal_phi_loss_mmsegmentation)
 89  - **License:** Apache 2.0 License. A copy of the license is included in this repository.
 90  
 91  ### CLAHE Algorithm
 92  - **Description:** The CLAHE algorithm was used to balance high-contrast images.
 93  - **Source:** [https://github.com/anntzer/clahe](https://github.com/anntzer/clahe)
 94  - **License:** Zlib License. A copy of the license is included in this repository.
 95  
 96  
 97  ## License:
 98  
 99  This project is licensed under the MIT License.
100  
101