Skip to main content

A deep learning crack detection package supporting U-Net and DeepCrack models with PyTorch and ONNX backends.

Project description

findcrack

findcrack is a deep learning crack detection package designed for pixel-level segmentation on high-resolution images. It supports U-Net and DeepCrack architectures, providing an easy-to-use API for inference, model caching, and multi-backend execution (PyTorch & ONNX).


Features

  • Pre-trained Model Zoo: Fetch pre-trained model weights (e.g., Seg_UNET_CFD_actual_v1, Seg_UNET_CFD_actual_v2) dynamically on demand.
  • Unified Backend Engine: Seamlessly executes either PyTorch (.pth/.pt) or ONNX (.onnx) models using the same standard interface.
  • Sliding-Window Inference: Efficiently process ultra-high-resolution images by dividing them into overlapping patches.
  • Gaussian & Average Blending: Reconstructs the full image from patches using overlapping Gaussian blending filters to eliminate edge-seam artifacts.
  • Test-Time Augmentation (TTA): Performs multi-way augmentations (original, horizontal flip, vertical flip, and rotations) to produce highly robust prediction masks.
  • Validation Metrics: Compute standard segmentation metrics like IoU, Dice Coefficient, Precision, Recall, and Pixel Accuracy.

Installation

You can install findcrack directly from source or via PyPI (once published):

# Install via pip
pip install findcrack

# Or using uv
uv add findcrack

Quickstart

Here is how to load a pre-trained model and run crack detection on a large image:

import cv2
from findcrack import CrackInferencePipeline, load_model

# 1. Load a pre-trained model from the official registry (or use your own URL)
# The weights are downloaded dynamically from GitHub releases on first use.
model = load_model("Seg_UNET_CFD_actual_v1", device="cuda")

# 2. Setup the inference pipeline
pipeline = CrackInferencePipeline(
    model=model,
    device="cuda",
    patch_size=512,
    overlap_ratio=0.2,
    confidence_threhold=0.5,
    use_tta=True  # Enables multi-way Test-Time Augmentation
)

# 3. Perform inference
results = pipeline.predict("path/to/high_res_concrete.jpg")

# The results dictionary contains:
# - results["original_image"]: Original RGB image (numpy array)
# - results["confidence_map"]: Float probability map [0.0 - 1.0]
# - results["binary_mask"]: Binary segmentation mask [0 or 255]

# Save the output mask
cv2.imwrite("detected_cracks.png", results["binary_mask"])

API Reference

Model Loading & Caching

load_model(variant: str, device: str = "cpu", force_download: bool = False, architecture = None, **kwargs)

Loads a model variant from the local registry or directly from a remote HTTP(S) URL.

  • Parameters:
    • variant: The name of a registered variant (e.g., "Seg_UNET_CFD_actual_v1") or a direct HTTP(S) URL to a weights file.
    • device: Target execution device ("cpu", "cuda", or "mps").
    • force_download: If True, re-downloads weights even if cached locally.
    • architecture: PyTorch architecture class (e.g., UNet, DeepCrack) - required only if loading a raw .pth/.pt file from a custom URL.
from findcrack import load_model, UNet

# Load custom model weights directly from an external URL
model = load_model(
    variant="https://my-domain.com/custom_unet.pth",
    architecture=UNet,
    device="cuda"
)

list_models()

Returns a list of all pre-trained models available in the built-in registry.

register_model(name: str, url: str, architecture = None, kwargs: dict = None, backend: str = "pytorch")

Registers a custom variant dynamically at runtime.


Pipeline Configuration

CrackInferencePipeline(model, device: str = "cuda", patch_size: int = 512, overlap_ratio: float = 0.2, confidence_threhold: float = 0.5, use_tta: bool = False)

Handles sliding window preprocessing, execution, TTA, and patching reconstruction.


Directory Structure

src/
└── findcrack/
    ├── __init__.py          # Main API endpoints (load_model, CrackInferencePipeline, etc.)
    ├── metrics.py           # Segmentation evaluation metrics (IoU, Dice, etc.)
    ├── patching.py          # Sliding window extraction and blend reconstruction
    ├── pipeline.py          # Crack Inference Pipeline wrapper
    ├── preprocess.py        # Color-space CLAHE contrast enhancement & transforms
    ├── tta.py               # Test-Time Augmentation forward pass routines
    └── models/
        ├── __init__.py      # Model module exports
        ├── unet.py          # U-Net model definition
        ├── deepcrack.py     # DeepCrack model definition
        ├── onnx_wrapper.py  # Wrapper for running ONNX models as nn.Modules
        └── zoo.py           # Remote weight registry and cached loaders

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

findcrack-0.1.1.tar.gz (95.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

findcrack-0.1.1-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file findcrack-0.1.1.tar.gz.

File metadata

  • Download URL: findcrack-0.1.1.tar.gz
  • Upload date:
  • Size: 95.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for findcrack-0.1.1.tar.gz
Algorithm Hash digest
SHA256 15076c3da5e04dba9826d2bf5a65331c7c356394dedb7efcb0d3c542ed88ec54
MD5 03f7534d28f26c4f310042a8b6a4cef4
BLAKE2b-256 2dc7921af6cbed8921ef7844b1cee652ae53929de14ac39327d8078c1e588c3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for findcrack-0.1.1.tar.gz:

Publisher: release.yml on StrikerEurika/findcrack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file findcrack-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: findcrack-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for findcrack-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 97b4c80957ed0655ec02be2782e9d81c01b2956d987b53f0fff656d7a551a209
MD5 a0a86c4340daaddefad0947511440748
BLAKE2b-256 3b9f1c3789072695a574dacd14eae9f6267b8859749b0d4c82b0c54bdf103eaa

See more details on using hashes here.

Provenance

The following attestation bundles were made for findcrack-0.1.1-py3-none-any.whl:

Publisher: release.yml on StrikerEurika/findcrack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page