How patlevin/face-detection-tflite works
Project type and purpose
• This is an open-source Python library (face-detection-tflite) that re-implements parts of Google’s MediaPipe face and iris detection models in pure Python.
• It provides a simple API for:
• Loading a TFLite model (several variants for front/back cameras and different ranges)
• Running inference on an image (via Numpy + PIL + TFLite)
• Post-processing (non-max suppression, coordinate transforms, landmark extraction)
File structure
Top-level:
• README, setup.py, pyproject.toml, etc. – packaging/configuration
• docs/ – user tutorials and examples
• fdlite/ – core library code and data
fdlite/:
• data/ – shipped .tflite model files and auxiliary data (camdb.csv/txt)
• face_detection.py, face_landmark.py, iris_landmark.py – model wrappers
• nms.py – non-max suppression
• transform.py – coordinate conversions between image and model space
• render.py – conversion of detections into drawable primitives
• exif.py – image orientation handling
• types.py – definitions of Detection, Landmark, etc.
• examples/ – sample scripts (e.g. iris_recoloring.py)
• errors.py – custom exception classes
Extract additional insights from README
• Dependencies: numpy, Pillow, TFLite runtime
• No protobuf graphs; lightweight, easily introspectable pipeline
• Models: five face-detection variants + landmark and iris detectors
Main components & interactions
A. Model Loader & Inference
• FaceDetection, FaceLandmark, IrisLandmark classes
• Internally: select .tflite file → initialize TFLite interpreter → allocate tensors
B. Preprocessing
• exif.py reads orientation; transform.py resizes / normalizes image → Numpy array
C. Inference
• Numpy array → TFLite interpreter invoke() → raw output tensors
D. Post-processing
• nms.py performs non-max suppression on raw detections
• types.py packages results into Python objects
E. Rendering
• detections_to_render_data() & render_to_image() in render.py
F. Examples & CLI
• example scripts in fdlite/examples/ demonstrate usage
• docs/tutorial.md explains end-to-end examples
Architectural patterns & design principles
• Modular separation:
• Loader/Inference ↔ Preprocess ↔ Postprocess ↔ Rendering
• Clear layer boundaries: each step is a pure function or class method
• Minimal external dependencies: only numpy, PIL, TFLite runtime
• Extensibility: add new models by dropping .tflite into data/ and wrapping
Elements
• Model Loader & TFLite Interpreter
• Preprocessing (exif + transform)
• Post-processing (nms + transform)
• Data types (types.py)
• Rendering (render.py)
• Data store (fdlite/data/*.tflite)
• External dependencies: Numpy, PIL, TFLite Runtime
• Image file → PIL → Preprocess → Interpreter → Raw tensors → NMS → Detections → Render → Output image
• Orange: external libraries
Detail and clarity
• Core modules vs. resources vs. external libs