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.0.0.tar.gz (95.1 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.0.0-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for findcrack-0.0.0.tar.gz
Algorithm Hash digest
SHA256 6d948881f89c7a06b8f2a56b6e0ede0c6bca78ba468fd498c340ac9ca49d7134
MD5 e620aa1dd2bb523659d502676852bd44
BLAKE2b-256 74f15ae19f3dce3577d9a0f52d8fb54fbed5140e599d45c6ae8410776a55a43e

See more details on using hashes here.

Provenance

The following attestation bundles were made for findcrack-0.0.0.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.0.0-py3-none-any.whl.

File metadata

  • Download URL: findcrack-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 15.4 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.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 639b2a02355afa0a1853c40c2887612686c49dfc6e7110843d72eab92c0c3e6d
MD5 7d4b1835cd64572aa3c2cb1eb07bab38
BLAKE2b-256 6ff23a7ba1a53e05021ef462e84e9b0c4788dbd86a5390fd0d0840d0fd244775

See more details on using hashes here.

Provenance

The following attestation bundles were made for findcrack-0.0.0-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