Production-ready autonomous vehicle perception system with multimodal ML
Project description
OpenCar
OpenCar is a production-ready autonomous vehicle perception system that combines advanced computer vision, machine learning, and AI to provide real-time object detection, scene analysis, and safety recommendations for autonomous driving applications.
Features
Core Capabilities
- Real-time Object Detection: YOLO-based detection with 90%+ accuracy
- AI-Powered Scene Analysis: GPT-4 Vision integration for comprehensive scene understanding
- Safety Assessment: Real-time hazard detection and safety scoring
- Multi-Modal Processing: Support for images, video streams, and sensor data
- Production-Ready API: FastAPI-based REST API with OpenAPI documentation
Advanced Features
- Async Processing: High-performance async inference engine
- Batch Processing: Efficient batch inference for multiple inputs
- Caching & Optimization: Redis-based caching and model optimization
- Monitoring & Observability: Prometheus metrics, Grafana dashboards, distributed tracing
- Scalable Architecture: Docker containerization with Kubernetes support
Enterprise Features
- Security: JWT authentication, rate limiting, security headers
- Reliability: Health checks, circuit breakers, graceful degradation
- Compliance: GDPR-ready data handling, audit logging
- Integration: OpenAI API, custom model support, webhook notifications
Quick Start
Prerequisites
- Python 3.10+
- Docker & Docker Compose (for containerized deployment)
- CUDA-compatible GPU (optional, for accelerated inference)
Installation
Option 1: pip install (Recommended)
pip install opencar
Option 2: From source
git clone https://github.com/llamasearchai/opencar.git
cd opencar
pip install -e .
Option 3: Docker
docker pull llamasearchai/opencar:latest
docker run -p 8000:8000 llamasearchai/opencar:latest
Basic Usage
CLI Interface
# Initialize a new project
opencar init my-project
# Start the API server
opencar serve --host 0.0.0.0 --port 8000
# Check system status
opencar status
# View system information
opencar info
Python API
import asyncio
from opencar.perception.models.detector import ObjectDetector
from opencar.integrations.openai_client import OpenAIClient
async def main():
# Initialize detector
detector = ObjectDetector()
await detector.initialize()
# Detect objects in image
with open("street_scene.jpg", "rb") as f:
image_data = f.read()
detections = await detector.detect(image_data)
print(f"Found {len(detections)} objects")
# AI scene analysis
client = OpenAIClient(api_key="your-api-key")
analysis = await client.analyze_image(image_data, "safety")
print(f"Safety score: {analysis['safety_score']}")
asyncio.run(main())
REST API
# Health check
curl http://localhost:8000/health
# Object detection
curl -X POST "http://localhost:8000/api/v1/perception/detect" \
-H "Content-Type: multipart/form-data" \
-F "file=@street_scene.jpg"
# Scene analysis
curl -X POST "http://localhost:8000/api/v1/perception/analyze" \
-H "Content-Type: multipart/form-data" \
-F "file=@street_scene.jpg" \
-F "analysis_type=comprehensive"
Documentation
API Reference
Object Detection Endpoint
POST /api/v1/perception/detect
Content-Type: multipart/form-data
Parameters:
- file: Image file (JPEG, PNG)
- confidence_threshold: float (0.0-1.0, default: 0.5)
Response:
{
"request_id": "uuid",
"timestamp": "2024-01-01T00:00:00Z",
"detections": [
{
"class_name": "car",
"confidence": 0.92,
"bbox": {"x1": 100, "y1": 200, "x2": 300, "y2": 400},
"attributes": {"vehicle_type": "sedan"}
}
],
"image_info": {
"filename": "image.jpg",
"size": 1024000,
"content_type": "image/jpeg"
}
}
Scene Analysis Endpoint
POST /api/v1/perception/analyze
Content-Type: multipart/form-data
Parameters:
- file: Image file (JPEG, PNG)
- analysis_type: string (comprehensive|traffic|safety|weather|navigation)
Response:
{
"request_id": "uuid",
"timestamp": "2024-01-01T00:00:00Z",
"analysis": {
"scene_type": "urban",
"objects": ["car", "person", "traffic_light"],
"hazards": [],
"recommendations": ["proceed_normally"],
"safety_score": 0.85,
"weather_conditions": "clear",
"traffic_situation": "normal"
},
"confidence": 0.85,
"analysis_type": "comprehensive"
}
Configuration
Environment Variables
# Core settings
OPENCAR_ENV=production
OPENCAR_DEBUG=false
OPENCAR_LOG_LEVEL=INFO
# API settings
OPENCAR_API_HOST=0.0.0.0
OPENCAR_API_PORT=8000
# Database
OPENCAR_DATABASE_URL=postgresql://user:pass@localhost:5432/opencar
# Redis
OPENCAR_REDIS_URL=redis://localhost:6379/0
# OpenAI
OPENCAR_OPENAI_API_KEY=your-api-key
# Monitoring
OPENCAR_SENTRY_DSN=your-sentry-dsn
Configuration File (opencar.yaml)
project:
name: my-opencar-project
version: 1.0.0
perception:
models:
- yolov8n
- yolov8s
confidence_threshold: 0.5
nms_threshold: 0.4
max_detections: 100
inference:
device: cuda # or cpu
batch_size: 4
use_tensorrt: false
use_onnx: false
api:
cors_origins:
- "http://localhost:3000"
- "https://yourdomain.com"
rate_limit: 100 # requests per minute
max_file_size: 10485760 # 10MB
monitoring:
enable_metrics: true
enable_tracing: true
log_requests: true
๐ณ Docker Deployment
Development
# Start development environment
docker-compose up -d
# View logs
docker-compose logs -f opencar-api
# Stop services
docker-compose down
Production
# Build production image
docker build --target production -t opencar:latest .
# Start production stack
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
# Scale API instances
docker-compose up -d --scale opencar-api=3
Kubernetes
# Deploy to Kubernetes
kubectl apply -f k8s/
# Check deployment status
kubectl get pods -l app=opencar
# View logs
kubectl logs -f deployment/opencar-api
Development
Setup Development Environment
# Clone repository
git clone https://github.com/opencar/opencar.git
cd opencar
# Install development dependencies
pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit install
# Run tests
pytest
# Run with coverage
pytest --cov=opencar --cov-report=html
# Format code
black src/ tests/
ruff check src/ tests/
# Type checking
mypy src/
Project Structure
opencar/
โโโ src/opencar/ # Main package
โ โโโ api/ # FastAPI application
โ โ โโโ routes/ # API endpoints
โ โ โโโ middleware/ # Custom middleware
โ โ โโโ schemas/ # Pydantic models
โ โโโ perception/ # Computer vision models
โ โ โโโ models/ # Detection models
โ โ โโโ processors/ # Image processors
โ โ โโโ utils/ # Utilities
โ โโโ ml/ # Machine learning
โ โ โโโ inference/ # Inference engine
โ โ โโโ training/ # Training utilities
โ โ โโโ optimization/ # Model optimization
โ โโโ integrations/ # External integrations
โ โโโ config/ # Configuration
โ โโโ cli/ # Command-line interface
โโโ tests/ # Test suite
โ โโโ unit/ # Unit tests
โ โโโ integration/ # Integration tests
โโโ docker/ # Docker configurations
โโโ k8s/ # Kubernetes manifests
โโโ docs/ # Documentation
โโโ scripts/ # Utility scripts
Testing
# Run all tests
pytest
# Run specific test categories
pytest tests/unit/
pytest tests/integration/
# Run with markers
pytest -m "not slow"
pytest -m integration
# Generate coverage report
pytest --cov=opencar --cov-report=html
open htmlcov/index.html
Performance Testing
# Benchmark inference
pytest --benchmark-only
# Load testing
locust -f tests/load/locustfile.py --host=http://localhost:8000
Monitoring & Observability
Metrics (Prometheus)
- Request latency and throughput
- Model inference performance
- System resource usage
- Error rates and types
Dashboards (Grafana)
- Real-time performance metrics
- System health overview
- Model accuracy tracking
- Business KPIs
Logging (Structured)
- Request/response logging
- Error tracking with stack traces
- Performance profiling
- Audit trails
Tracing (Jaeger)
- Distributed request tracing
- Performance bottleneck identification
- Service dependency mapping
Security
Authentication & Authorization
- JWT token-based authentication
- Role-based access control (RBAC)
- API key management
- OAuth2 integration
Security Features
- Rate limiting and DDoS protection
- Input validation and sanitization
- Security headers (HSTS, CSP, etc.)
- Encrypted data transmission (TLS)
Compliance
- GDPR-compliant data handling
- SOC 2 Type II controls
- Audit logging and monitoring
- Data retention policies
Production Deployment
Cloud Platforms
AWS
# Deploy with AWS ECS
aws ecs create-cluster --cluster-name opencar-cluster
aws ecs create-service --cluster opencar-cluster --service-name opencar-api
# Deploy with AWS EKS
eksctl create cluster --name opencar-cluster
kubectl apply -f k8s/aws/
Google Cloud
# Deploy with Google Cloud Run
gcloud run deploy opencar-api --image gcr.io/project/opencar:latest
# Deploy with GKE
gcloud container clusters create opencar-cluster
kubectl apply -f k8s/gcp/
Azure
# Deploy with Azure Container Instances
az container create --resource-group opencar-rg --name opencar-api
# Deploy with AKS
az aks create --resource-group opencar-rg --name opencar-cluster
kubectl apply -f k8s/azure/
Performance Optimization
- Model quantization and pruning
- TensorRT optimization for NVIDIA GPUs
- ONNX runtime for cross-platform inference
- Batch processing for improved throughput
Scaling Strategies
- Horizontal pod autoscaling (HPA)
- Vertical pod autoscaling (VPA)
- Cluster autoscaling
- Load balancing with session affinity
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Workflow
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for new functionality
- Ensure all tests pass (
pytest) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Code Standards
- Follow PEP 8 style guidelines
- Add type hints for all functions
- Write comprehensive docstrings
- Maintain test coverage above 80%
- Use conventional commit messages
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- YOLO for object detection models
- OpenAI for GPT-4 Vision API
- FastAPI for the web framework
- Pydantic for data validation
- Docker for containerization
Support
- Email: nikjois@llamasearch.ai
- Documentation: GitHub README
- Issues: GitHub Issues
Made with love by the OpenCar Team
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 opencar-1.0.0.tar.gz.
File metadata
- Download URL: opencar-1.0.0.tar.gz
- Upload date:
- Size: 34.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79d28b85bf3f33c2fbb74310f8fc11e2223309a036e2d6c6b60e3de78134a1bb
|
|
| MD5 |
6d5a8e07dd7b5ab819cb6a5ba43d3a8d
|
|
| BLAKE2b-256 |
2397204d9f0f3e8b9515ed078ba06c839e00228f7e8d48e25f8b5e114c359626
|
File details
Details for the file opencar-1.0.0-py3-none-any.whl.
File metadata
- Download URL: opencar-1.0.0-py3-none-any.whl
- Upload date:
- Size: 33.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7f208dde3b8d4639d20e387d682a111d855f25b4126a025294512147f4f2275
|
|
| MD5 |
413a94cbc41450d0d28e2e7a31e1713f
|
|
| BLAKE2b-256 |
d7ab113423da8781e68b91fb4c9a07a6b1e350785778e6502b376325cd821ff2
|