This repository explores a split-compute approach for object detection and segmentation. A lightweight edge container runs YOLOv8-n-seg on CPU and sends compressed features to a heavier cloud container with GPU access. The aim is to measure accuracy, bandwidth and latency trade-offs while experimenting with a reinforcement-learning controller that decides when to offload processing.
src/edge/detector.py)src/common/codec.py (baseline zlib or the Adaptive Flow Encoder).src/cloud/segmenter.py)src/common/offload_policy.py)tc/ that emulate 5G, 4G and 3G links so the entire system can be evaluated on a single machine.The experiments run inside Docker containers via docker-compose.yml. The edge container can be throttled to Raspberry Pi‑class resources (for example an 8 GB Pi 5). If time permits, the same container can run on a real Pi to validate the concept on physical hardware.
Install the Python dependencies from requirements-dev.txt.
Set up Python path: The source code is organized under src/. To run modules directly (without the src. prefix), add the src directory to your Python path:
Windows (PowerShell):
$env:PYTHONPATH = "c:\path\to\hybrid-vision\src"
Linux/macOS:
export PYTHONPATH="/path/to/hybrid-vision/src"
(Optional) Clone the Gen2Seg repo if you want to use the Gen2Seg decoder outside Docker:
python hv.py fetch-gen2seg
export PYTHONPATH="$(pwd)/gen2seg:${PYTHONPATH}"
Run pytest to execute the unit tests (see examples below for running specific tests).
Both the edge and cloud containers have their own requirements-*.txt files and Dockerfiles under docker/.
pytest # run the full suite
pytest tests/test_codec.py # run a single test file
pytest tests/test_codec.py::test_encode_zlib # run one test case
The AFE is an invertible flow that can compress either mid-level features or full images more efficiently than zlib. Separate checkpoints are produced for each kind of data.
For feature compression, dump neck tensors from COCO validation images:
python -m common.dump_neck_tensors --imgs datasets/coco/val2017 --out results/neck_stack.pt --count 2000
This extracts neck features from 2000 COCO images and saves them as a PyTorch tensor file.
Train on features (default) or on raw images by specifying --kind image:
# Feature codec
python -m src.training.train_afe --tensors results/neck_stack.pt --epochs 20
# Image codec
python -m src.training.train_afe --tensors results/image_stack.pt --kind image
Feature weights are written to _weights/codec.pt and image weights to _weights/image_codec.pt.
Mount the trained model(s) into your Docker containers:
/app/weights/codec.pt/app/weights/image_codec.ptSet the codec backend to use AFE instead of zlib:
export HYBRID_CODEC=afe
Run your experiments with the trained AFE codec:
docker-compose up
# Then run experiments as normal - they will automatically use the AFE codec
You can also test the AFE codec locally on your dev machine by:
Copy the trained model to the expected location:
mkdir -p /app/weights # or adjust _ckpt path in codec.py
cp _weights/codec.pt /app/weights/codec.pt
Set the environment variable and run experiments:
$env:HYBRID_CODEC = "afe" # PowerShell
python -m experiments.experiment_runner --dataset datasets/coco --frames 200 --csv results/afe_test.csv
Note: The codec automatically switches between zlib (default) and AFE based on the HYBRID_CODEC environment variable.
You can prune and quantize the YOLO weights for edge deployment with the helper
script under src/training. The tool supports dynamic, static and
quantization-aware training (QAT) modes:
# direct module invocation
python -m training.optimize_yolo yolov8n-seg.pt pruned_quantized.pt --prune 0.2 --quant static
# hv.py shorthand
python hv.py optimize yolov8n-seg.pt pruned.pt --prune 0.3 --quant static
By default dynamic quantization is used. Pass --quant static for post-training
static quantization or --quant qat (optionally with --steps) to run a short
QAT loop before converting the model.
To prune the provided YOLO weights and export a quantized ONNX model:
python -m training.prune_quantize_export _weights/yolov8n-seg.pt
The experiment runner processes a batch of COCO images through the edge → cloud
pipeline and records latency, bandwidth and accuracy metrics. Use
--policy heuristic (or --policy rl) together with --bandwidth to
enable bandwidth-aware routing.
The RL policy can be trained online and persisted for later runs. Pass
--policy-train together with a --policy-path to update and save the
Q-table while processing frames:
python -m experiments.experiment_runner --dataset datasets/coco --frames 200 \
--policy rl --bandwidth 8 --policy-train --policy-path policy.pkl
To reuse a previously trained policy, supply the same path without the
--policy-train flag:
python -m experiments.experiment_runner --dataset datasets/coco --frames 200 \
--policy rl --bandwidth 8 --policy-path policy.pkl
# direct module invocation
python -m experiments.experiment_runner --dataset datasets/coco --frames 200 \
--profile 5G --policy heuristic --bandwidth 8 --csv results/run1.csv
# hv.py shorthand
python hv.py experiment --dataset datasets/coco --frames 200 --profile 5G \
--policy heuristic --bandwidth 8 --csv results/run1.csv
To reproduce the full study, sweep the four quantisation modes, three
compression ratios, four bandwidth classes and two control policies using the
convenience script below. The aggregated summary for all 96 configurations is
written to results/factorial.csv.
python -m experiments.factorial_experiment --dataset datasets/coco --frames 1000 --out results/factorial.csv
The accompanying analysis notebook demonstrates how to compute ANOVA tables, mixed‑effects models and the headline numbers used in the dissertation text:
jupyter lab notebooks/factorial_analysis.ipynb
The hv.py script in the repository root exposes handy commands so you don't have to remember full module paths:
# Run the edge detector on one image
python hv.py edge path/to/image.jpg
# Run the complete edge → cloud pipeline
python hv.py cloud path/to/image.jpg
# Launch the docker containers
python hv.py compose-up
Run python hv.py -h to see all available subcommands.
1 commits
Jupyter Notebook
83.9%
Python
15.9%
This repository explores a split-compute approach for object detection and segmentation. A lightweight edge container runs YOLOv8-n-seg on CPU and sends compressed features to a heavier cloud container with GPU access. The aim is to measure accuracy, bandwidth and latency trade-offs while experimenting with a reinforcement-learning controller that decides when to offload processing.
src/edge/detector.py)src/common/codec.py (baseline zlib or the Adaptive Flow Encoder).src/cloud/segmenter.py)src/common/offload_policy.py)tc/ that emulate 5G, 4G and 3G links so the entire system can be evaluated on a single machine.The experiments run inside Docker containers via docker-compose.yml. The edge container can be throttled to Raspberry Pi‑class resources (for example an 8 GB Pi 5). If time permits, the same container can run on a real Pi to validate the concept on physical hardware.
Install the Python dependencies from requirements-dev.txt.
Set up Python path: The source code is organized under src/. To run modules directly (without the src. prefix), add the src directory to your Python path:
Windows (PowerShell):
$env:PYTHONPATH = "c:\path\to\hybrid-vision\src"
Linux/macOS:
export PYTHONPATH="/path/to/hybrid-vision/src"
(Optional) Clone the Gen2Seg repo if you want to use the Gen2Seg decoder outside Docker:
python hv.py fetch-gen2seg
export PYTHONPATH="$(pwd)/gen2seg:${PYTHONPATH}"
Run pytest to execute the unit tests (see examples below for running specific tests).
Both the edge and cloud containers have their own requirements-*.txt files and Dockerfiles under docker/.
pytest # run the full suite
pytest tests/test_codec.py # run a single test file
pytest tests/test_codec.py::test_encode_zlib # run one test case
The AFE is an invertible flow that can compress either mid-level features or full images more efficiently than zlib. Separate checkpoints are produced for each kind of data.
For feature compression, dump neck tensors from COCO validation images:
python -m common.dump_neck_tensors --imgs datasets/coco/val2017 --out results/neck_stack.pt --count 2000
This extracts neck features from 2000 COCO images and saves them as a PyTorch tensor file.
Train on features (default) or on raw images by specifying --kind image:
# Feature codec
python -m src.training.train_afe --tensors results/neck_stack.pt --epochs 20
# Image codec
python -m src.training.train_afe --tensors results/image_stack.pt --kind image
Feature weights are written to _weights/codec.pt and image weights to _weights/image_codec.pt.
Mount the trained model(s) into your Docker containers:
/app/weights/codec.pt/app/weights/image_codec.ptSet the codec backend to use AFE instead of zlib:
export HYBRID_CODEC=afe
Run your experiments with the trained AFE codec:
docker-compose up
# Then run experiments as normal - they will automatically use the AFE codec
You can also test the AFE codec locally on your dev machine by:
Copy the trained model to the expected location:
mkdir -p /app/weights # or adjust _ckpt path in codec.py
cp _weights/codec.pt /app/weights/codec.pt
Set the environment variable and run experiments:
$env:HYBRID_CODEC = "afe" # PowerShell
python -m experiments.experiment_runner --dataset datasets/coco --frames 200 --csv results/afe_test.csv
Note: The codec automatically switches between zlib (default) and AFE based on the HYBRID_CODEC environment variable.
You can prune and quantize the YOLO weights for edge deployment with the helper
script under src/training. The tool supports dynamic, static and
quantization-aware training (QAT) modes:
# direct module invocation
python -m training.optimize_yolo yolov8n-seg.pt pruned_quantized.pt --prune 0.2 --quant static
# hv.py shorthand
python hv.py optimize yolov8n-seg.pt pruned.pt --prune 0.3 --quant static
By default dynamic quantization is used. Pass --quant static for post-training
static quantization or --quant qat (optionally with --steps) to run a short
QAT loop before converting the model.
To prune the provided YOLO weights and export a quantized ONNX model:
python -m training.prune_quantize_export _weights/yolov8n-seg.pt
The experiment runner processes a batch of COCO images through the edge → cloud
pipeline and records latency, bandwidth and accuracy metrics. Use
--policy heuristic (or --policy rl) together with --bandwidth to
enable bandwidth-aware routing.
The RL policy can be trained online and persisted for later runs. Pass
--policy-train together with a --policy-path to update and save the
Q-table while processing frames:
python -m experiments.experiment_runner --dataset datasets/coco --frames 200 \
--policy rl --bandwidth 8 --policy-train --policy-path policy.pkl
To reuse a previously trained policy, supply the same path without the
--policy-train flag:
python -m experiments.experiment_runner --dataset datasets/coco --frames 200 \
--policy rl --bandwidth 8 --policy-path policy.pkl
# direct module invocation
python -m experiments.experiment_runner --dataset datasets/coco --frames 200 \
--profile 5G --policy heuristic --bandwidth 8 --csv results/run1.csv
# hv.py shorthand
python hv.py experiment --dataset datasets/coco --frames 200 --profile 5G \
--policy heuristic --bandwidth 8 --csv results/run1.csv
To reproduce the full study, sweep the four quantisation modes, three
compression ratios, four bandwidth classes and two control policies using the
convenience script below. The aggregated summary for all 96 configurations is
written to results/factorial.csv.
python -m experiments.factorial_experiment --dataset datasets/coco --frames 1000 --out results/factorial.csv
The accompanying analysis notebook demonstrates how to compute ANOVA tables, mixed‑effects models and the headline numbers used in the dissertation text:
jupyter lab notebooks/factorial_analysis.ipynb
The hv.py script in the repository root exposes handy commands so you don't have to remember full module paths:
# Run the edge detector on one image
python hv.py edge path/to/image.jpg
# Run the complete edge → cloud pipeline
python hv.py cloud path/to/image.jpg
# Launch the docker containers
python hv.py compose-up
Run python hv.py -h to see all available subcommands.
1 commits
Jupyter Notebook
83.9%
Python
15.9%