Skip to content

Pre-built yolov8 demo for Alveo u55c #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
33 changes: 33 additions & 0 deletions finn_examples/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from qonnx.core.datatype import DataType

from finn_examples.driver import FINNExampleOverlay
from finn_examples.yolov8.yolov8 import DetectorDriver

_mnist_fc_io_shape_dict = {
"idt": [DataType["UINT8"]],
Expand Down Expand Up @@ -99,6 +100,27 @@
"num_outputs": 1,
}

_yolov8n_4w4a_coco_io_shape_dict = {
# FINN DataType for input and output tensors
"idt": [DataType["UINT8"]],
"odt": [DataType["INT21"], DataType["INT21"], DataType["INT21"]],
# shapes for input and output tensors (NHWC layout)
"ishape_normal": [(1, 192, 320, 3)],
"oshape_normal": [(1, 24, 40, 144), (1, 12, 20, 144), (1, 6, 10, 144)],
# folded / packed shapes below depend on idt/odt and input/output
# PE/SIMD parallelization settings -- these are calculated by the
# FINN compiler.
"ishape_folded": [(1, 192, 320, 3, 1)],
"oshape_folded": [(1, 24, 40, 144, 1), (1, 12, 20, 144, 1), (1, 6, 10, 144, 1)],
"ishape_packed": [(1, 192, 320, 3, 1)],
"oshape_packed": [(1, 24, 40, 144, 3), (1, 12, 20, 144, 3), (1, 6, 10, 144, 3)],
"input_dma_name": ["idma0"],
"output_dma_name": ["odma0", "odma1", "odma2"],
"number_of_external_weights": 0,
"num_inputs": 1,
"num_outputs": 3,
}

_imagenet_top5inds_io_shape_dict = {
"idt": [DataType["UINT8"]],
"odt": [DataType["UINT16"]],
Expand Down Expand Up @@ -333,6 +355,17 @@ def bincop_cnv(target_platform=None, bitfile_path=None):
return FINNExampleOverlay(filename, driver_mode, _bincop_cnv_io_shape_dict)


def yolov8n_4w4a_coco(target_platform=None, bitfile_path=None, batch_size=1):
target_platform = resolve_target_platform(target_platform)
driver_mode = get_driver_mode()
model_name = "yolov8n_4w4a_coco"
filename = find_bitfile(model_name, target_platform, bitfile_path)
quant_tail_params_dir = pk.resource_filename("finn_examples", "yolov8")
return DetectorDriver(
filename, driver_mode, _yolov8n_4w4a_coco_io_shape_dict, quant_tail_params_dir, batch_size
)


def mobilenetv1_w4a4_imagenet(target_platform=None, bitfile_path=None, rt_weights_path=None):
target_platform = resolve_target_platform(target_platform)
driver_mode = get_driver_mode()
Expand Down
86 changes: 86 additions & 0 deletions finn_examples/notebooks/8_yolov8_object_detection.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import cv2\n",
"from finn_examples import models"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Initialize the Accelerator"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# The yolov8 is pre-build only for alveo u55c at the moment\n",
"accel = models.yolov8n_4w4a_coco()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Run Inference"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"img = cv2.imread('images/test.jpg')\n",
"detections = accel.single_inference(img, conf_thres=0.3) "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Visualize output"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"visualized_img = accel.visualize(img, detections)\n",
"cv2.imwrite('demo.jpg', visualized_img)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Binary file added finn_examples/yolov8/Add_0_param0
Binary file not shown.
Binary file added finn_examples/yolov8/Add_1_param0
Binary file not shown.
Binary file added finn_examples/yolov8/Add_2_param0
Binary file not shown.
Binary file added finn_examples/yolov8/Mul_0_param0
Binary file not shown.
Binary file added finn_examples/yolov8/Mul_1_param0
Binary file not shown.
Binary file added finn_examples/yolov8/Mul_2_param0
Binary file not shown.
Loading