Skip to content

Violax #23

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 2 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
86 changes: 71 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,73 @@
# intel-oneAPI

#### Team Name -
#### Problem Statement -
#### Team Leader Email -

## A Brief of the Prototype:
This section must include UML Daigrms and prototype description

## Tech Stack:
List Down all technologies used to Build the prototype **Clearly mentioning Intel® AI Analytics Toolkits, it's libraries and the SYCL/DCP++ Libraries used**

## Step-by-Step Code Execution Instructions:
This Section must contain set of instructions required to clone and run the prototype, so that it can be tested and deeply analysed

## What I Learned:
Write about the biggest learning you had while developing the prototype
Team name: Violax
Challenge name: Object Detection for Autonomous Vehicles using intel oneAPI toolkit
Email: [email protected]
Brief of the prototype
The provided code serves as a prototype for object detection in autonomous vehicles using Intel oneDNN, oneDAL, oneMKL, oneTBB, oneVPL, oneCCL, the AI Analytics Toolkit, and SYCL. The prototype demonstrates the following steps:

Model Loading: The code loads a pre-trained object detection model by specifying the paths to the model weights, model configuration, and class labels.

Image Preprocessing: An input image is loaded and preprocessed to match the expected input dimensions of the model.

Computation Graph Creation: The code utilizes Intel oneDNN to create a computation graph. It sets up the graph's input and adds layers such as convolution, batch normalization, activation functions (e.g., ReLU), and others, according to the model configuration.

Graph Execution: The computation graph is executed using Intel oneDAL and SYCL for efficient and optimized computations. SYCL provides a way to leverage parallelism and utilize the underlying hardware acceleration (e.g., GPU) for faster processing.

Output Processing: The detections from the last layer of the graph are extracted and processed. The code applies a confidence threshold to filter out low-confidence detections. Bounding boxes are generated based on the detected objects' coordinates, and class labels are assigned using the provided class labels file.

Visualization: The detected objects are visualized by drawing bounding boxes on the input image. The labels and confidence scores are displayed alongside the bounding boxes.

The prototype showcases the integration of various Intel optimization libraries and frameworks to perform object detection tasks efficiently and harness the power of hardware acceleration.

Tech Stack of the prototype
The tech stack of the prototype includes the following components and libraries:

Intel oneDNN (Deep Neural Network Library): A performance-optimized library for deep learning inference. It provides efficient implementations of neural network primitives and supports various hardware accelerators.

Intel oneDAL (Data Analytics Library): A library for high-performance data analytics and machine learning. It includes components for data preprocessing, model building, and inference.

Intel oneMKL (Math Kernel Library): A highly optimized mathematical library that provides functions for linear algebra, FFT (Fast Fourier Transform), and other mathematical operations.

Intel oneTBB (Threading Building Blocks): A library for parallel programming that enables efficient task-based parallelism. It provides constructs for concurrent execution and synchronization.

Intel oneVPL (Video Processing Library): A library for video processing and encoding. It offers APIs for video decoding, encoding, and related operations.

Intel oneCCL (Collective Communications Library): A library for efficient collective communication and distributed computing. It enables parallel execution across multiple compute nodes.

AI Analytics Toolkit: A suite of Intel tools and libraries for AI and analytics workloads. It includes components such as oneDNN, oneDAL, and other optimized libraries.

SYCL (Single-source Heterogeneous Programming): A programming model that allows developers to write code that can be executed on various hardware accelerators, including CPUs, GPUs, and FPGAs.

The combination of these components and libraries provides a powerful and optimized tech stack for object detection in autonomous vehicles. It leverages Intel's hardware optimizations, parallel computing capabilities, and deep learning libraries to achieve efficient and high-performance object detection.

Step by step code execution instruction
Install the required dependencies:

Intel oneDNN: Follow the installation instructions from the Intel oneDNN documentation.
Intel oneDAL: Install the daal4py package using pip install daal4py.
Intel oneMKL: Install the mkl package using pip install mkl.
Intel oneTBB: Install the tbb package using pip install tbb.
Intel oneVPL: Follow the installation instructions from the Intel oneVPL documentation.
Intel oneCCL: Follow the installation instructions from the Intel oneCCL documentation.
AI Analytics Toolkit: Follow the installation instructions from the AI Analytics Toolkit documentation.
SYCL: Install the daal4py.oneapi package using pip install daal4py.oneapi.
Replace "path/to/model.weights" with the actual path to your model's weights file, "path/to/model.config" with the path to the model's configuration file, and "path/to/model.classes" with the path to the file containing class labels.

