This directory contains the test suite for faster_coco_eval, which validates that the library produces identical results to pycocotools while being significantly faster.
- test_basic.py - Basic COCO evaluation functionality
- test_coco_metric.py - COCO metrics with pycocotools comparison (small examples)
- test_keypoints.py - Keypoint evaluation
- test_cocoapi_fake_data.py - Tests with synthetic data
- test_extensive_pycocotools_comparison.py - NEW: Comprehensive validation against pycocotools with large synthetic datasets
- test_lvis_metric.py - LVIS dataset support
- test_crowdpose.py - CrowdPose keypoints dataset
- test_init_pycocotools.py - Drop-in replacement compatibility
- test_torchmetrics.py - PyTorch integration (if available)
- test_mask_api.py - Mask utilities
- test_boundary.py - Boundary evaluation
- test_extra_draw.py, test_extra_utils.py, test_simple_extra.py - Visualization features
- test_ranges.py, test_dataset.py - Utility functions
The test_extensive_pycocotools_comparison.py module provides comprehensive validation that faster_coco_eval produces identical results to pycocotools across a wide range of scenarios.
Tests bounding box detection with datasets of varying sizes:
- Small dataset: 10 images, 5 categories, ~50 annotations
- Medium dataset: 50 images, 10 categories, ~500 annotations
- Large dataset: 100 images, 20 categories, ~1500 annotations
Each test validates that both libraries produce identical mAP, mAP@50, mAP@75, and size-specific metrics (small/medium/large objects).
Tests segmentation masks with the same dataset size variations as bbox tests. Validates pixel-level mask IoU calculations match exactly between implementations.
Tests keypoint pose estimation with datasets containing:
- Small dataset: 10 images with 17 keypoints per person
- Medium dataset: 50 images with multiple people per image
- Large dataset: 100 images with varied keypoint visibility
Validates that OKS (Object Keypoint Similarity) calculations are identical.
- Perfect predictions: All predictions match ground truth exactly (IoU=1.0)
- Low confidence predictions: Tests with very low-scoring detections
- Mixed object sizes: Validates correct assignment to small/medium/large categories
The tests use synthetic but realistic COCO-formatted datasets that mimic actual model predictions:
- Varied image sizes: Random dimensions between 400x400 and 800x800 pixels
- Realistic bounding boxes: Objects categorized as small (<32²), medium (32²-96²), or large (>96²)
- Segmentation masks: RLE-encoded binary masks matching bbox regions
- Keypoint annotations: 17 keypoints per instance with realistic visibility flags
- Prediction noise: Simulated detection errors with bbox jitter and confidence scores
- False positives: Includes spurious detections to test precision/recall
Run all extensive comparison tests:
cd tests/
pytest test_extensive_pycocotools_comparison.py -vRun specific test categories:
# Only bbox tests
pytest test_extensive_pycocotools_comparison.py -k "bbox" -v
# Only segmentation tests
pytest test_extensive_pycocotools_comparison.py -k "segmentation" -v
# Only keypoint tests
pytest test_extensive_pycocotools_comparison.py -k "keypoints" -v
# Only large dataset tests
pytest test_extensive_pycocotools_comparison.py -k "large" -vTests pass if and only if:
- All metrics (mAP, mAP@50, mAP@75, mAP_small, mAP_medium, mAP_large, etc.) are numerically identical between
faster_coco_evalandpycocotools - Floating-point comparison uses tolerance of
1e-10(essentially exact) - All intermediate calculations (IoU, OKS) produce identical results
These extensive tests address the requirement for confidence in correctness when using faster_coco_eval as a drop-in replacement for pycocotools:
- Broader coverage: Tests hundreds to thousands of annotations vs. single-digit examples in original tests
- Real-world scenarios: Synthetic data mimics actual model predictions with realistic error patterns
- All task types: Validates bbox, segmentation, and keypoints independently
- Edge cases: Ensures correct behavior in corner cases that might not appear in small datasets
- Continuous validation: Runs in CI/CD to catch any regression in numerical accuracy
Run the complete test suite:
cd tests/
pytest --cov=faster_coco_eval .Run tests for a specific Python version (CI/CD runs Python 3.9-3.13):
pytest --cov=faster_coco_eval . -vInstall test dependencies:
pip install "faster-coco-eval[tests]"Or from source:
cd /path/to/faster_coco_eval
pip install -e ".[tests]"Required packages:
pytest- Test frameworkpytest-cov- Coverage reportingparameterized- Parameterized test casespycocotools- Original COCO API for comparison testsnumpy- Numerical operations
When adding new features to faster_coco_eval, please:
- Add corresponding tests that validate exact equality with
pycocotoolsbehavior - Use parameterized tests to cover multiple scenarios efficiently
- Generate synthetic test data programmatically for reproducibility
- Set
np.random.seed()for deterministic test data - Document what each test validates and why it's important