sefaburakokcu / finn-quantized-yolo

Low-Precision YOLO on PYNQ with FINN
26 stars 6 forks source link
face-detection finn fpga pynq-z2 qnn tiny-yolov3 yolov3

LPYOLO: Low Precision YOLO for Face Detection on FPGA

Contents

Introduction

This repo contains evaluation and deploy scripts for official LPYOLO: Low Precision YOLO for Face Detection on FPGA paper. Models are trained by Brevitas which is a PyTorch research library for quantization-aware training (QAT) and exported to ONNX. FINN which is an experimental framework from Xilinx Research Labs to explore deep neural network inference on FPGAs is used for deploying models on a PYNQ-Z2 board.

Requirements

Installation

First, download Pytorch armv7 and Torchvision armv7.

Then, run

pip install torch-1.8.1-cp38-cp38-linux_armv7l.whl
pip install torchvision-0.9.1-cp38-cp38-linux_armv7l.whl

on PYNQ-Z2 board.

Also, install bitstream

pip install bitstream

Usage

First, connect a PYNQ-Z2 board and open a terminal.Then, clone the project:

git clone git@github.com:sefaburakokcu/finn-quantized-yolo.git

Then, download one of the deploy.zip file from the table below and extract. Copy finn-accel.bit, finn-accel.hwh and scale.npy into src/deploy/bitfile/.

Model Definition

Definition of LPYOLO architecture is given below.

Model Definition

Pretrained Models

Models ONNX Deploy
2W4A 2w4a.onnx 2w4a_deploy.zip
3W5A 3w5a.onnx 3w5a_deploy.zip
4W2A 4w2a.onnx 4w2a_deploy.zip
4W4A 4w4a.onnx 4w4a_deploy.zip
6W4A 6w4a.onnx 6w4a_deploy.zip
8W3A 8w3a.onnx 8w3a_deploy.zip

Note: All models have 8 bits input and 8 bits output precisions. xWyA indicates x bits for weights and y bits precision for activations.

Training

Please use the following quantized-yolov5 repository for training quantized models.

Deployment

Please follow the steps in End-to-End Deployment of LPYOLO: Low Precision YOLO for Face Detection on FPGA.

Inference

Open inference.ipynb for inference on images, _videodemo.ipynb for inference on a video under finn-quantized-yolo/src/deploy/ in jupyter-notebook.

Citation

@inproceedings{Gunay_2022, series={EECSS’22},
   title={LPYOLO: Low Precision YOLO for Face Detection on FPGA},
   ISSN={2369-811X},
   url={http://dx.doi.org/10.11159/mvml22.108},
   DOI={10.11159/mvml22.108},
   booktitle={Proceedings of the 8th World Congress on Electrical Engineering and Computer Systems and Science},
   publisher={Avestia Publishing},
   author={Gunay, Bestami and Okcu, Sefa Burak and Bilge, Hasan Sakir},
   year={2022},
   month=jul, collection={EECSS’22} }