EPC Floorplan Image Detection
A Python package for classifying images as EPCs, floorplans, property photos, or exterior shots using SAM-CLIP, a state-of-the-art vision model that combines Segment Anything Model (SAM) with Contrastive Language-Image Pre-Training (CLIP).
What's New in Version 2.0.0
Major update replacing the YOLO-based classifier with SAM-CLIP for improved accuracy and robustness:
- SAM-CLIP Integration: Leverages both semantic segmentation and visual-language understanding
- Improved Accuracy: Better handling of complex layouts and variations in image styles
- More Robust: Enhanced performance on edge cases and unusual image formats
- Zero-shot Capabilities: Potential for recognizing new image types without retraining
Quick Start Guide
Get started with image classification in just a few steps:
-
Install the package:
pip install floorplan-epc-detector==2.0.0
-
Basic Usage:
from floorplan_epc_detector import FloorplanPredictor # Initialize the predictor (models will be downloaded automatically) predictor = FloorplanPredictor() # Classify a single image prediction, confidence = predictor.predict_with_confidence( "path/to/your/image.jpg", confidence_threshold=0.7 ) print(f"Image Type: {prediction}") print(f"Confidence: {confidence:.2%}")
-
Batch Processing Example:
# Process multiple images images = [ "image1.jpg", "image2.png", "floor_plan.jpeg" ] for image_path in images: # Get detailed probabilities probs = predictor.get_raw_probabilities(image_path) print(f"\nAnalyzing: {image_path}") print(f"Probabilities: {probs}") # Get final prediction prediction, confidence = predictor.predict_with_confidence( image_path, confidence_threshold=0.7 ) print(f"Predicted Type: {prediction}") print(f"Confidence: {confidence:.2%}")
-
Understanding Results:
- The predictor classifies images into 4 categories:
epc: Energy Performance Certificatefloorplan: Floor Plansinterior: Interior Property Photosexterior: Exterior Property Photos
- Confidence scores range from 0 to 1 (shown as percentages)
- The default confidence threshold is 0.7 (70%)
- The predictor classifies images into 4 categories:
-
Best Practices:
- Use clear, well-lit images
- Ensure images are readable and not corrupted
- Higher resolution images generally work better
- Supported formats: JPG, JPEG, PNG
- For batch processing, handle each image's results individually
Prerequisites
- Python 3.7 or higher
Installation
pip install floorplan-epc-detector==2.0.0
Real-World Example
Here's a complete example showing how to process multiple images and handle results:
import os
from floorplan_epc_detector import FloorplanPredictor
# Initialize predictor
predictor = FloorplanPredictor()
# List of images to process
test_images = [
"property_photo.jpeg",
"epc_certificate.png",
"house_floorplan.jpg"
]
# Process each image
for image_name in test_images:
if not os.path.exists(image_name):
print(f"Image not found: {image_name}")
continue
print(f"\nAnalyzing image: {image_name}")
try:
# Get detailed classification probabilities
raw_probabilities = predictor.get_raw_probabilities(image_name)
print(f"Detailed probabilities:")
for class_name, prob in raw_probabilities.items():
print(f" {class_name}: {prob:.2%}")
# Get final prediction with confidence
prediction, confidence = predictor.predict_with_confidence(
image_name,
confidence_threshold=0.7
)
print(f"Final Result:")
print(f" Type: {prediction}")
print(f" Confidence: {confidence:.2%}")
except Exception as e:
print(f"Error processing {image_name}: {e}")
This example shows:
- How to handle multiple images
- Error handling for missing files
- Getting detailed classification probabilities
- Making final predictions with confidence scores
- Proper formatting of results
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
- onnxruntime-extensions
- numpy >= 1.19.0
- torch >= 2.0.0
- torchvision >= 0.15.0
- huggingface-hub
- sentencepiece
- opencv-python-headless
- ftfy
- regex
- scipy
- gdown
- Pillow >= 10.0.0
- tqdm >= 4.65.0
License
MIT License
Author
Oliver Brown
Metadata
Release files for floorplan-epc-detector 2.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| floorplan_epc_detector-2.0.5.tar.gz | 6.9 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| floorplan_epc_detector-2.0.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.9 MB
Release files / floorplan_epc_detector-2.0.5.tar.gz
| Download URL | floorplan_epc_detector-2.0.5.tar.gz |
|---|---|
| Size | 6.9 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aff9a1ec091c56bf9073148ace21c6b1576acaf52d16d40b7a966837ff137ca4
|
|
BLAKE2b-256 checksum How to use checksums |
45c6270647b27825688fa048294c6fbf38964b9e44def03f6329956c84d40ccd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.11
|
Release files / floorplan_epc_detector-2.0.5-py3-none-any.whl
| Download URL | floorplan_epc_detector-2.0.5-py3-none-any.whl |
|---|---|
| Size | 6.9 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
085ebdc587cefd1223f0229eef7c610f2db782777d3d6bb8fb12ed1e56d273ae
|
|
BLAKE2b-256 checksum How to use checksums |
9f5290d67c7abe996b30584076d5848dfd51dc39ab2eced58354dba7f9e30ba1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.11
|