02. Raspberry Pi Setup
Raspberry Pi serves as the standard entry point for edge AI experimentation. The Pi 4 Model B with 4GB RAM provides a reproducible baseline: 64-bit ARM Cortex-A72, VideoCore VI GPU with 1 TOPS throughput, and USB 3.0 storage interface. This configuration runs most quantized models at interactive speeds.
Initial setup requires flashing a 64-bit operating system. Ubuntu Server 22.04 LTS outperforms Raspberry Pi OS for ML workloads due to optimized BLAS libraries and better compiler toolchain support. The flashing command:
# Download Ubuntu Server 22.04 LTS 64-bit
wget https://cdimage.ubuntu.com/ubuntu-server/jammy/daily-bootleg/zCuZnvLAUFBZbdmtJrkjLS6aGJKqdpVGa_los_3.04.2023.img.xz
# Flash to SD card (replace /dev/sdX with actual device)
xzcat zCuZnvLAUFBZbdmtJrkjLS6aGJKqdpVGa_los_3.04.2023.img.xz | sudo dd of=/dev/sdX bs=4M status=progress
After initial boot, configure config.txt to enable hardware video encoding if using camera inputs. Add these lines to /boot/firmware/config.txt:
# Enable hardware codecs
start_x=1
gpu_mem=128
Memory allocation deserves serious attention. Setting gpu_mem=128 reserves 128MB for GPU operations—necessary for camera pipelines but reduces available RAM. For pure CPU inference with 4GB total RAM, gpu_mem=16 suffices.
Common post-installation failures include thermal throttling and SD card corruption. The Pi 4 throttles at 80°C core temperature, dropping from 1.5GHz to 1.0GHz. Installing a heatsink and fan drops sustained operating temperature by 15-20°C. SD card corruption manifests as filesystem errors appearing weeks after deployment—always use high-endurance industrial SD cards (Samsung Pro Endurance or similar) for production.
Python environment setup requires separate virtualenv for ML dependencies to avoid system package conflicts:
sudo apt update && sudo apt install -y python3.10-venv libgomp1
python3 -m venv ~/venv-ml
source ~/venv-ml/bin/activate
pip install --upgrade pip setuptools wheel
pip install numpy scipy onnxruntime quantization-lib
Local verification checkpoint
Run the smallest example from this chapter in a local workspace and record the package version, runtime, data path, and observed output. If the result depends on model size, vector count, CPU/GPU backend, or available memory, note that constraint beside the exercise so the lesson remains reproducible.
Configure a Raspberry Pi 4 with Ubuntu Server, verify CPU governor settings (cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor), and install a 64-bit Python ML environment.