Views
No views yet
person_classification_flash(448x640).tfliteperson_classification_sram(256x448).tfliteuint8 (quantized RGB values 0-255)[1, 480, 640, 3] (921,600 total values)
SRAM Model Input Shape: [1, 270, 480, 3] (388,800 total values)1import tensorflow as tf
2import numpy as np
3from PIL import Image
4
5def load_model(model_path):
6 """Load TensorFlow Lite model"""
7 interpreter = tf.lite.Interpreter(model_path=model_path)
8 interpreter.allocate_tensors()
9 return interpreter
10
11def preprocess_image(image_path, target_size):
12 """Preprocess input image"""
13 image = Image.open(image_path).convert('RGB')
14 image = image.resize(target_size)
15 image_array = np.array(image, dtype=np.uint8)
16 return np.expand_dims(image_array, axis=0) # Add batch dimension
17
18def classify_person(interpreter, image_data):
19 """Run inference on the model"""
20 input_details = interpreter.get_input_details()
21 output_details = interpreter.get_output_details()
22
23 interpreter.set_tensor(input_details[0]['index'], image_data)
24 interpreter.invoke()
25
26 output_data = interpreter.get_tensor(output_details[0]['index'])
27
28 # Dequantize output if needed
29 scale = output_details[0]['quantization'][0]
30 zero_point = output_details[0]['quantization'][1]
31
32 if scale != 0: # Quantized output
33 dequantized_output = scale * (output_data.astype(np.float32) - zero_point)
34 probability = 1 / (1 + np.exp(-dequantized_output[0])) # Apply sigmoid
35 else:
36 probability = output_data[0]
37
38 return probability
39
40# Example usage
41# For Flash model (VGA resolution)
42interpreter_flash = load_model("person_classification_flash(448x640).tflite")
43image_data_vga = preprocess_image("test_image.jpg", (640, 480))
44result_flash = classify_person(interpreter_flash, image_data_vga)
45
46# For SRAM model (WQVGA resolution)
47interpreter_sram = load_model("person_classification_sram(256x448).tflite")
48image_data_wqvga = preprocess_image("test_image.jpg", (480, 270))
49result_sram = classify_person(interpreter_sram, image_data_wqvga)
50
51print(f"Flash model prediction: {result_flash:.3f}")
52print(f"SRAM model prediction: {result_sram:.3f}")1# For WQVGA (SRAM model)
2make cm55_person_classification_defconfig
3
4# For VGA (Flash model) - modify via menuconfig
5make menuconfig
6# Navigate to: COMPONENTS CONFIGURATION → Off Chip Components → Display Resolution
7# Change to: VGA(640x480)1# Install dependencies
2# pip install tensorflow numpy pillow
3
4import tensorflow as tf
5
6# Load and run model
7interpreter = tf.lite.Interpreter(model_path="person_classification_sram(256x448).tflite")
8interpreter.allocate_tensors()
9
10# Get input and output tensors
11input_details = interpreter.get_input_details()
12output_details = interpreter.get_output_details()
13
14# Run inference
15interpreter.set_tensor(input_details[0]['index'], input_data)
16interpreter.invoke()
17output_data = interpreter.get_tensor(output_details[0]['index'])| 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 |
1@misc{person_classification_tflite_2024,
2 title={Person Classification TensorFlow Lite Models for Embedded Deployment},
3 author={Astra MCU SDK Team},
4 year={2024},
5 publisher={Hugging Face},
6 url={https://huggingface.co/JahnaviBhansali/person-classification-tflite}
7}