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:
- Automatic Download: The model will be automatically downloaded from the configured repository on first use
- Local Model: Provide a local path to an existing model file
- The package automatically attempts to download the
model.onnxfile 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_TOKENenvironment variable or direct token provision
Error Handling
The package provides specific error types for better error handling:
ModelDownloadError: Issues with model downloadingImageLoadError: Problems with image loading or preprocessingInferenceError: Issues during model inferenceFloorplanPredictorError: Base class for all package errors
Common Errors & Troubleshooting
-
ModelDownloadError: ... 404 Not Found ...:- Check if the
GITHUB_TOKENenvironment variable is set correctly (if accessing a private repo) - Verify the token is valid, not expired, and has the
reposcope enabled - Confirm the repository and model path settings are correct
- Check if the
-
ModelDownloadError: ... 403 Forbidden ...:- Usually indicates the provided
GITHUB_TOKENlacks necessary permissions
- Usually indicates the provided
-
FloorplanPredictorError: GITHUB_TOKEN is required...:- Set the
GITHUB_TOKENenvironment variable for private repository access
- Set the
-
FileNotFoundErrororImageLoadError:- Ensure the image path is correct and the file exists
- Verify the image format is supported (JPEG, PNG, etc.)
-
ONNX Runtime Issues:
- Ensure
onnxruntimeis installed correctly for your OS - Check Python version compatibility
- Ensure
Running Tests (Development)
- Clone the repository
- Install development dependencies:
pip install -r requirements.txt - Set the
GITHUB_TOKENenvironment variable if testing with private repo - Place test images in the root directory
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
097ca45765638471297df4deebcea2f89b3576efdb81dfab59d3a56b20c27a3a
|
|
| MD5 |
db3831ba2c9a474510117300579c1ee5
|
|
| BLAKE2b-256 |
6d7faaf426bcdf280aad970611859b60ecd6bddef7ee6c8e3696d6bba87d23d9
|
File details
Details for the file floorplan_epc_detector-1.1.2-py3-none-any.whl.
File metadata
- Download URL: floorplan_epc_detector-1.1.2-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22c48d17d3df974aed301d902ab5b80cb092a0dccf02d19248cda53b733b760f
|
|
| MD5 |
05874b07c88c82a863450c4fd6b86675
|
|
| BLAKE2b-256 |
cdd790621607d9519c35160c399ea9daa8da3c457dc5aab369d7a27eff9ce410
|