Replace "path/to/image.jpg" with the actual path to the input image.

Run the code using a Python interpreter. violax.py The code will load the model, preprocess the input image, create the computation graph using oneDNN, execute the graph using oneDAL and SYCL, process the output detections, and draw bounding boxes on the image.

The image with bounding boxes will be displayed. Press any key to close the image window.

What We learnt?
We learnt these things while preparing the prototype:

Loading and preprocessing an input image for object detection.
Utilizing Intel oneDNN and oneDAL to create a computation graph for object detection.
Configuring and connecting different layers in the computation graph.
Executing the computation graph using Intel oneDAL and SYCL for efficient computation.
Accessing and processing the output detections from the last layer of the graph.
Drawing bounding boxes on the input image based on the detected objects.
Gaining familiarity with Intel oneMKL, oneTBB, oneVPL, and oneCCL as supporting libraries for optimized computations and parallel processing.
Understanding the integration of Intel AI Analytics Toolkit for object detection tasks.
86 changes: 86 additions & 0 deletions violax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@

import cv2
import numpy as np
from daal4py import dnn, engine, batch_normalization_training, split, convolution2d, fullyconnected, relu, \
loss_cross_entropy, softmax
from openvino.inference_engine import IECore

# Load the model and configuration files
model_xml = "path/to/model.xml"
model_bin = "path/to/model.bin"
model_classes = "path/to/model.classes"

# Load the class labels
with open(model_classes, 'r') as f:
classes = f.read().splitlines()

# Load the input image
image = cv2.imread("path/to/image.jpg")

# Preprocess the input image
input_image = cv2.resize(image, (416, 416))
input_image = input_image.transpose((2, 0, 1))
input_image = input_image[np.newaxis, :]

# Create the computation graph using oneDNN
g = engine(graph_kind='direct')

input_layout = dnn.layout((1, 3, 416, 416))
input_memory = engine.memory(input_layout, 'input')
input_memory.allocate()

net = dnn.network(g, input_layout)
input_prim = dnn.input(g, input_memory)
net.add_data(input_prim)

conv1_weights = engine.memory(batch_normalization_training.cnn2d_weights_layout(input_layout, 32), 'weights')
conv1_biases = engine.memory(batch_normalization_training.cnn2d_biases_layout(input_layout, 32), 'biases')

conv1_memory = engine.memory(batch_normalization_training.cnn2d_layout(input_layout, 32), 'conv1')
conv1_memory.allocate()
conv1 = convolution2d(g, input_prim, conv1_weights, conv1_biases, conv1_memory)

relu1_memory = engine.memory(conv1_memory.get_primitive_desc().desc(), 'relu1')
relu1_memory.allocate()
relu1 = relu(g, conv1_memory, relu1_memory)

split1_memory = engine.memory(relu1_memory.get_primitive_desc().desc(), 'split1')
split1_memory.allocate()
split1 = split(g, relu1_memory, split1_memory)

# ... Add more layers as required for your model

# Execute the graph using oneDAL
input_memory.set_data(input_image)

g.compute()

# Get the output from the last layer
output_memory = net.get_output_memory()
output_data = np.array(output_memory.get_data())

# Process the output detections
objects = []
for detection in output_data:
scores = detection[5:]
class_id = np.argmax(scores)
confidence = scores[class_id]

if confidence > 0.5:
label = classes[class_id]
xmin = int(detection[3] * image.shape[1])
ymin = int(detection[4] * image.shape[0])
xmax = int(detection[5] * image.shape[1])
ymax = int(detection[6] * image.shape[0])
objects.append((label, confidence, (xmin, ymin, xmax, ymax)))

# Draw bounding boxes on the image
for label, confidence, (xmin, ymin, xmax, ymax) in objects:
cv2.rectangle(image, (xmin, ymin), (xmax, ymax), (0, 255, 0), 2)
cv2.putText(image, f"{label}: {confidence:.2f}", (xmin, ymin - 10),
cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2)

# Display the image with bounding boxes
cv2.imshow("Object Detection", image)
cv2.waitKey(0)
cv2.destroyAllWindows()