Person Classification TensorFlow Lite Models
Model Description
These are quantized TensorFlow Lite models designed for binary person classification (person vs. non-person) optimized for embedded deployment on microcontrollers, specifically targeting the Astra MCU SDK platform.
The models perform real-time object detection and classification, analyzing camera feed inputs to accurately identify human presence within the field of view.
Model Variants
This repository contains two optimized model variants for different deployment scenarios:
1. Flash Memory Model
- File:
person_classification_flash(448x640).tflite
- Input Resolution: VGA (640ร480ร3)
- Target: Flash memory deployment for higher resolution processing
- Use Case: Applications requiring higher accuracy with sufficient flash storage
- Memory Requirement: Model stored in flash memory
2. SRAM Model
- File:
person_classification_sram(256x448).tflite
- Input Resolution: WQVGA (480ร270ร3)
- Target: SRAM deployment for memory-constrained environments
- Use Case: Real-time applications with limited memory footprint
- Memory Requirement: Model stored in SRAM for faster access
Technical Specifications
Input Format
- Data Type:
uint8
(quantized RGB values 0-255) - Channel Order: RGB
- Normalization: No additional normalization required (quantized model)
Flash Model Input Shape: [1, 480, 640, 3]
(921,600 total values)
SRAM Model Input Shape: [1, 270, 480, 3]
(388,800 total values)
Output Format
- Task: Binary classification
- Output: Single probability score
- Classes:
- 0: Non-person
- 1: Person
- Data Type: Quantized output (requires dequantization for probability)
Model Optimization
- Quantization: 8-bit quantization for embedded deployment
- Model Size: ~1.5MB each (highly optimized for MCU deployment)
- Target Hardware: ARM Cortex-M55 with Ethos-U55 NPU
- Framework: TensorFlow Lite for Microcontrollers
Usage Example
import tensorflow as tf
import numpy as np
from PIL import Image
def load_model(model_path):
"""Load TensorFlow Lite model"""
interpreter = tf.lite.Interpreter(model_path=model_path)
interpreter.allocate_tensors()
return interpreter
def preprocess_image(image_path, target_size):
"""Preprocess input image"""
image = Image.open(image_path).convert('RGB')
image = image.resize(target_size)
image_array = np.array(image, dtype=np.uint8)
return np.expand_dims(image_array, axis=0) # Add batch dimension
def classify_person(interpreter, image_data):
"""Run inference on the model"""
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
interpreter.set_tensor(input_details[0]['index'], image_data)
interpreter.invoke()
output_data = interpreter.get_tensor(output_details[0]['index'])
# Dequantize output if needed
scale = output_details[0]['quantization'][0]
zero_point = output_details[0]['quantization'][1]
if scale != 0: # Quantized output
dequantized_output = scale * (output_data.astype(np.float32) - zero_point)
probability = 1 / (1 + np.exp(-dequantized_output[0])) # Apply sigmoid
else:
probability = output_data[0]
return probability
# Example usage
# For Flash model (VGA resolution)
interpreter_flash = load_model("person_classification_flash(448x640).tflite")
image_data_vga = preprocess_image("test_image.jpg", (640, 480))
result_flash = classify_person(interpreter_flash, image_data_vga)
# For SRAM model (WQVGA resolution)
interpreter_sram = load_model("person_classification_sram(256x448).tflite")
image_data_wqvga = preprocess_image("test_image.jpg", (480, 270))
result_sram = classify_person(interpreter_sram, image_data_wqvga)
print(f"Flash model prediction: {result_flash:.3f}")
print(f"SRAM model prediction: {result_sram:.3f}")
Performance Characteristics
Memory Requirements
- Flash Model: Designed for devices with sufficient flash storage
- SRAM Model: Optimized for memory-constrained microcontrollers
- Inference Memory: Minimal tensor arena requirements due to quantization
Deployment Targets
- Primary Platform: Astra MCU SDK with ARM Cortex-M55 + Ethos-U55 NPU
- Compatible: Any TensorFlow Lite Micro compatible microcontroller
- Resolution Support: Multiple input resolutions for different use cases
Real-World Applications
- Security and surveillance systems
- Smart home automation
- IoT edge devices
- Battery-powered computer vision applications
- Real-time person detection in embedded systems
Deployment Guide
For Astra MCU SDK:
Model Selection:
- Use Flash model for VGA resolution applications
- Use SRAM model for memory-constrained or real-time applications
Integration:
- Place model file in your project's model directory
- Configure input resolution in your application
- Set up camera interface for chosen resolution
Memory Configuration:
- Flash model: Configure flash memory allocation
- SRAM model: Ensure sufficient SRAM for model weights
Build Configuration:
# For WQVGA (SRAM model) make cm55_person_classification_defconfig # For VGA (Flash model) - modify via menuconfig make menuconfig # Navigate to: COMPONENTS CONFIGURATION โ Off Chip Components โ Display Resolution # Change to: VGA(640x480)
General TensorFlow Lite Deployment:
# Install dependencies
# pip install tensorflow numpy pillow
import tensorflow as tf
# Load and run model
interpreter = tf.lite.Interpreter(model_path="person_classification_sram(256x448).tflite")
interpreter.allocate_tensors()
# Get input and output tensors
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
# Run inference
interpreter.set_tensor(input_details[0]['index'], input_data)
interpreter.invoke()
output_data = interpreter.get_tensor(output_details[0]['index'])
Model Selection Guide
Use Case | Model Variant | Resolution | Memory | Best For |
---|---|---|---|---|
High Accuracy | Flash Model | 640ร480 | Flash storage | Security cameras, detailed detection |
Real-time Processing | SRAM Model | 480ร270 | SRAM storage | IoT devices, battery-powered applications |
Memory Constrained | SRAM Model | 480ร270 | Low memory | Microcontrollers with limited resources |
General Purpose | Both | Variable | Flexible | Development and prototyping |
Requirements
- TensorFlow Lite runtime (2.13.0+)
- NumPy for data processing
- PIL/Pillow for image handling
- Target hardware with TensorFlow Lite Micro support
Citation
If you use these models in your research or applications, please cite:
@misc{person_classification_tflite_2024,
title={Person Classification TensorFlow Lite Models for Embedded Deployment},
author={Astra MCU SDK Team},
year={2024},
publisher={Hugging Face},
url={https://huggingface.co/JahnaviBhansali/person-classification-tflite}
}
License
Licensed under the Apache License 2.0. See LICENSE file for details.
Related Resources
These models are optimized for embedded deployment and provide an excellent starting point for person detection applications on resource-constrained devices.
- Downloads last month
- 3
Evaluation results
- Binary Classificationself-reportedOptimized for embedded deployment
- Binary Classificationself-reportedOptimized for SRAM deployment