Skip to main content

A package for making predictions using a custom-trained ONNX floorplan/epc/proprty_image model

Project description

Smart Floorplan Predictor

A Python package for classifying images as EPCs, floorplans, property photos, or exterior shots using a pre-trained ONNX model.

Prerequisites

  • Python 3.7 or higher

Installation

pip install floorplan-epc-detector

Features

  • Image Classification into 4 categories:
    • EPC (Energy Performance Certificate)
    • Floorplans
    • Property Interior Images
    • Property Exterior Images
  • Confidence Scoring
  • Automatic model download from private/public repositories
  • Progress bar for model downloads
  • Configurable confidence thresholds
  • Raw probability access for advanced use cases

Usage

import os
from floorplan_epc_detector import FloorplanPredictor, FloorplanPredictorError

# --- Configuration for Private Repositories --- 
# If the model is hosted in a private GitHub repository, 
# you MUST provide a GitHub Personal Access Token (PAT).
# Set it as an environment variable:
# export GITHUB_TOKEN="your_github_pat_here"
# Ensure the token has the 'repo' scope to access private repository content.

github_token = os.environ.get("GITHUB_TOKEN")

try:
    # Initialize the predictor with options
    predictor = FloorplanPredictor(
        github_token=github_token,  # Optional: For private repos
        model_path="custom/path/model.onnx",  # Optional: Custom model path
        skip_download=False  # Optional: Skip auto-download
    )

    # Basic prediction (returns just the class)
    predicted_class = predictor.predict("path/to/your/image.jpg")
    print(f"Predicted Class: {predicted_class}")

    # Prediction with confidence score
    predicted_class, confidence = predictor.predict_with_confidence(
        "path/to/your/image.jpg",
        confidence_threshold=0.7  # Optional: Default is 0.7
    )
    print(f"Predicted Class: {predicted_class}")
    print(f"Confidence: {confidence:.2%}")

    # Get raw probabilities for all classes
    probabilities = predictor.get_raw_probabilities("path/to/your/image.jpg")
    print("Raw probabilities:", probabilities)

except FloorplanPredictorError as e:
    print(f"An error occurred: {e}")
    # Handle specific errors:
    # - ModelDownloadError
    # - ImageLoadError
    # - InferenceError

Model Downloading

The package supports two ways to use the model:

  1. Automatic Download: The model will be automatically downloaded from the configured repository on first use
  2. Local Model: Provide a local path to an existing model file
  • The package automatically attempts to download the model.onnx file using the GitHub API if it's not found locally
  • Progress bar shows download progress for large model files
  • Supports Git LFS for efficient model file handling
  • Private Repositories: Downloading from private GitHub repositories requires a GITHUB_TOKEN environment variable or direct token provision

Error Handling

The package provides specific error types for better error handling:

  • ModelDownloadError: Issues with model downloading
  • ImageLoadError: Problems with image loading or preprocessing
  • InferenceError: Issues during model inference
  • FloorplanPredictorError: Base class for all package errors

Common Errors & Troubleshooting

  • ModelDownloadError: ... 404 Not Found ...:

    • Check if the GITHUB_TOKEN environment variable is set correctly (if accessing a private repo)
    • Verify the token is valid, not expired, and has the repo scope enabled
    • Confirm the repository and model path settings are correct
  • ModelDownloadError: ... 403 Forbidden ...:

    • Usually indicates the provided GITHUB_TOKEN lacks necessary permissions
  • FloorplanPredictorError: GITHUB_TOKEN is required...:

    • Set the GITHUB_TOKEN environment variable for private repository access
  • FileNotFoundError or ImageLoadError:

    • Ensure the image path is correct and the file exists
    • Verify the image format is supported (JPEG, PNG, etc.)
  • ONNX Runtime Issues:

    • Ensure onnxruntime is installed correctly for your OS
    • Check Python version compatibility

Running Tests (Development)

  1. Clone the repository
  2. Install development dependencies: pip install -r requirements.txt
  3. Set the GITHUB_TOKEN environment variable if testing with private repo
  4. Place test images in the root directory
  5. Run the test script: python test.py

Requirements

  • Python >= 3.7
  • onnxruntime >= 1.12.0
  • numpy >= 1.19.0
  • requests >= 2.25.0
  • Pillow >= 10.0.0
  • tqdm >= 4.65.0

License

MIT License

Author

Oliver Brown

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

floorplan_epc_detector-1.1.2.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

floorplan_epc_detector-1.1.2-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file floorplan_epc_detector-1.1.2.tar.gz.

File metadata

  • Download URL: floorplan_epc_detector-1.1.2.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for floorplan_epc_detector-1.1.2.tar.gz
Algorithm Hash digest
SHA256 097ca45765638471297df4deebcea2f89b3576efdb81dfab59d3a56b20c27a3a
MD5 db3831ba2c9a474510117300579c1ee5
BLAKE2b-256 6d7faaf426bcdf280aad970611859b60ecd6bddef7ee6c8e3696d6bba87d23d9

See more details on using hashes here.

File details

Details for the file floorplan_epc_detector-1.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for floorplan_epc_detector-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 22c48d17d3df974aed301d902ab5b80cb092a0dccf02d19248cda53b733b760f
MD5 05874b07c88c82a863450c4fd6b86675
BLAKE2b-256 cdd790621607d9519c35160c399ea9daa8da3c457dc5aab369d7a27eff9ce410

See more details on using hashes here.

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