Readme
Image Orientation Detection Model
This model identifies the orientation of images, determining whether they are rotated 0°, 90°, 180°, or 270°. It uses a fine-tuned ResNet152 architecture to automatically detect the correct orientation with high accuracy.
Overview
The Image Orientation Detection model solves a common problem in image processing pipelines: automatically determining and correcting image orientation. Whether you’re building an OCR system, processing scanned documents, or organizing a photo collection, having properly oriented images is essential.
This model has been trained on a diverse dataset of images to recognize the natural orientation based on visual cues such as: - Text orientation - Horizon lines - Portrait/landscape recognition - Faces and object positioning
How It Works
The model uses a fine-tuned ResNet152 architecture converted to ONNX format for optimal performance. When an image is submitted, it:
- Preprocesses the image (resizes and normalizes)
- Runs inference through the ONNX model
- Returns the predicted orientation angle (0°, 90°, 180°, or 270°)
For improved accuracy, the model can optionally use a rotation averaging technique that evaluates the image from multiple rotated perspectives and combines the results.
Usage
Basic Usage
import replicate
output = replicate.run(
"grace-raper/resnet-rot:latest",
input={"image": open("path/to/your_image.jpg", "rb")}
)
print(f"The image is rotated {output['best_angle']} degrees.")
Advanced Options
output = replicate.run(
"grace-raper/resnet-rot:latest",
input={
"image": open("path/to/your_image.jpg", "rb"),
"return_probabilities": True,
"use_rotation_averaging": True
}
)
print(f"Best angle: {output['best_angle']} degrees")
print(f"Confidence scores: {output['probabilities']}")
API Reference
Input Parameters
Parameter | Type | Default | Description |
---|---|---|---|
image |
file | Required | The image file to analyze |
return_probabilities |
boolean | false |
When true, returns probability scores for all possible orientations |
use_rotation_averaging |
boolean | false |
When true, uses multiple rotated views of the image to improve accuracy |
Output Format
Standard output:
{
"best_angle": 90
}
With return_probabilities=true
:
{
"best_angle": 90,
"probabilities": {
"0": 0.021,
"90": 0.965,
"180": 0.008,
"270": 0.006
}
}
Use Cases
- Document Processing: Automatically correct the orientation of scanned documents before OCR
- Photo Organization: Ensure all images in a collection have the correct orientation
- Content Moderation: Preprocess user-uploaded images to ensure consistent orientation
- Data Preparation: Normalize image orientation for machine learning datasets
Model Details
- Architecture: ResNet152 converted to ONNX format
- Input Size: 224x224 pixels (images are automatically resized)
- Model Size: ~60MB
- Runtime: GPU-optimized, with CPU fallback
Limitations
- Performance may vary with extremely unusual images or images without clear orientation cues
- Very small images or images with uniform patterns may be challenging to orient correctly
- The model detects orientation in 90-degree increments only (0°, 90°, 180°, 270°)
Feedback and Contributions
For issues, questions, or feedback about this model, please open an issue in the GitHub repository.
License
This model uses weights from the ResNet-Ixion project and is available for research and commercial use under the terms of the Apache 2.0 license.