Skip to content

Latest commit

 

History

History
279 lines (199 loc) · 6.33 KB

File metadata and controls

279 lines (199 loc) · 6.33 KB

Edgeai-app-python Object Detection

This folder is a laptop-native Python rewrite of the original TI edgeai-tiovx-apps object-detection flow.

It keeps the high-level application behavior:

  • read frames from a camera
  • run an object detection model
  • draw labels and bounding boxes
  • display the annotated result
  • optionally save the annotated video

It removes the TI board dependencies. See TI_DEPENDENCIES_REMOVED.md.

Application Preview

Edgeai-app-python object detection preview

Project Layout

edgeai-app-python/
├── app.py
├── apps/
│   └── src/
│       ├── app_runtime.py
│       ├── deep_learning_block.py
│       ├── input_block.py
│       ├── misc.py
│       ├── output_block.py
│       └── resize_block.py
├── assets/
│   └── app-screenshot.png
├── configs/
│   └── linux/
│       └── object_detection.yaml
├── models/
├── modules/
│   ├── mosaic.py
│   └── video_sources.py
├── ORIGINAL_TO_PYTHON_MAPPING.md
├── outputs/
├── requirements.txt
├── scripts/
├── src/
├── utils/
└── TI_DEPENDENCIES_REMOVED.md

Setup

From this folder:

sudo apt update
sudo apt install -y python3-tk
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt

TI-Style CMake Build

The original TI edgeai-tiovx-apps CMake build compiles C/C++ sources and creates a runnable binary such as:

bin/Release/edgeai-tiovx-apps-main

This Python rewrite does not need compilation, but its CMake build stages a runnable launcher in the same style:

bin/Release/edgeai-app-python-main

Install packaging tools:

sudo apt update
sudo apt install -y cmake build-essential

Configure and build:

cmake -S . -B build
cmake --build build

Run it like the original TI app:

./bin/Release/edgeai-app-python-main configs/linux/object_detection.yaml

Install it with CMake:

sudo cmake --install build

This installs the application files to:

<install-prefix>/share/edgeai-app-python

and installs command-line launchers to:

<install-prefix>/bin/edgeai-app-python
<install-prefix>/bin/edgeai-app-python-main

Run after CMake install:

edgeai-app-python-main configs/linux/object_detection.yaml

Build a Debian Package

The original TI edgeai-tiovx-apps CMake files install binaries and libraries, but this repo does not appear to include CPack or .deb package generation. This Python rewrite keeps the TI-style build above and also adds CMake/CPack support for creating a local Ubuntu .deb.

Build the package:

cmake -S . -B build
cmake --build build --target package

The .deb will be created under build/, for example:

build/edgeai-app-python_1.0.0_all.deb

Install it:

sudo apt install ./build/edgeai-app-python_1.0.0_all.deb

The package installs the app to:

/usr/share/edgeai-app-python

and installs this launcher:

/usr/bin/edgeai-app-python
/usr/bin/edgeai-app-python-main

Install the Python runtime dependencies after installing the package:

cd /usr/share/edgeai-app-python
sudo python3 -m venv .venv
sudo .venv/bin/pip install --upgrade pip
sudo .venv/bin/pip install -r requirements.txt

Run the installed app:

edgeai-app-python

Or pass an explicit config/model:

edgeai-app-python configs/linux/object_detection.yaml --model /path/to/weights.pt

When running the installed .deb launcher, pass an absolute path for models that live outside the installed app directory:

edgeai-app-python configs/linux/object_detection.yaml --model /home/user/models/model.onnx

Uninstall:

sudo apt remove edgeai-app-python

Model Weights

The default model is configured in configs/linux/object_detection.yaml:

models:
  model0:
    model_path: yolov8n.pt

By default, it uses:

yolov8n.pt

Ultralytics downloads this model automatically on first run. The app automatically selects the inference engine by model extension:

  • .pt: Ultralytics/PyTorch
  • .onnx or .onnc: ONNXRuntime

To use your own weights, pass the path manually:

python app.py configs/linux/object_detection.yaml --model /path/to/weights.pt
python app.py configs/linux/object_detection.yaml --model /path/to/model.onnx

Or make it the default by changing models.model0.model_path in configs/linux/object_detection.yaml:

models:
  model0:
    model_path: models/my_model.onnx

For ONNX models with custom classes, add labels to the model block in the YAML:

class_names: [person, bicycle, car]

Run Webcam Inference

python app.py configs/linux/object_detection.yaml

Useful options:

python app.py configs/linux/object_detection.yaml --camera 0
python app.py configs/linux/object_detection.yaml --model /path/to/weights.pt
python app.py configs/linux/object_detection.yaml --max-frames 300
./scripts/run_object_detection.sh --model /path/to/weights.pt

Press q or Esc in the display window to stop.

TI-Style Visual Output

The Python display now mirrors the original Linux object-detection output as closely as possible on a laptop:

  • black 1920x1080 mosaic canvas
  • red EDGEAI TIOVX APPS heading at top-left
  • green flow title below it
  • object-detection video placed at [320, 150, 1280, 720]
  • bottom performance overlay
  • desktop window transport instead of TI KMS/DRM

OpenCV Qt Warnings on Ubuntu

This app uses a Tkinter display window instead of cv2.imshow, so OpenCV's Qt backend is not used during normal display. If you still see old Qt warnings, make sure you are running the updated app.py and reinstall the updated requirements:

pip install -r requirements.txt

If you choose to add OpenCV Qt display code later, install the common Qt/X11 and font packages:

sudo apt install -y fonts-dejavu-core fontconfig libxcb-xinerama0 libxcb-cursor0

Notes

  • This is not linked against TI libraries and does not require a TI board.
  • CPU inference will run, but a laptop GPU will usually be much faster.
  • If the webcam cannot open, try --camera 1 or close other apps that may be using the camera.