Commit e14e5737 authored by cuongvt2's avatar cuongvt2

add branch & tool, example

parent 615e3857
2021-08-23 21:24:21,465 - INFO - udp_rate_limiter.py:525 - Setting UDP rate to 400000.0 Kbits for 10.0.0.93:32401
2021-08-23 21:24:26,682 - ERROR - udp_rate_limiter.py:184 - RTNETLINK answers: File exists
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['run.py'],
pathex=['/home/avim/repos_3_7_1/customer-support2_work/tools/HailoRT/python_example_video_140fps'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='run',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='run')
#
- video file (~95MB): full_mov_slow.mp4
\ No newline at end of file
. /home/avim/SDK/Latest/platform/hailo_platform_venv/bin/activate
pip3 install zenlog
pip3 install colorama
pip3 install pillow
pip3 install opencv-python
pip3 install tensorflow
hailo udp-limiter reset --board-ip 10.0.0.93
hailo udp-limiter set --board-ip=10.0.0.93 --kbit-rate=400000
sudo /home/avim/SDK/Latest/platform/scripts/configure_ethernet_buffers.sh eno2
./run.py --hef yolov5m.hef
cmake_minimum_required(VERSION 3.0.0)
# Setting the ARCH if not provided
if (NOT DEFINED ARCH)
execute_process(COMMAND uname -m OUTPUT_VARIABLE arch_from_cmd)
string(STRIP ${arch_from_cmd} arch_from_cmd)
set(ARCH ${arch_from_cmd})
endif()
set(HAILORT_ROOT $ENV{HAILORT_ROOT})
set(HAILORT_VER $ENV{HAILORT_VER})
set(HAILORT_LIB ${HAILORT_ROOT}/../lib/linux.${ARCH}.release/libhailort.so.${HAILORT_VER})
set(HAILORT_LIB ${HAILORT_ROOT}/lib/${ARCH}/libhailort.so.${HAILORT_VER})
set(HAILORT_INCLUDE_DIR ${HAILORT_ROOT}/include)
message(STATUS ${HAILORT_LIB})
message(STATUS ${HAILORT_INCLUDE_DIR})
set(COMPILE_OPTIONS -Wall -g -O0)
find_package(Threads)
foreach(target example-hef example)
add_executable(${target}.${HAILORT_VER} "${target}.c")
include_directories(${HAILORT_INCLUDE_DIR})
target_compile_options(${target}.${HAILORT_VER} PRIVATE ${COMPILE_OPTIONS})
target_link_libraries(${target}.${HAILORT_VER} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(${target}.${HAILORT_VER} ${HAILORT_LIB})
endforeach(target)
To Compile all targets to all architectures (x86, armv7l, aarch64):
`build.sh`
\ No newline at end of file
This diff is collapsed.
#include <hailo/hailort.h>
#define FREE(var) \
do \
{ \
if (NULL != (var)) \
{ \
free(var); \
var = NULL; \
} \
} while (0)
#define REQUIRE_SUCCESS(status, label, msg) \
do \
{ \
if (HAILO_SUCCESS != (status)) \
{ \
printf(BOLDRED); \
printf("-E- %s : (%d)\n",msg, status); \
printf(RESET); \
goto label; \
} \
} while (0)
typedef struct write_thread_args_t
{
hailo_stream_info_t *input_stream_info;
hailo_input_stream input_stream;
hailo_status status;
int output_streams_cnt;
unsigned int num_images;
size_t host_frame_size;
size_t frame_hw_size;
int write_log;
int tid;
int source_fps;
} write_thread_args_t;
typedef struct recv_thread_args_t
{
hailo_stream_info_t *output_stream_info;
hailo_output_stream output_stream;
hailo_status status;
int tid;
unsigned int num_images;
int num_streams;
int write_log;
size_t host_frame_size;
size_t frame_hw_size;
} recv_thread_args_t;
typedef struct video_thread_args_t
{
hailo_stream_info_t *input_stream_info;
const char *video_path;
int num_images;
} video_thread_args_t;
const char* get_direction_name(hailo_stream_direction_t dir) {
switch (dir) {
case HAILO_H2D_STREAM: return "Input";
case HAILO_D2H_STREAM: return "Output";
case HAILO_STREAM_DIRECTION_MAX_ENUM: return "Wrong";
}
return "Wrong";
}
const char *get_transform_string(hailo_stream_transform_mode_t transform)
{
switch(transform) {
case HAILO_STREAM_NO_TRANSFORM: return "NO";
case HAILO_STREAM_TRANSFORM_COPY: return "COPY";
case HAILO_STREAM_TRANSFORM_INPLACE: return "IN_PLACE";
case HAILO_STREAM_MAX_ENUM:
default: return "Wrong";
}
}
const char *get_flags_string(int flags)
{
switch(flags) {
case 0: return "NONE";
case 1: return "QUANT";
case 2: return "TRANS";
case 3: return "QT+TR";
default: return "UNKNOWN";
}
}
const char *get_type_string(int type)
{
switch(type) {
case 0: return "AUTO";
case 1: return "UINT8";
case 2: return "UINT16";
case 3: return "FLOAT32";
default: return "UNKNOWN";
}
}
const char *get_order_string(int order)
{
switch(order) {
case 0: return "NHWC";
case 1: return "NHCW";
case 2: return "FCR";
case 3: return "F8CR";
case 5: return "NC";
case 8: return "NMS";
case 10: return "NCHW";
default: return "UNKNOWN";
}
}
#define RESET "\033[0m"
#define BLACK "\033[30m" /* Black */
#define RED "\033[31m" /* Red */
#define GREEN "\033[32m" /* Green */
#define YELLOW "\033[33m" /* Yellow */
#define BLUE "\033[34m" /* Blue */
#define MAGENTA "\033[35m" /* Magenta */
#define CYAN "\033[36m" /* Cyan */
#define WHITE "\033[37m" /* White */
#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */
#define BOLDRED "\033[1m\033[31m" /* Bold Red */
#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */
#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */
#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */
\ No newline at end of file
cmake_minimum_required(VERSION 3.0.0)
project( OpenCV_example )
##Setting the ARCH if not provided
if (NOT DEFINED ARCH)
execute_process(COMMAND uname -m OUTPUT_VARIABLE arch_from_cmd)
string(STRIP ${arch_from_cmd} arch_from_cmd)
set(ARCH ${arch_from_cmd})
endif()
# Setting the CMAKE_C_COMPILER if not provided
if (${ARCH} STREQUAL "aarch64")
if (NOT DEFINED CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER "/usr/bin/aarch64-linux-gnu-gcc")
endif()
else()
if (NOT DEFINED CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER "/usr/bin/gcc")
endif()
endif()
set(CMAKE_CXX_COMPILER "/usr/bin/g++-9")
set(HAILORT_ROOT "/home/nadave/SDK/3.2.0/platform/hailort")
set(HAILORT_INCLUDE_DIR "${HAILORT_ROOT}/include")
set(HAILORT_LIB "${HAILORT_ROOT}/lib/x86_64/libhailort.so.2.2.0")
set(COMPILE_OPTIONS -Wall -std=gnu++2a -DNDEBUG)
include_directories(${HAILORT_INCLUDE_DIR})
set(target runme)
add_executable(${target} example.cpp ImageNetLabels.cpp)
target_compile_options(${target} PRIVATE ${COMPILE_OPTIONS})
find_package(Threads)
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
target_link_libraries(${target} ${OpenCV_LIBS})
target_link_libraries(${target} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(${target} ${HAILORT_LIB})
This diff is collapsed.
#ifndef IMAGENETLABELS_H
#define IMAGENETLABELS_H
#include <iostream>
#include <string>
#include <vector>
class ImageNetLabels
{
private:
std::vector<std::string> _labels;
public:
ImageNetLabels();
std::string imagenet_labelstring(int i);
};
#endif
\ No newline at end of file
1. Dependencies:
1. OpenCV
`sudo apt-get install -y libopencv-dev`
`sudo apt-get install g++-9`
2. First time directory preparation:
`cmake -H. -Bbuild`
3. Consecutive builds:
`cmake --build build`
This diff is collapsed.
#define FREE(var) \
do { \
if (NULL != (var)) { \
free(var); \
var = NULL; \
} \
} while(0)
#define REQUIRE_SUCCESS(status, label, msg) \
do \
{ \
if (HAILO_SUCCESS != (status)) \
{ \
printf(BOLDRED); \
printf("-E- %s : (%d)\n",msg, status); \
printf(RESET); \
goto label; \
} \
} while(0)
#define RESET "\033[0m"
#define BLACK "\033[30m" /* Black */
#define RED "\033[31m" /* Red */
#define GREEN "\033[32m" /* Green */
#define YELLOW "\033[33m" /* Yellow */
#define BLUE "\033[34m" /* Blue */
#define MAGENTA "\033[35m" /* Magenta */
#define CYAN "\033[36m" /* Cyan */
#define WHITE "\033[37m" /* White */
#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */
#define BOLDRED "\033[1m\033[31m" /* Bold Red */
#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */
#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */
#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */
typedef struct write_thread_args_t {
hailo_stream_info_t *input_stream_info;
hailo_input_stream input_stream;
hailo_status status;
int output_streams_cnt;
int num_images;
} write_thread_args_t;
typedef struct video_thread_args_t {
hailo_stream_info_t *input_stream_info;
const char *video_path;
int num_images;
} video_thread_args_t;
typedef struct post_infer_thread_args_t {
hailo_output_stream output_stream;
hailo_stream_info_t *stream_info;
int tid;
int num_streams;
} post_infer_thread_args_t;
typedef struct recv_thread_args_t {
hailo_stream_info_t *output_stream_info;
hailo_output_stream output_stream;
hailo_status status;
int tid;
int lat_counter;
int num_streams;
int write_log;
int num_images;
} recv_thread_args_t;
\ No newline at end of file
#define FREE(var) \
do { \
if (NULL != (var)) { \
free(var); \
var = NULL; \
} \
} while(0)
#define REQUIRE_SUCCESS(status, label, msg) \
do \
{ \
if (HAILO_SUCCESS != (status)) \
{ \
printf(BOLDRED); \
printf("-E- %s : (%d)\n",msg, status); \
printf(RESET); \
goto label; \
} \
} while (0)
#define RESET "\033[0m"
#define BLACK "\033[30m" /* Black */
#define RED "\033[31m" /* Red */
#define GREEN "\033[32m" /* Green */
#define YELLOW "\033[33m" /* Yellow */
#define BLUE "\033[34m" /* Blue */
#define MAGENTA "\033[35m" /* Magenta */
#define CYAN "\033[36m" /* Cyan */
#define WHITE "\033[37m" /* White */
#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */
#define BOLDRED "\033[1m\033[31m" /* Bold Red */
#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */
#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */
#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */
typedef struct write_thread_args_t {
hailo_stream_info_t *input_stream_info;
hailo_input_stream input_stream;
hailo_status status;
int output_streams_cnt;
int num_images;
size_t input_shape_size;
} write_thread_args_t;
typedef struct video_thread_args_t {
hailo_stream_info_t *input_stream_info;
const char *video_path;
int num_images;
} video_thread_args_t;
typedef struct post_infer_thread_args_t {
hailo_output_stream output_stream;
hailo_stream_info_t *stream_info;
int tid;
int num_streams;
} post_infer_thread_args_t;
typedef struct recv_thread_args_t {
hailo_stream_info_t *output_stream_info;
hailo_output_stream output_stream;
hailo_status status;
int tid;
int lat_counter;
int num_streams;
int write_log;
size_t output_shape_size;
} recv_thread_args_t;
// http://www.jclay.host/dev-journal/simple_cpp_argmax_argmin.html
template <typename T, typename A>
int argmax(std::vector<T, A> const& vec) {
return static_cast<int>(std::distance(vec.begin(), max_element(vec.begin(), vec.end())));
}
template <typename T, typename A>
std::vector<T, A> softmax(std::vector<T, A> const& vec) {
std::vector<T, A> result;
float m = -INFINITY;
float sum = 0.0;
for (const auto &val : vec) m = (val>m) ? val : m;
for (const auto &val : vec) sum += expf(val - m);
for (const auto &val : vec) result.push_back(expf(val-m)/sum);
return result;
}
\ No newline at end of file
cmake_minimum_required(VERSION 3.1)
project(cpp_agent)
message(STATUS "HAILORT_ROOT: $ENV{HAILORT_ROOT}")
set(HAILORT_ROOT $ENV{HAILORT_ROOT})
set(HAILORT_LIB $ENV{HAILORT_ROOT}/lib/${ARCH}/libhailort.so.$ENV{LIB_VER})
set(HAILORT_INCLUDE_DIR "$ENV{HAILORT_ROOT}/include")
set(COMPILE_OPTIONS_CPP -Werror -g -O0 -std=c++2a)
set(COMPILE_OPTIONS_CPP -Wall -Werror -O3 -DNDEBUG -std=c++2a)
include_directories(${HAILORT_INCLUDE_DIR} ./)
find_package(Threads)
find_package( OpenCV REQUIRED )
foreach(target runme.$ENV{LIB_VER})
add_executable(${target} example_device.cpp main.cpp)
# https://github.com/llohse/libnpy
target_include_directories(${target} PUBLIC /home/nadave/repos/libnpy)
target_compile_options(${target} PRIVATE ${COMPILE_OPTIONS_CPP})
target_link_libraries(${target} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(${target} ${HAILORT_LIB})
target_link_libraries(${target} ${OpenCV_LIBS})
endforeach(target)
1. Dependencies:
1. OpenCV
`sudo apt-get install -y libopencv-dev`
`sudo apt-get install gcc-9 g++-9`
Install libnpy, if you want debug capability
git clone https://github.com/llohse/libnpy.git
2. Set HAILORT_ROOT environment variable, e.g.:
export HAILORT_ROOT=~/SDK/3.7.0/platform/hailort
2. Build the project
build.sh
#!/bin/bash
declare -A COMPILER=( [x86_64]=/usr/bin/gcc
[aarch64]=/usr/bin/aarch64-linux-gnu-gcc
[armv7l]=/usr/bin/arm-linux-gnueabi-gcc )
HAILORT_ROOT=/home/nadave/SDK/platform-sw/hailort
HAILORT_ROOT=/local/users/nadave/SDK/3.9.0/platform/hailort
for ARCH in x86_64
do
echo "-I- Building ${ARCH}"
mkdir -p build/${ARCH}
export CXX=g++-9
LIB_VER=2.9.0 HAILORT_ROOT=${HAILORT_ROOT} cmake -H. -Bbuild/${ARCH} -DARCH=${ARCH} -DCMAKE_C_COMPILER=${COMPILER[${ARCH}]}
cmake --build build/${ARCH}
done
if [[ -f "hailort.log" ]]; then
rm hailort.log
fi
This diff is collapsed.
#ifndef _EXAMPLE_DEVICE_H_
#define _EXAMPLE_DEVICE_H_
#include <time.h>
#include <net/if.h>
#include <vector>
#include <memory>
#include <unistd.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <dirent.h>
#include <linux/limits.h>
#include <example_utils.hpp>
#include <condition_variable>
#include <queue>
#include <future>
#include <opencv2/opencv.hpp>
#include <opencv2/video/video.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <hailo/hailort.h>
#define NOF_STREAMS (6)
#define NOF_DEVICES (2)
#define NSEC_IN_SEC (1e+9)
#define LATENCY_MEASUREMENTS (100)
#define MAX_OUTPUT_MUX_INFO_CAPACITY (16)
class example_device
{
private:
hailo_eth_device_info_t device_info;
hailo_pcie_device_info_t pcie_device_info[NOF_DEVICES];
hailo_device device;
hailo_hef hef;
hailo_network_group network_group;
hailo_activated_network_group active_net_g;
hailo_input_stream input_stream;
hailo_output_stream output_streams[NOF_STREAMS];
hailo_stream_info_t all_stream_infos[NOF_STREAMS];
struct timespec start_time;
struct timespec end_time;
struct timespec sent_clock_t[LATENCY_MEASUREMENTS];
struct timespec recv_clock_t[NOF_STREAMS-1][LATENCY_MEASUREMENTS];
std::string iface;
std::string hef_file;
unsigned int num_imgs;
int write_log;
bool yolo_post;
qp_zp_scale_t qp_zp_scale;
bool use_one_rx_thrd;
std::queue<cv::Mat> input_image_queue;
pthread_mutex_t input_image_queue_m = PTHREAD_MUTEX_INITIALIZER;
// std::queue< std::vector<uint8_t> > post_infer_queue[NOF_STREAMS-1];
// pthread_mutex_t post_infer_queue_m = PTHREAD_MUTEX_INITIALIZER;
void* _frame_lib_thread(void *args);
void* _video_source_thread(void *args);
void* _send_from_source_thread(void *args);
std::string source_path;
bool source_is_video(std::string& path);
template <class T> void _recv_thread1(std::future<void> &futureObj);
void init_qp_zp_struct();
hailo_status create_pcie_device();
hailo_status create_eth_device();
hailo_status print_debug_stats();
template<class T> hailo_status set_stream_infos(hailo_input_stream_params_by_name_t *input_stream_params, hailo_output_stream_params_by_name_t *output_stream_params);
const char* get_direction_name(hailo_stream_direction_t dir);
double calc_latency(int count);
template <class T> void _recv_thread(void *args);
template <class T> void _send_thread(void *args);
template <class T> hailo_status infer();
void deactivate_network_group();
void release_hef();
void release_device();
double get_time_from_ts(struct timespec ts);
public:
size_t output_stream_cnt;
size_t input_stream_cnt;
example_device(std::string& iface, std::string& hef_file, unsigned int num_imgs, int write_log, bool yolo_post, std::string source_path);
~example_device();
hailo_status create_and_load_hef();
void print_net_banner();
void print_inference_stats();
template <class T> hailo_status setup_device_for_inference();
void run_inference();
hailo_status activate_network_group(hailo_input_stream_params_by_name_t *input_stream_params, hailo_output_stream_params_by_name_t *output_stream_params);
size_t host_input_frame_size;
size_t host_output_frame_size[NOF_STREAMS];
};
#endif
#ifndef _EXAMPLE_UTILS_H_
#define _EXAMPLE_UTILS_H_
#include <hailo/hailort.h>
#define FREE(var) \
do \
{ \
if (NULL != (var)) \
{ \
free(var); \
var = NULL; \
} \
} while (0)
#define REQUIRE_SUCCESS(status, label, msg) \
do \
{ \
if (HAILO_SUCCESS != (status)) \
{ \
printf(BOLDRED); \
printf("-E- %s : (%d)\n",msg, status); \
printf(RESET); \
goto label; \
} \
} while (0)
typedef struct write_thread_args_t
{
hailo_stream_info_t input_stream_info;
hailo_input_stream input_stream;
hailo_status status;
hailo_stream_info_t stream_info;
int output_streams_cnt;
unsigned int num_images;
size_t host_input_frame_size;
int tid;
} write_thread_args_t;
typedef struct recv_thread_args_t
{
hailo_output_stream output_stream;
hailo_status status;
size_t host_output_frame_size;
hailo_stream_info_t stream_info;
unsigned int num_images;
int num_streams;
int write_log;
int tid;
} recv_thread_args_t;
typedef struct recv_thread1_args_t
{
hailo_output_stream *output_stream;
size_t *host_output_frame_size;
hailo_stream_info_t *stream_info;
unsigned int num_images;
int num_streams;
int write_log;
} recv_thread1_args_t;
typedef struct video_thread_args_t
{
hailo_stream_info_t *input_stream_info;
const char *video_path;
int num_images;
} video_thread_args_t;
typedef struct qp_zp_scale_t {
float32_t qp_zp_1;
float32_t qp_scale_1;
float32_t qp_zp_2;
float32_t qp_scale_2;
float32_t qp_zp_3;
float32_t qp_scale_3;
} qp_zp_scale_t;
#define RESET "\033[0m"
#define BLACK "\033[30m" /* Black */
#define RED "\033[31m" /* Red */
#define GREEN "\033[32m" /* Green */
#define YELLOW "\033[33m" /* Yellow */
#define BLUE "\033[34m" /* Blue */
#define MAGENTA "\033[35m" /* Magenta */
#define CYAN "\033[36m" /* Cyan */
#define WHITE "\033[37m" /* White */
#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */
#define BOLDRED "\033[1m\033[31m" /* Bold Red */
#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */
#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */
#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */
#endif
/**
* Copyright 2020 (C) Hailo Technologies Ltd.
* All rights reserved.
*
* Hailo Technologies Ltd. ("Hailo") disclaims any warranties, including, but not limited to,
* the implied warranties of merchantability and fitness for a particular purpose.
* This software is provided on an "AS IS" basis, and Hailo has no obligation to provide maintenance,
* support, updates, enhancements, or modifications.
*
* You may use this software in the development of any project.
* You shall not reproduce, modify or distribute this software without prior written permission.
**/
/**
* @ file main.cpp
* This example demonstrates the basic data-path on HailoRT.
* The program scans for Hailo-8 devices connected to a provided Ethernet interface, generates random dataset,
* and runs it through the device.
**/
#include "example_device.hpp"
#include "example_utils.hpp"
#include <iostream>
#include <thread>
#include <functional>
void thread_wrapper(std::string &iface, std::string &hef_file, unsigned int &num_img, int &write_log, bool &yolo_post, std::string &source_input)
{
example_device dev(iface, hef_file, num_img, write_log, yolo_post, source_input);
dev.run_inference();
}
int main(int argc, char **argv)
{
std::string hef = "";
std::string iface = "pcie";
std::string video_path = "";
bool yolo_post = false;
int opt;
unsigned int num_img = 100;
int write_log = 0;
while ((opt = getopt(argc, argv, "i:c:n:v:dly")) != -1)
{
switch (opt)
{
case 'c':
hef = optarg;
break;
case 'i':
iface = optarg;
break;
case 'n':
num_img = atoi(optarg);
break;
case 'l':
write_log = 1;
break;
case 'v':
video_path = optarg;
break;
case 'y':
yolo_post = true;
break;
case '?':
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
default:
fprintf(stderr, "Usage: %s -i INTERFACE -j JLF-DIR [-n NUM-IMAGES]\n\n", argv[0]);
fprintf(stderr, " -c HEF The HEF Configuration file\n");
fprintf(stderr, " -n NUM-IMAGES The number of images to process, defaults to 100\n");
fprintf(stderr, " -v VIDEO FILE Path to an input video file, relevant only in conjuction with the -y option\n");
fprintf(stderr, " -i INTERFACE The device interface, defaults to \'pcie\', if using Ethernet name the Host port\n");
fprintf(stderr, " -y Do YOLOv5 640x640 post-processing\n");
exit(EXIT_FAILURE);
}
}
try
{
std::cout << CYAN << "-I- TEST STARTS" << RESET << std::endl;
if (yolo_post==true && video_path.empty()) {
std::cout << RED << "-W- Received no input source (Video or images) and YOLOv5, aborting" << RESET << std::endl;
exit(0);
}
std::thread t0(thread_wrapper, std::ref(iface), std::ref(hef), std::ref(num_img), std::ref(write_log), std::ref(yolo_post), std::ref(video_path));
t0.join();
std::cout << CYAN << "-I- TEST ENDED" << RESET << std::endl;
}
catch (const std::exception &e)
{
std::cout << e.what();
}
}
This diff is collapsed.
#!/usr/bin/env python3
import os
import time
import argparse as ap
import numpy as np
from zenlog import logging as logger
from colorama import Fore
from tqdm import trange
import ctypes
from multiprocessing import Process, Value, Array
from hailo_platform import HEF, HailoPcieObject, InputStreamParams, OutputStreamParams, FormatType
from hailo_platform import HailoUdpControllerObject, HailoPcieObject, SendPipeline, RecvPipeline
from hailo_platform.drivers.hailort.pyhailort import PcieDevice, HailoRTException
def arg_prep():
parser = ap.ArgumentParser()
parser.add_argument('--hef', help='Point to the HEF')
parser.add_argument('--mode', help='Choose the communication mode [hw-only|full]', type=str, default='full')
parser.add_argument('--iterations', help='How many repeasts on the picture stream (Default:100)', type=int, default=100)
parser.add_argument('--power', help='Enable Power measurement', default=False, action='store_true')
parser.add_argument('--source', help='Specify image or video source', default=None)
parser.add_argument('--interface', help='Specify the physical interface, pcie or udp', default='pcie')
parser.add_argument('--fps', help='Emulate a source FPS', type=int, default='0')
# parser.add_argument('--ip', help='Set the IP of the Hailo device', type=str, default='10.0.0.100')
args = parser.parse_args()
return args
def _pre_infer_hef(stream, input_data):
dst_buffer = ctypes.create_string_buffer(stream.stream_information.hw_frame_size)
stream.transform(input_data, ctypes.addressof(dst_buffer), False)
return dst_buffer.raw
def _recv_process_hw_only_hef(output_streams, iterations, end_time, recv_times):
logger.info('RECV process HW-only Started')
local_recv_times = list()
outputs = dict()
for i in trange(iterations, desc='INFO:Recv...', position=0, bar_format="{l_bar}%s{bar}%s{r_bar}" % (Fore.GREEN, Fore.RESET)):
try:
for j, output_stream in enumerate(output_streams):
outputs[j] = output_stream.recv()
if i<100 and j==0:
local_recv_times.append(time.time())
except HailoRTException as e:
if e.args and '0x4' in e.args and i>iterations*0.9:
pass
for i, t in enumerate(local_recv_times):
recv_times[i] = t
end_time.value = time.time()
def _recv_process_full_hef(activated_network, iterations, end_time, recv_times):
logger.info('RECV process Full Started')
with RecvPipeline(activated_network) as recv_pipeline:
output_streams = [recv_pipeline.get_output_by_name(output_name) for output_name in activated_network.target.sorted_output_layer_names]
[logger.info("Output: {}".format(name)) for name in activated_network.target.sorted_output_layer_names]
outputs = dict()
for i in trange(iterations, desc='INFO:Recv...', position=0, bar_format="{l_bar}%s{bar}%s{r_bar}" % (Fore.GREEN, Fore.RESET)):
logger.debug("[{}] Recv frame {}/{}".format(time.time(), i, iterations))
for j, output_stream in enumerate(output_streams):
outputs[j] = output_stream.recv()
if i<100:
recv_times[i] = time.time()
end_time.value = time.time()
logger.debug("[{}] Finished Recving {} frames".format(end_time.value, iterations))
def _send_process_hw_only_hef(input_streams, iterations, fps, send_times):
logger.info('SEND process HW-only Started')
local_send_times = list()
if fps>0.0:
logger.info("Emulate source FPS: {}".format(fps))
data_per_input = [_pre_infer_hef(s, np.random.randint(256, size=(1,) + shape, dtype=np.uint8)) for s, shape in input_streams.items()]
# [logger.info("Input: {} with shape: {}".format(name, shape)) for name, shape in input_streams.items()]
for i in range(iterations):
try:
for intput_stream in input_streams.keys():
if fps>0:
time.sleep(1.0/fps)
if i<100:
local_send_times.append(time.time())
intput_stream.send(data_per_input[0])
except HailoRTException as e:
if e.args and '0x4' in e.args and i>iterations*0.9:
pass
for i,t in enumerate(local_send_times):
send_times[i] = t
def _send_process_full_hef(activated_network, iterations, input_shapes, fps, send_times):
with SendPipeline(activated_network) as send_pipeline:
input_streams = {send_pipeline.get_input_by_name(input_name): shape
for input_name, shape in input_shapes.items()}
data_per_input = [np.random.randint(256, size=(1,) + shape, dtype=np.uint8) for _, shape in input_shapes.items()]
[logger.info("Input: {} with shape: {}".format(name, shape)) for name, shape in input_shapes.items()]
if fps>0.0:
logger.info("Emulate source FPS: {}".format(fps))
local_send_times = list()
for i in range(iterations):
try:
for input_stream, _ in input_streams.items():
logger.debug("[{}] Send frame {}/{}".format(time.time(), i, iterations))
if fps>0:
time.sleep(1.0/fps)
if i<100:
local_send_times.append(time.time())
input_stream.send(data_per_input[0])
except HailoRTException as e:
if e.args and '0x4' in e.args and i>iterations*0.9:
pass
for i,t in enumerate(local_send_times):
send_times[i] = t
def run_hef(target, hef, iterations, streaming_mode, fps):
logger.info("Loading HEF to target")
network = target.configure(hef)[0]
application_params = network.create_params()
# Explanation about definition of the streams-
# quantized - Whether to scale and zero-point the values from 0-255, if the input is uint8 can use as-is
# format_type - The input type UINT8, UINT16, FLOAT32, AUTO
input_streams_params = InputStreamParams.make_from_network_group(network, quantized=True, format_type=FormatType.UINT8)
output_streams_params = OutputStreamParams.make_from_network_group(network, quantized=True, format_type=FormatType.UINT8)
with network.activate(application_params, input_streams_params=input_streams_params,
output_streams_params=output_streams_params) as activated_network:
send_times = Array(ctypes.c_double, [0.0] * 100)
recv_times = Array(ctypes.c_double, [0.0] * 100)
end_time = Value(ctypes.c_double, 0.0)
if streaming_mode=='full':
input_shapes = {layer_info.name: layer_info.shape for layer_info in hef.get_input_layers_info()}
recv_process = Process(target=_recv_process_full_hef, args=(activated_network, iterations, end_time, recv_times))
send_process = Process(target=_send_process_full_hef, args=(activated_network, iterations, input_shapes, fps, send_times))
else:
input_streams = {activated_network.get_input_by_name(l.name): l.shape for l in hef.get_input_layers_info()}
send_process = Process(target=_send_process_hw_only_hef, args=(input_streams, iterations, fps, send_times))
output_streams = [activated_network.get_output_by_name(l.name) for l in hef.get_output_layers_info()]
recv_process = Process(target=_recv_process_hw_only_hef, args=(output_streams, iterations, end_time, recv_times))
start = time.time()
try:
logger.info("[{}] Starting Inference".format(start))
send_process.start()
recv_process.start()
except KeyboardInterrupt:
logger.info("Interrupted by the user, stopping..")
send_process.terminate()
recv_process.terminate()
except Exception:
logger.info("Exception happened, stopping..")
send_process.terminate()
recv_process.terminate()
finally:
send_process.join()
recv_process.join()
logger.info("[{}] Finished Inference".format(end_time.value))
latencies = [r-t for r,t in zip(recv_times, send_times)]
logger.info("-------------------------------------")
logger.info(" Infer Time: {:.3f} sec".format(end_time.value - start))
logger.info(" Average FPS: {:.3f}".format(iterations/(end_time.value - start)))
logger.info(" Average Latency: {:.3f} ms".format(np.average(latencies) * 1000.0))
logger.info("-------------------------------------")
def main():
logger.basicConfig(level=logger.INFO)
args = arg_prep()
logger.info('Reading HEF from: {}'.format(args.hef))
config = HEF(args.hef)
with HailoPcieObject() as target:
run_hef(target, config, args.iterations, args.mode, args.fps)
if __name__ == "__main__":
main()
cmake_minimum_required(VERSION 3.0.0)
# Setting the ARCH if not provided
if (NOT DEFINED ARCH)
execute_process(COMMAND uname -m OUTPUT_VARIABLE arch_from_cmd)
string(STRIP ${arch_from_cmd} arch_from_cmd)
set(ARCH ${arch_from_cmd})
endif()
# Setting the CMAKE_C_COMPILER if not provided
if (${ARCH} STREQUAL "aarch64")
if (NOT DEFINED CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER "/usr/bin/aarch64-linux-gnu-gcc")
endif()
else()
if (NOT DEFINED CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER "/usr/bin/gcc")
endif()
endif()
set(HAILORT_ROOT $ENV{HAILORT_ROOT})
set (HAILORT_LIB ${HAILORT_ROOT}/lib/${ARCH}/libhailort.so.0.5.0)
# set(HAILORT_LIB "${HAILORT_ROOT}/../lib/linux.x86_64.release/libhailort.so.0.5.0")
set(HAILORT_INCLUDE_DIR ${HAILORT_ROOT}/include)
message(STATUS ${HAILORT_LIB})
message(STATUS ${HAILORT_INCLUDE_DIR})
set(COMPILE_OPTIONS_CPP -Werror -O3 -DNDEBUG -std=c++11)
set(COMPILE_OPTIONS -O3 -DNDEBUG)
include_directories(${HAILORT_INCLUDE_DIR} "./")
find_package(Threads)
foreach(target example shortcut example_1rx_thread)
add_executable(${target} "${target}.c")
target_compile_options(${target} PRIVATE ${COMPILE_OPTIONS})
target_link_libraries(${target} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(${target} ${HAILORT_LIB})
endforeach(target)
#find_package( OpenCV REQUIRED )
#include_directories( ${OpenCV_INCLUDE_DIRS} )
# add_executable(md_example example_device.cpp main.cpp)
# target_compile_options(md_example PRIVATE ${COMPILE_OPTIONS_CPP})
# target_link_libraries(md_example ${CMAKE_THREAD_LIBS_INIT})
# target_link_libraries(md_example ${HAILORT_LIB})
#target_link_libraries(md_example ${OpenCV_LIBS})
\ No newline at end of file
To Compile all targets to all architectures (x86, armv7l, aarch64):
`build.sh`
\ No newline at end of file
#!/bin/bash
declare -A COMPILER=( [x86_64]=/usr/bin/gcc
[aarch64]=/usr/bin/aarch64-linux-gnu-gcc
[armv7l]=/usr/bin/arm-linux-gnueabi-gcc )
HAILORT_ROOT=/home/${USER}/SDK/2.12.1/cpu_sdk/platform/hailort
for ARCH in x86_64 aarch64 armv7l
do
echo "-I- Building ${ARCH}"
HAILORT_LIB=${HAILORT_ROOT}/lib/${ARCH}/libhailort.so.0.5.0
mkdir -p build/${ARCH}
HAILORT_ROOT=${HAILORT_ROOT} cmake -H. -Bbuild/${ARCH} -DARCH=${ARCH} -DCMAKE_C_COMPILER=${COMPILER[${ARCH}]}
cmake --build build/${ARCH}
done
\ No newline at end of file
This diff is collapsed.
#include <hailo/hailort.h>
#define FREE(var) \
do \
{ \
if (NULL != (var)) \
{ \
free(var); \
var = NULL; \
} \
} while (0)
#define REQUIRE_SUCCESS(status, label, msg) \
do \
{ \
if (HAILO_SUCCESS != (status)) \
{ \
printf(BOLDRED); \
printf("-E- %s : (%d)\n",msg, status); \
printf(RESET); \
goto label; \
} \
} while (0)
typedef struct write_thread_args_t
{
hailo_stream_info_t *input_stream_info;
hailo_input_stream input_stream;
hailo_status status;
int output_streams_cnt;
unsigned int num_images;
size_t host_frame_size;
} write_thread_args_t;
typedef struct recv_thread_args_t
{
hailo_stream_info_t *output_stream_info;
hailo_output_stream output_stream;
hailo_status status;
int tid;
unsigned int num_images;
int num_streams;
int write_log;
size_t host_frame_size;
} recv_thread_args_t;
typedef struct video_thread_args_t
{
hailo_stream_info_t *input_stream_info;
const char *video_path;
int num_images;
} video_thread_args_t;
#define RESET "\033[0m"
#define BLACK "\033[30m" /* Black */
#define RED "\033[31m" /* Red */
#define GREEN "\033[32m" /* Green */
#define YELLOW "\033[33m" /* Yellow */
#define BLUE "\033[34m" /* Blue */
#define MAGENTA "\033[35m" /* Magenta */
#define CYAN "\033[36m" /* Cyan */
#define WHITE "\033[37m" /* White */
#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */
#define BOLDRED "\033[1m\033[31m" /* Bold Red */
#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */
#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */
#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */
\ No newline at end of file
/**
* Copyright 2020 (C) Hailo Technologies Ltd.
* All rights reserved.
*
* Hailo Technologies Ltd. ("Hailo") disclaims any warranties, including, but not limited to,
* the implied warranties of merchantability and fitness for a particular purpose.
* This software is provided on an "AS IS" basis, and Hailo has no obligation to provide maintenance,
* support, updates, enhancements, or modifications.
*
* You may use this software in the development of any project.
* You shall not reproduce, modify or distribute this software without prior written permission.
**/
/**
* @ file main.cpp
* This example demonstrates the basic data-path on HailoRT.
* The program scans for Hailo-8 devices connected to a provided Ethernet interface, generates random dataset,
* and runs it through the device.
**/
#include "example_device.hpp"
#include <iostream>
#include <thread>
#include <functional>
#define NOF_DEVICES (2)
void thread_wrapper(std::string &iface, std::string &jlf_dir, unsigned int &num_img)
{
example_device dev(iface, jlf_dir, num_img, 0, 0);
dev.run_inference();
}
int main(int argc, char **argv)
{
std::string jlf_dir;
int opt;
std::string iface;
std::string iface2;
unsigned int num_img = 100;
int debug = 0;
int write_log = 0;
while ((opt = getopt(argc, argv, "i:j:w:n:k:dl")) != -1)
{
switch (opt)
{
case 'j':
jlf_dir = optarg;
break;
case 'i':
iface = optarg;
break;
case 'k':
iface2 = optarg;
break;
case 'n':
num_img = atoi(optarg);
break;
case 'd':
debug = 1;
break;
case 'l':
write_log = 1;
break;
case '?':
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
default:
fprintf(stderr, "Usage: %s -i INTERFACE -j JLF-DIR [-n NUM-IMAGES]\n\n", argv[0]);
fprintf(stderr, " -i INTERFACE The Ethernet interface, defaults to \'eno2\'\n");
fprintf(stderr, " -j JLF-DIR The JLFs directory, defaults to \'./JLFs/\'\n");
fprintf(stderr, " -n NUM-IMAGES The number of images to process, defaults to 100\n");
fprintf(stderr, " -d Read and print debug registers from FW\n");
fprintf(stderr, " -l Each receive thread will write a log file\n");
exit(EXIT_FAILURE);
}
}
try
{
std::cout << "-I- TEST STARTS" << std::endl;
std::thread t0(thread_wrapper, std::ref(iface), std::ref(jlf_dir), std::ref(num_img));
if (!iface2.empty())
{
std::cout << "-I- TEST STARTS" << std::endl;
std::thread t1(thread_wrapper, std::ref(iface2), std::ref(jlf_dir), std::ref(num_img));
t1.join();
}
t0.join();
}
catch (const std::exception &e)
{
std::cout << e.what();
}
}
\ No newline at end of file
cmake_minimum_required(VERSION 3.0.0)
# Setting the ARCH if not provided
if (NOT DEFINED ARCH)
execute_process(COMMAND uname -m OUTPUT_VARIABLE arch_from_cmd)
string(STRIP ${arch_from_cmd} arch_from_cmd)
set(ARCH ${arch_from_cmd})
endif()
# Setting the CMAKE_C_COMPILER if not provided
if (${ARCH} STREQUAL "aarch64")
if (NOT DEFINED CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER "/usr/bin/aarch64-linux-gnu-gcc")
endif()
else()
if (NOT DEFINED CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER "/usr/bin/gcc")
endif()
endif()
set(HAILORT_ROOT $ENV{HAILORT_ROOT})
set(HAILORT_LIB ${HAILORT_ROOT}/lib/${ARCH}/libhailort.so.2.1.0)
set(HAILORT_INCLUDE_DIR ${HAILORT_ROOT}/include)
message(STATUS ${HAILORT_LIB})
message(STATUS ${HAILORT_INCLUDE_DIR})
set(COMPILE_OPTIONS -DNDEBUG -O3)
find_package(Threads)
foreach(target example shortcut example_1rx_thread)
add_executable(${target} "${target}.c")
include_directories(${HAILORT_INCLUDE_DIR})
target_compile_options(${target} PRIVATE ${COMPILE_OPTIONS})
target_link_libraries(${target} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(${target} ${HAILORT_LIB})
endforeach(target)
To Compile all targets to all architectures (x86, armv7l, aarch64):
`build.sh`
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
To Compile all targets to all architectures (x86, armv7l, aarch64):
`build.sh`
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
To Compile all targets to all architectures (x86, armv7l, aarch64):
`build.sh`
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment