πŸ—Ό Industrial Tower Defect Detection & Localization Model

100% Custom Mathematical Machine Learning Architecture (Pure PyTorch & NumPy)

This model is an industrial-grade Computer Vision detector for power transmission and telecommunication tower inspection, engineered from mathematical first principles in pure PyTorch with zero third-party YOLO/Ultralytics dependencies.


🎯 Target Defect Classes

Class ID Defect Name Severity Description
0 rust HIGH Surface oxidation, flaking paint, and steel corrosion
1 missing_bolt CRITICAL Unbolted joint holes and loosened fasteners on gusset plates
2 veg MEDIUM Climbing vegetation, weeds, and tree branches reaching tower legs
3 bird_nest MEDIUM Avian twig nests on antenna brackets and crossarms
4 damaged_insulator CRITICAL Chipped, broken porcelain glass sheds or flashover burn marks

🎨 Rust-Colored Tower Paint & Color-Invariance Defense

Towers painted with red oxide primer, reddish-brown anti-corrosion paint, or Cor-Ten weathering steel often fool traditional models into producing false rust detections.

This model employs texture-centric feature discrimination:

  • Color-Invariance Training: Trained with random desaturation (grayscale) and hue jitter to prevent relying on red/brown color channels alone.
  • Morphology Over Hue: Convolutions prioritize surface pitting, peeling blisters, and edge irregularities over uniform paint sheen.
  • Hard Negative Background Training: Unlabeled clean painted metal surfaces train objectness logits to zero ($y_{\text{obj}} = 0$).

🧠 Neural Architecture

  • Backbone: Deep Residual Convolutional Network with Squeeze-and-Excitation (SE) Channel Attention, SPPF (Spatial Pyramid Pooling - Fast), and 4-stage multi-scale downsampling ($P_3$ Stride 8, $P_4$ Stride 16, $P_5$ Stride 32) with SiLU activations.
  • Neck: 3-Scale Feature Pyramid Network & Path Aggregation Network (FPN + PAN) with dual-pathway lateral fusion across $P_3, P_4, P_5$.
  • Head: Triple decoupled prediction heads separating bounding box regression $[t_x, t_y, t_w, t_h]$, objectness $t_{\text{obj}}$, and class probabilities.
  • Loss: Multi-task Complete IoU (CIoU) regression + $\alpha$-Balanced Focal Loss for dense background suppression + Scale-aware target routing + Multi-class Cross-Entropy (CE).

πŸš€ Quick Usage in Python

1. Load with Pure PyTorch

import torch
from model import RawCustomDetector, decode_predictions, custom_nms
from PIL import Image
import numpy as np

# Load architecture & weights
model = RawCustomDetector(num_classes=5)
checkpoint = torch.load("best.pt", map_location="cpu")
model.load_state_dict(checkpoint["model_state_dict"] if "model_state_dict" in checkpoint else checkpoint)
model.eval()

# Preprocess image
img = Image.open("tower_photo.jpg").convert("RGB").resize((640, 640))
tensor = torch.from_numpy(np.array(img, dtype=np.float32) / 255.0).permute(2, 0, 1).unsqueeze(0)

# Forward pass & Decode
with torch.no_grad():
    preds = model(tensor)
    boxes, scores, classes = decode_predictions(preds, conf_thresh=0.25)[0]
    detections = custom_nms(boxes, scores, classes, iou_thresh=0.45)

print("Detected defects:", detections)

2. Load with ONNX Runtime (Cross-Platform)

import onnxruntime as ort
import numpy as np

session = ort.InferenceSession("best_640x640.onnx")
dummy_input = np.random.randn(1, 3, 640, 640).astype(np.float32)
outputs = session.run(None, {"images": dummy_input})
print("P3 Stride 8 shape  (Small Defects - Bolts):", outputs[0].shape)
print("P4 Stride 16 shape (Medium Defects - Nests/Insulators):", outputs[1].shape)
print("P5 Stride 32 shape (Large Defects - Rust/Veg):", outputs[2].shape)
Downloads last month
33
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support