Compare commits

...

5 Commits

Author SHA1 Message Date
openvino-pushbot
30594bb309 Update readme 2019-01-21 23:30:11 +03:00
Alexey Suhov
9de27f16bc Publishing R5 content (#72)
* Publishing R5 content

* Updated ade revision

* updated readme

* add possibility to build CPU plugin with Intel MKL package
2019-01-21 21:31:31 +03:00
Alexey Suhov
fbc7a4a710 updated readme files (#54) 2018-12-14 21:26:38 +03:00
RachelRen05
e5d4940a0f update the dependency file to support ubuntu 18.04 (#17)
* update dependency file to support ubuntu 18.04

* update dependency file to support ubuntu 18.04
2018-12-14 21:09:44 +03:00
Alexey Suhov
3600f36d7b updated install_dependencies.sh and readme for python api (#43)
* use absolute path in readme for python api
* Update install_dependencies.sh
2018-11-29 21:04:21 +03:00
1617 changed files with 126416 additions and 17707 deletions

View File

@@ -1,5 +1,5 @@
# [OpenVINO™ Toolkit](https://01.org/openvinotoolkit) - Deep Learning Deployment Toolkit repository
[![Stable release](https://img.shields.io/badge/version-2018.R4-green.svg)](https://github.com/opencv/dldt/releases/tag/2018_R4)
[![Stable release](https://img.shields.io/badge/version-2018.R5-green.svg)](https://github.com/opencv/dldt/releases/tag/2018_R5)
[![Apache License Version 2.0](https://img.shields.io/badge/license-Apache_2.0-green.svg)](LICENSE)
This toolkit allows developers to deploy pre-trained deep learning models through a high-level C++ Inference Engine API integrated with application logic.

View File

@@ -1,6 +1,7 @@
# Copyright (C) 2018 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
cmake_minimum_required (VERSION 3.3)
project(InferenceEngine)
@@ -18,7 +19,9 @@ endif()
option (OS_FOLDER "create OS dedicated folder in output" OFF)
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
set (ARCH_FOLDER armv7l)
elseif("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
set (ARCH_FOLDER intel64)
else()
set (ARCH_FOLDER ia32)
@@ -46,7 +49,6 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "")
debug_message(STATUS "CMAKE_BUILD_TYPE not defined, 'Release' will be used")
set(CMAKE_BUILD_TYPE "Release")
endif()
message(STATUS "BUILD_CONFIGURATION: ${CMAKE_BUILD_TYPE}")
if(COVERAGE)
@@ -55,17 +57,38 @@ endif()
if (UNIX)
SET(LIB_DL ${CMAKE_DL_LIBS})
else()
endif()
set (OUTPUT_ROOT ${IE_MAIN_SOURCE_DIR})
if(NOT(UNIX))
if (WIN32)
#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
endif()
include(os_flags)
#resolving dependencies for the project
include (dependencies)
set(CMAKE_DEBUG_POSTFIX ${IE_DEBUG_POSTFIX})
set(CMAKE_RELEASE_POSTFIX ${IE_RELEASE_POSTFIX})
if (WIN32)
# Support CMake multiconfiguration for Visual Studio build
set(IE_BUILD_POSTFIX $<$<CONFIG:Debug>:${IE_DEBUG_POSTFIX}>$<$<CONFIG:Release>:${IE_RELEASE_POSTFIX}>)
set(IE_BUILD_CONFIGURATION $<CONFIG>)
else ()
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug" )
set(IE_BUILD_POSTFIX ${IE_DEBUG_POSTFIX})
else()
set(IE_BUILD_POSTFIX ${IE_RELEASE_POSTFIX})
endif()
set(IE_BUILD_CONFIGURATION ${CMAKE_BUILD_TYPE})
endif()
add_definitions(-DIE_BUILD_POSTFIX=\"${IE_BUILD_POSTFIX}\")
if(NOT(UNIX))
if (WIN32)
#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
endif()
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_ROOT}/${BIN_FOLDER})
set (CMAKE_LIBRARY_PATH ${OUTPUT_ROOT}/${BIN_FOLDER})
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_ROOT}/${BIN_FOLDER})
@@ -75,20 +98,15 @@ if(NOT(UNIX))
set (LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_ROOT}/${BIN_FOLDER})
set (LIBRARY_OUTPUT_PATH ${LIBRARY_OUTPUT_DIRECTORY}) # compatibility issue: linux uses LIBRARY_OUTPUT_PATH, windows uses LIBRARY_OUTPUT_DIRECTORY
else ()
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_ROOT}/${BIN_FOLDER}/${CMAKE_BUILD_TYPE}/lib)
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_ROOT}/${BIN_FOLDER}/${CMAKE_BUILD_TYPE}/lib)
set (CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY ${OUTPUT_ROOT}/${BIN_FOLDER}/${CMAKE_BUILD_TYPE})
set (CMAKE_PDB_OUTPUT_DIRECTORY ${OUTPUT_ROOT}/${BIN_FOLDER}/${CMAKE_BUILD_TYPE})
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_ROOT}/${BIN_FOLDER}/${CMAKE_BUILD_TYPE})
set (LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_ROOT}/${BIN_FOLDER}/${CMAKE_BUILD_TYPE}/lib)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_ROOT}/${BIN_FOLDER}/${IE_BUILD_CONFIGURATION}/lib)
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OUTPUT_ROOT}/${BIN_FOLDER}/${IE_BUILD_CONFIGURATION}/lib)
set (CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY ${OUTPUT_ROOT}/${BIN_FOLDER}/${IE_BUILD_CONFIGURATION})
set (CMAKE_PDB_OUTPUT_DIRECTORY ${OUTPUT_ROOT}/${BIN_FOLDER}/${IE_BUILD_CONFIGURATION})
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_ROOT}/${BIN_FOLDER}/${IE_BUILD_CONFIGURATION})
set (LIBRARY_OUTPUT_DIRECTORY ${OUTPUT_ROOT}/${BIN_FOLDER}/${IE_BUILD_CONFIGURATION}/lib)
set (LIBRARY_OUTPUT_PATH ${LIBRARY_OUTPUT_DIRECTORY}/lib)
endif()
include(os_flags)
#resolving rependencies for the project
include (dependencies)
if (APPLE)
set(CMAKE_MACOSX_RPATH 1)
endif(APPLE)
@@ -108,9 +126,8 @@ message (STATUS "IE_MAIN_SOURCE_DIR .................... " ${IE_MAIN_SOURCE_DIR}
message (STATUS "CMAKE_GENERATOR ....................... " ${CMAKE_GENERATOR})
message (STATUS "CMAKE_C_COMPILER_ID ................... " ${CMAKE_C_COMPILER_ID})
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
include(sdl)
endif()
include(sdl)
set (CMAKE_POSITION_INDEPENDENT_CODE ON)
include (sanitizer)
@@ -131,6 +148,10 @@ if (ENABLE_SAMPLES_CORE)
set(InferenceEngine_DIR "${CMAKE_BINARY_DIR}")
#to be able to link
set (LIB_FOLDER ${IE_MAIN_SOURCE_DIR}/${BIN_FOLDER}/${CMAKE_BUILD_TYPE}/lib)
set (LIB_FOLDER ${IE_MAIN_SOURCE_DIR}/${BIN_FOLDER}/${IE_BUILD_CONFIGURATION}/lib)
add_subdirectory(samples)
endif()
if (ENABLE_PYTHON)
add_subdirectory(ie_bridges/python)
endif()

View File

@@ -8,6 +8,7 @@ The software was validated on:
### Software Requirements
- [CMake\*](https://cmake.org/download/) 3.9 or higher
- GCC\* 4.8 or higher to build the Inference Engine
- Python 2.7 or higher for Inference Engine Python API wrapper
### Build Steps
1. Clone submodules:
@@ -29,6 +30,11 @@ You can use the following additional build options:
- Internal JIT GEMM implementation is used by default.
- To switch to OpenBLAS\* implementation, use `GEMM=OPENBLAS` option and `BLAS_INCLUDE_DIRS` and `BLAS_LIBRARIES` cmake options to specify path to OpenBLAS headers and library, for example use the following options on CentOS\*: `-DGEMM=OPENBLAS -DBLAS_INCLUDE_DIRS=/usr/include/openblas -DBLAS_LIBRARIES=/usr/lib64/libopenblas.so.0`
- To switch to optimized MKL-ML\* GEMM implementation, use `GEMM=MKL` and `MKLROOT` cmake options to specify path to unpacked MKL-ML with `include` and `lib` folders, for example use the following options: `-DGEMM=MKL -DMKLROOT=<path_to_MKL>`. MKL-ML\* package can be downloaded [here](https://github.com/intel/mkl-dnn/releases/download/v0.17/mklml_lnx_2019.0.1.20180928.tgz)
- OpenMP threading is used by default. To build Inference Engine with TBB threading, set `-DTHREADING=TBB` option.
- To build Python API wrapper, use -DENABLE_PYTHON=ON option. To specify exact Python version, use the following options: `-DPYTHON_EXECUTABLE=`which python3.6` -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so -DPYTHON_INCLUDE_DIR=/usr/include/python3.6`
- To switch on/off the CPU and GPU plugins, use `cmake` options `-DENABLE_MKL_DNN=ON/OFF` and `-DENABLE_CLDNN=ON/OFF`.
## Build on Windows\* Systems:
@@ -41,6 +47,7 @@ The software was validated on:
- [CMake\*](https://cmake.org/download/) 3.9 or higher
- [OpenBLAS\*](https://sourceforge.net/projects/openblas/files/v0.2.14/OpenBLAS-v0.2.14-Win64-int64.zip/download) and [mingw64\* runtime dependencies](https://sourceforge.net/projects/openblas/files/v0.2.14/mingw64_dll.zip/download).
- [Intel® C++ Compiler](https://software.intel.com/en-us/intel-parallel-studio-xe) 18.0 to build the Inference Engine on Windows.
- Python 3.4 or higher for Inference Engine Python API wrapper
### Build Steps
1. Clone submodules:
@@ -59,15 +66,32 @@ The software was validated on:
5. In the `build` directory, run `cmake` to fetch project dependencies and generate a Visual Studio solution:
```sh
cd build
cmake -G "Visual Studio 15 2017 Win64" -T "Intel C++ Compiler 18.0" -DOS_FOLDER=ON ^
cmake -G "Visual Studio 15 2017 Win64" -T "Intel C++ Compiler 18.0" ^
-DCMAKE_BUILD_TYPE=Release ^
-DICCLIB="C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018\windows\compiler\lib" ..
```
- Internal JIT GEMM implementation is used by default.
- To switch to OpenBLAS GEMM implementation, use -DGEMM=OPENBLAS cmake option and specify path to OpenBLAS using `-DBLAS_INCLUDE_DIRS=<OPENBLAS_DIR>\include` and `-DBLAS_LIBRARIES=<OPENBLAS_DIR>\lib\libopenblas.dll.a` options. Prebuilt OpenBLAS\* package can be downloaded [here](https://sourceforge.net/projects/openblas/files/v0.2.14/OpenBLAS-v0.2.14-Win64-int64.zip/download), mingw64* runtime dependencies [here](https://sourceforge.net/projects/openblas/files/v0.2.14/mingw64_dll.zip/download)
- To switch to optimized MKL-ML GEMM implementation, use `GEMM=MKL` and `MKLROOT` cmake options to specify path to unpacked MKL-ML with `include` and `lib` folders, for example use the following options: `-DGEMM=MKL -DMKLROOT=<path_to_MKL>`. MKL-ML\* package can be downloaded [here](https://github.com/intel/mkl-dnn/releases/download/v0.17/mklml_win_2019.0.1.20180928.zip)
- OpenMP threading is used by default. To build Inference Engine with TBB threading, set `-DTHREADING=TBB` option.
- To build Python API wrapper, use -DENABLE_PYTHON=ON option. To specify exact Python version, use the following options: `-DPYTHON_EXECUTABLE="C:\Program Files\Python36\python.exe" -DPYTHON_INCLUDE_DIR="C:\Program Files\Python36\include" -DPYTHON_LIBRARY="C:\Program Files\Python36\libs\python36.lib"`.
6. Build generated solution in Visual Studio 2017 or run `cmake --build . --config Release` to build from the command line.
### Building Inference Engine with Ninja
```sh
call "C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018\windows\bin\ipsxe-comp-vars.bat" intel64 vs2017
set CXX=icl
set CC=icl
cmake -G Ninja -Wno-dev -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --config Release
```
Before running the samples on Microsoft\* Windows\*, please add path to OpenMP library (<dldt_repo>/inference-engine/temp/omp/lib) and OpenCV libraries (<dldt_repo>/inference-engine/temp/opencv_4.0.0/bin) to the %PATH% environment variable.
---
\* Other names and brands may be claimed as the property of others.

View File

@@ -0,0 +1,39 @@
# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
#module to locate GNA libraries
cmake_minimum_required(VERSION 2.8)
if (WIN32)
set(GNA_PLATFORM_DIR win64)
set(GNA_LIB_DIR x64)
set(GNA_LIB gna)
elseif (UNIX)
set(GNA_PLATFORM_DIR linux)
set(GNA_LIB_DIR lib)
set(GNA_LIB gna_api)
set(GNA_KERNEL_LIB gna_kernel)
else ()
message(FATAL_ERROR "GNA not supported on this platform, only linux, and windows")
endif ()
find_library(GNA_API_LIBRARY
${GNA_LIB}
HINTS
${GNA}/${GNA_PLATFORM_DIR}/${GNA_LIB_DIR})
set(libGNA_INCLUDE_DIRS ${GNA}/${GNA_PLATFORM_DIR}/include)
set(libGNA_LIBRARY ${GNA_API_LIBRARY})
if (UNIX)
#message("Searching for libgna_kernel.so in: ${GNA}/${GNA_PLATFORM_DIR}/${GNA_KERNEL_LIB}")
find_library(GNA_KERNEL_LIBRARY
${GNA_KERNEL_LIB}
HINTS
${GNA}/${GNA_PLATFORM_DIR}/${GNA_LIB_DIR})
endif ()
set(libGNA_LIBRARIES ${libGNA_LIBRARY} ${GNA_KERNEL_LIBRARY})

View File

@@ -0,0 +1,10 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armv7l)
set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

View File

@@ -2,11 +2,9 @@
#
# SPDX-License-Identifier: Apache-2.0
#
include("features")
include("mode")
if (THREADING STREQUAL "OMP")
include("omp")
endif()
include("itt")
#64 bits platform
@@ -28,17 +26,15 @@ else()
SET(ENABLE_MKL_DNN OFF)
endif()
#apple specific
if (APPLE)
set(ENABLE_GNA OFF)
set(ENABLE_CLDNN OFF)
endif()
#minGW specific - under wine no support for downloading file and applying them using git
if (WIN32)
enable_omp()
if (MINGW)
SET(ENABLE_CLDNN OFF) # dont have mingw dll for linking
set(ENABLE_SAMPLES OFF)
@@ -61,7 +57,7 @@ if (LINUX)
endif ()
if (NOT ENABLE_MKL_DNN)
set(GEMM OPENBLAS)
set(ENABLE_MKL OFF)
endif()
#next section set defines to be accesible in c++/c code for certain feature
@@ -93,6 +89,10 @@ if (ENABLE_OBJECT_DETECTION_TESTS)
add_definitions(-DENABLE_OBJECT_DETECTION_TESTS=1)
endif()
if (ENABLE_GNA)
add_definitions(-DENABLE_GNA)
endif()
if (DEVELOPMENT_PLUGIN_MODE)
message (STATUS "Enabled development plugin mode")
@@ -112,9 +112,5 @@ if (VERBOSE_BUILD)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif()
if (THREADING STREQUAL "TBB" OR THREADING STREQUAL "SEQ")
set(ENABLE_INTEL_OMP OFF)
message(STATUS "ENABLE_INTEL_OMP should be disabled if THREADING is TBB or Sequential. ENABLE_INTEL_OMP option is " ${ENABLE_INTEL_OMP})
endif()
print_enabled_features()
print_enabled_features()

View File

@@ -1,6 +1,8 @@
# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
if(DEFINED IE_MAIN_SOURCE_DIR AND TARGET inference_engine)
set(InferenceEngine_INCLUDE_DIRS ${IE_MAIN_SOURCE_DIR}/include)
set(InferenceEngine_LIBRARIES inference_engine)

View File

@@ -67,3 +67,8 @@ function (log_rpath component lib_path)
log_rpath_remove_top(${component} TRUE ${lib_path} TRUE)
endfunction()
# Just wrapping of the original message() function to make this macro known during IE build.
# This macro is redefined (with additional checks) within the InferenceEngineConfig.cmake file.
macro(ext_message TRACE_LEVEL)
message(${TRACE_LEVEL} "${ARGN}")
endmacro()

View File

@@ -59,10 +59,12 @@ if (GEMM STREQUAL "MKL")
if(NOT MKLROOT)
message(FATAL_ERROR "MKLROOT not found: install MKL and set -DMKLROOT=<path_to_MKL>")
endif()
set(MKL ${MKLROOT})
debug_message(STATUS "mkl_ml=" ${MKLROOT})
endif ()
if (ENABLE_INTEL_OMP)
## Intel OMP package
if (THREADING STREQUAL "OMP")
if (WIN32)
RESOLVE_DEPENDENCY(OMP
ARCHIVE_WIN "iomp.zip"
@@ -80,36 +82,29 @@ log_rpath_from_dir(OMP "${OMP}/lib")
debug_message(STATUS "intel_omp=" ${OMP})
endif ()
#TBB package
## TBB package
if (THREADING STREQUAL "TBB")
if (WIN32)
#TODO: add target_path to be platform specific as well, to avoid following if
RESOLVE_DEPENDENCY(TBB
ARCHIVE_WIN "tbb2018_20180618_win.zip" #TODO: windows zip archive created incorrectly using old name for folder
ARCHIVE_WIN "tbb2019_20181010_win.zip" #TODO: windows zip archive created incorrectly using old name for folder
TARGET_PATH "${TEMP}/tbb"
ENVIRONMENT "TBBROOT"
VERSION_REGEX ".*_([a-z]*_([a-z0-9]+\\.)*[0-9]+).*")
elseif(LINUX)
RESOLVE_DEPENDENCY(TBB
ARCHIVE_LIN "tbb2018_20180618_lin.tgz"
ARCHIVE_LIN "tbb2019_20181010_lin.tgz"
TARGET_PATH "${TEMP}/tbb"
ENVIRONMENT "TBBROOT")
endif()
set(TBB_INCLUDE_DIRS "${TBB}/include")
find_path(TBB_INCLUDE_DIRS tbb/tbb.h)
find_library(TBB_LIBRARIES_RELEASE tbb HINTS "${TBB}/lib")
if (TBB_INCLUDE_DIRS AND TBB_LIBRARIES_RELEASE)
log_rpath_from_dir(TBB "${TBB}/lib")
else()
message("FATAL_ERROR" "TBB is unset")
endif()
log_rpath_from_dir(TBB "${TBB}/lib")
debug_message(STATUS "tbb=" ${TBB})
endif ()
if (ENABLE_OPENCV)
if (WIN32)
RESOLVE_DEPENDENCY(OPENCV
ARCHIVE_WIN "opencv_4.0.0-0256.zip"
ARCHIVE_WIN "opencv_4.0.1-0353.zip"
TARGET_PATH "${TEMP}/opencv_4.0.0"
ENVIRONMENT "OpenCV_DIR"
VERSION_REGEX ".*_([0-9]+.[0-9]+.[0-9]+).*")
@@ -118,14 +113,21 @@ if (WIN32)
elseif(LINUX)
if (${LINUX_OS_NAME} STREQUAL "Ubuntu 16.04")
RESOLVE_DEPENDENCY(OPENCV
ARCHIVE_LIN "opencv_4.0.0-0256_ubuntu16.tgz"
ARCHIVE_LIN "opencv_4.0.0-0305_ubuntu16.tgz"
TARGET_PATH "${TEMP}/opencv_4.0.0_ubuntu"
ENVIRONMENT "OpenCV_DIR"
VERSION_REGEX ".*_([0-9]+.[0-9]+.[0-9]+).*")
log_rpath_from_dir(OPENCV "opencv_4.0.0_ubuntu/lib")
elseif (${LINUX_OS_NAME} STREQUAL "Ubuntu 18.04")
RESOLVE_DEPENDENCY(OPENCV
ARCHIVE_LIN "opencv_4.0.0-0305_ubuntu18.tgz"
TARGET_PATH "${TEMP}/opencv_4.0.0_ubuntu18"
ENVIRONMENT "OpenCV_DIR"
VERSION_REGEX ".*_([0-9]+.[0-9]+.[0-9]+).*")
log_rpath_from_dir(OPENCV "opencv_4.0.0_ubuntu/lib")
elseif (${LINUX_OS_NAME} STREQUAL "CentOS 7")
RESOLVE_DEPENDENCY(OPENCV
ARCHIVE_LIN "opencv_4.0.0-0256_centos.tgz"
ARCHIVE_LIN "opencv_4.0.0-0305_centos.tgz"
TARGET_PATH "${TEMP}/opencv_4.0.0_centos"
ENVIRONMENT "OpenCV_DIR"
VERSION_REGEX ".*_([0-9]+.[0-9]+.[0-9]+).*")
@@ -136,6 +138,26 @@ endif()
debug_message(STATUS "opencv=" ${OPENCV})
endif()
if (THREADING STREQUAL "OMP")
include(omp)
endif ()
include(ie_parallel)
if (ENABLE_GNA)
RESOLVE_DEPENDENCY(GNA
ARCHIVE_UNIFIED "gna_20181120.zip"
TARGET_PATH "${TEMP}/gna")
endif()
configure_file(
"${CMAKE_SOURCE_DIR}/cmake/share/InferenceEngineConfig.cmake.in"
"${CMAKE_BINARY_DIR}/share/InferenceEngineConfig.cmake"
@ONLY)
configure_file(
"${CMAKE_SOURCE_DIR}/cmake/share/InferenceEngineConfig-version.cmake.in"
"${CMAKE_BINARY_DIR}/share/InferenceEngineConfig-version.cmake"
COPYONLY)
configure_file(
"${CMAKE_SOURCE_DIR}/cmake/ie_parallel.cmake"
"${CMAKE_BINARY_DIR}/share/ie_parallel.cmake"
COPYONLY)

View File

@@ -144,7 +144,7 @@ function (CheckOrDownloadAndExtract component RELATIVE_URL archive_name unpacked
set (status "ON")
set (on_master FALSE)
set (URL "https://download.01.org/openvinotoolkit/2018_R4/dldt/inference_engine/${RELATIVE_URL}")
set (URL "https://download.01.org/openvinotoolkit/2018_R5/dldt/inference_engine/${RELATIVE_URL}")
#no message on recursive calls
if (${use_alternatives})

View File

@@ -11,6 +11,8 @@ include ("options")
#backed targets
ie_option (ENABLE_GNA "GNA support for inference engine" ON)
ie_option (ENABLE_MKL_DNN "MKL-DNN plugin for inference engine" ON)
ie_option (ENABLE_CLDNN "clDnn based plugin for inference engine" ON)
@@ -22,23 +24,45 @@ ie_option (ENABLE_PROFILING_RAW "Raw counters profiling (just values, no start/s
#
# "MKL-DNN library might use MKL-ML or OpenBLAS for gemm tasks: MKL|OPENBLAS|JIT"
if (NOT GEMM STREQUAL "MKL" AND NOT GEMM STREQUAL "OPENBLAS" AND NOT GEMM STREQUAL "JIT")
if (NOT GEMM STREQUAL "MKL"
AND NOT GEMM STREQUAL "OPENBLAS"
AND NOT GEMM STREQUAL "JIT")
set (GEMM "JIT")
message(STATUS "GEMM should be set to MKL|OPENBLAS|JIT. Default option is " ${GEMM})
message(STATUS "GEMM should be set to MKL, OPENBLAS or JIT. Default option is " ${GEMM})
endif()
list (APPEND IE_OPTIONS GEMM)
# "MKL-DNN library based on OMP or TBB or Sequential implementation: TBB|OMP|SEQ"
if (NOT THREADING STREQUAL "TBB" AND NOT THREADING STREQUAL "OMP" AND NOT THREADING STREQUAL "SEQ")
if (NOT THREADING STREQUAL "TBB"
AND NOT THREADING STREQUAL "OMP"
AND NOT THREADING STREQUAL "SEQ")
set (THREADING "OMP")
message(STATUS "THREADING should be set to TBB|OMP|SEQ. Default option is " ${THREADING})
message(STATUS "THREADING should be set to TBB, OMP or SEQ. Default option is " ${THREADING})
endif()
list (APPEND IE_OPTIONS THREADING)
ie_option (ENABLE_INTEL_OMP "MKL-DNN library based on Intel OMP implementation" ON)
# Enable postfixes for Debug/Release builds
set (IE_DEBUG_POSTFIX_WIN "d")
set (IE_RELEASE_POSTFIX_WIN "")
set (IE_DEBUG_POSTFIX_LIN "")
set (IE_RELEASE_POSTFIX_LIN "")
if (WIN32)
set (IE_DEBUG_POSTFIX ${IE_DEBUG_POSTFIX_WIN})
set (IE_RELEASE_POSTFIX ${IE_RELEASE_POSTFIX_WIN})
else()
set (IE_DEBUG_POSTFIX ${IE_DEBUG_POSTFIX_LIN})
set (IE_RELEASE_POSTFIX ${IE_RELEASE_POSTFIX_LIN})
endif()
list (APPEND IE_OPTIONS IE_DEBUG_POSTFIX)
list (APPEND IE_OPTIONS IE_RELEASE_POSTFIX)
ie_option (ENABLE_TESTS "unit and functional tests" OFF)
ie_option (ENABLE_GAPI_TESTS "unit tests for GAPI kernels" OFF)
ie_option (GAPI_TEST_PERF "if GAPI unit tests should examine performance" OFF)
ie_option (ENABLE_SAMPLES_CORE "console samples core library" ON)
ie_option (ENABLE_SANITIZER "enable checking memory errors via AddressSanitizer" OFF)
@@ -63,6 +87,12 @@ ie_option (OS_FOLDER "create OS dedicated folder in output" OFF)
ie_option (ENABLE_PLUGIN_RPATH "enables rpath information to be present in plugins binary, and in corresponding test_applications" ON)
ie_option (ENABLE_AFFINITY_GENERATOR "enables affinity generator build" OFF)
ie_option (ENABLE_DEBUG_SYMBOLS "generates symbols for debugging" OFF)
ie_option (ENABLE_PYTHON "enables ie python bridge build" OFF)
#environment variables used
#name of environment variable stored path to temp directory"

View File

@@ -0,0 +1,100 @@
# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
function(set_ie_threading_interface_for TARGET_NAME)
set(IE_THREAD_DEFINE "IE_THREAD_SEQ")
if (THREADING STREQUAL "TBB")
if (NOT (IE_MAIN_SOURCE_DIR))
set(incl_path ${IE_EXTERNAL_DIR}/tbb/include)
if (WIN32)
set(lib_rel_path ${IE_LIB_REL_DIR})
set(lib_dbg_path ${IE_LIB_DBG_DIR})
else ()
set(lib_rel_path ${IE_EXTERNAL_DIR}/tbb/lib)
set(lib_dbg_path ${lib_rel_path})
endif ()
else ()
set(incl_path ${TBB}/include)
set(lib_rel_path ${TBB}/lib)
set(lib_dbg_path ${lib_rel_path})
endif ()
if (NOT TBB_INCLUDE_DIRS OR NOT TBB_LIBRARIES_RELEASE OR NOT TBB_LIBRARIES_DEBUG)
find_path(TBB_INCLUDE_DIRS tbb/tbb.h ${incl_path} NO_DEFAULT_PATH)
find_library(TBB_LIBRARIES_RELEASE tbb ${lib_rel_path} NO_DEFAULT_PATH)
find_library(TBB_LIBRARIES_DEBUG tbb_debug ${lib_dbg_path} NO_DEFAULT_PATH)
ext_message(STATUS "TBB include: ${TBB_INCLUDE_DIRS}")
ext_message(STATUS "TBB Release lib: ${TBB_LIBRARIES_RELEASE}")
ext_message(STATUS "TBB Debug lib: ${TBB_LIBRARIES_DEBUG}")
endif ()
if (NOT TBB_INCLUDE_DIRS OR NOT TBB_LIBRARIES_RELEASE OR NOT TBB_LIBRARIES_DEBUG)
ext_message(WARNING "TBB not found. TBB support will be disabled. ${IE_THREAD_DEFINE} is defined")
else ()
set(IE_THREAD_DEFINE "IE_THREAD_TBB")
target_include_directories(${TARGET_NAME} PUBLIC ${TBB_INCLUDE_DIRS})
if (WIN32)
target_link_libraries(${TARGET_NAME} PUBLIC "-nodefaultlib:vcomp")
target_link_libraries(${TARGET_NAME} PUBLIC "$<$<CONFIG:DEBUG>:${TBB_LIBRARIES_DEBUG}>;$<$<NOT:$<CONFIG:DEBUG>>:${TBB_LIBRARIES_RELEASE}>")
else()
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
target_link_libraries(${TARGET_NAME} PUBLIC ${TBB_LIBRARIES_DEBUG})
else()
target_link_libraries(${TARGET_NAME} PUBLIC ${TBB_LIBRARIES_RELEASE})
endif ()
endif ()
endif ()
elseif (THREADING STREQUAL "OMP")
if (WIN32)
set(omp_lib_name libiomp5md)
else ()
set(omp_lib_name iomp5)
endif ()
if (NOT(IE_MAIN_SOURCE_DIR))
if (WIN32)
set(lib_rel_path ${IE_LIB_REL_DIR})
set(lib_dbg_path ${IE_LIB_DBG_DIR})
else ()
set(lib_rel_path ${IE_EXTERNAL_DIR}/omp/lib)
set(lib_dbg_path ${lib_rel_path})
endif ()
else ()
set(lib_rel_path ${OMP}/lib)
set(lib_dbg_path ${lib_rel_path})
endif ()
if (NOT OMP_LIBRARIES_RELEASE OR NOT OMP_LIBRARIES_DEBUG)
find_library(OMP_LIBRARIES_RELEASE ${omp_lib_name} ${lib_rel_path} NO_DEFAULT_PATH)
find_library(OMP_LIBRARIES_DEBUG ${omp_lib_name} ${lib_dbg_path} NO_DEFAULT_PATH)
ext_message(STATUS "OMP Release lib: ${OMP_LIBRARIES_RELEASE}")
ext_message(STATUS "OMP Debug lib: ${OMP_LIBRARIES_DEBUG}")
endif ()
if (NOT OMP_LIBRARIES_RELEASE OR NOT OMP_LIBRARIES_DEBUG)
ext_message(WARNING "Intel OpenMP not found. Intel OpenMP support will be disabled. ${IE_THREAD_DEFINE} is defined")
else ()
set(IE_THREAD_DEFINE "IE_THREAD_OMP")
if (WIN32)
target_compile_options(${TARGET_NAME} PUBLIC ${OpenMP_CXX_FLAGS} /openmp)
target_compile_options(${TARGET_NAME} PUBLIC ${OpenMP_CXX_FLAGS} /Qopenmp)
target_link_libraries(${TARGET_NAME} PUBLIC "-nodefaultlib:vcomp")
target_link_libraries(${TARGET_NAME} PUBLIC "$<$<CONFIG:DEBUG>:${OMP_LIBRARIES_DEBUG}>;$<$<NOT:$<CONFIG:DEBUG>>:${OMP_LIBRARIES_RELEASE}>")
else()
target_compile_options(${TARGET_NAME} PUBLIC ${OpenMP_CXX_FLAGS} -fopenmp)
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
target_link_libraries(${TARGET_NAME} PUBLIC ${OMP_LIBRARIES_DEBUG})
else()
target_link_libraries(${TARGET_NAME} PUBLIC ${OMP_LIBRARIES_RELEASE})
endif ()
endif ()
endif ()
endif ()
target_compile_definitions(${TARGET_NAME} PUBLIC -DIE_THREAD=${IE_THREAD_DEFINE})
endfunction(set_ie_threading_interface_for)

View File

@@ -1,59 +0,0 @@
# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
cmake_policy(SET CMP0054 NEW)
if (APPLE OR WIN32)
find_path(OMP_INC omp.h)
find_library(OMP_LIB iomp5
PATHS ${OMP}/lib)
if (OMP_INC AND OMP_LIB)
set(HAVE_OMP TRUE)
get_filename_component(OMP_LIB_DIR "${OMP_LIB}" PATH)
else()
if (THREADING STREQUAL "OMP")
find_package(OpenMP)
if (NOT OPENMP_FOUND)
message(WARNING "OpenMP not found. OpenMP support will be disabled.")
endif()
endif()
endif()
endif()
macro(enable_omp)
if (APPLE) ## MacOS
if (HAVE_OMP)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp=libiomp5")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L${OMP_LIB_DIR}")
else()
message(WARNING "Was trying to enable OMP for some target. However OpenMP was not detected on system.")
endif()
elseif(UNIX) # Linux
add_definitions(-fopenmp)
elseif(WIN32) # Windows
if (THREADING STREQUAL "OMP")
set(OPENMP_FLAGS "/Qopenmp /openmp")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CCXX_FLAGS} ${OPENMP_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CCXX_FLAGS} ${OPENMP_FLAGS}")
endif()
endif()
if (ENABLE_INTEL_OMP)
if (WIN32)
find_library(intel_omp_lib
libiomp5md
PATHS ${OMP}/lib ${ICCLIB})
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /nodefaultlib:vcomp")
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /nodefaultlib:vcomp")
else()
find_library(intel_omp_lib
iomp5
PATHS ${OMP}/lib)
endif()
endif()
endmacro(enable_omp)

View File

@@ -2,8 +2,8 @@
#
# SPDX-License-Identifier: Apache-2.0
#
# Usage: ie_option(<option_variable> "description" <initial value or boolean expression> [IF <condition>])
function (ie_option variable description value)
option(${variable} "${description}" ${value})
list (APPEND IE_OPTIONS "${variable}")

View File

@@ -7,12 +7,33 @@ if (WIN32)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS _CRT_SECURE_NO_WARNINGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_SCL_SECURE_NO_WARNINGS")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") #no asynchronous structured exception handling
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
if(ENABLE_DEBUG_SYMBOLS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Zi")
set(DEBUG_SYMBOLS_LINKER_FLAGS "/DEBUG")
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
# Keep default /OPT values. See /DEBUG reference for details.
set(DEBUG_SYMBOLS_LINKER_FLAGS "${DEBUG_SYMBOLS_LINKER_FLAGS} /OPT:REF /OPT:ICF")
endif()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${DEBUG_SYMBOLS_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${DEBUG_SYMBOLS_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${DEBUG_SYMBOLS_LINKER_FLAGS}")
endif()
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type ")
if (APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=unused-command-line-argument")
elseif(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wuninitialized -Winit-self -Wmaybe-uninitialized")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wuninitialized -Winit-self")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmaybe-uninitialized")
endif()
endif()
endif()

View File

@@ -3,9 +3,18 @@
# SPDX-License-Identifier: Apache-2.0
#
include(CheckCXXCompilerFlag)
if (ENABLE_SANITIZER)
set(CMAKE_CCXX_FLAGS "${CMAKE_CCXX_FLAGS} -fsanitize=address -fuse-ld=gold")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fuse-ld=gold")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
endif()
set(SANITIZER_COMPILER_FLAGS "-fsanitize=address")
CHECK_CXX_COMPILER_FLAG("-fsanitize-recover=address" SANITIZE_RECOVER_SUPPORTED)
if (SANITIZE_RECOVER_SUPPORTED)
set(SANITIZER_COMPILER_FLAGS "${SANITIZER_COMPILER_FLAGS} -fsanitize-recover=address")
endif()
set(SANITIZER_LINKER_FLAGS "-fsanitize=address -fuse-ld=gold")
set(CMAKE_CC_FLAGS "${CMAKE_CC_FLAGS} ${SANITIZER_COMPILER_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZER_COMPILER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${SANITIZER_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_LINKER_FLAGS}")
endif()

View File

@@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0
#
if (UNIX OR APPLE)
if (UNIX OR APPLE AND ${CMAKE_BUILD_TYPE} STREQUAL "Release")
set(CMAKE_CCXX_FLAGS "${CMAKE_CCXX_FLAGS} -fPIE -fPIC -Wformat -Wformat-security")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -D_FORTIFY_SOURCE=2")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -D_FORTIFY_SOURCE=2")
@@ -16,21 +16,24 @@ if (UNIX OR APPLE)
else()
set(CMAKE_CCXX_FLAGS "${CMAKE_CCXX_FLAGS} -fstack-protector-strong")
endif()
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s -fvisibility=hidden")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s -fvisibility=hidden")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CCXX_FLAGS "${CMAKE_CCXX_FLAGS} -fstack-protector-all")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fvisibility=hidden")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fvisibility=hidden")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -z noexecstack -z relro -z now")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z noexecstack -z relro -z now")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wl,--strip-all -fvisibility=hidden")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wl,--strip-all -fvisibility=hidden")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CCXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CCXX_FLAGS}")
elseif (WIN32)
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /sdl")
if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MP /sdl")
endif()
endif()

View File

@@ -1,7 +1,9 @@
# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
set(InferenceEngine_VERSION 1.4.0)
set(InferenceEngine_VERSION 1.5.0)
set(PACKAGE_VERSION ${InferenceEngine_VERSION})
set(PACKAGE_VERSION_EXACT False)

View File

@@ -1,6 +1,8 @@
# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
#
# FindIE
# ------
#
@@ -17,6 +19,18 @@
# IE::inference_engine - The Inference Engine library
#
macro(ext_message TRACE_LEVEL)
if (${TRACE_LEVEL} STREQUAL FATAL_ERROR)
if(InferenceEngine_FIND_REQUIRED)
message(FATAL_ERROR "${ARGN}")
elseif(NOT InferenceEngine_FIND_QUIETLY)
message(WARNING "${ARGN}")
endif()
return()
elseif(NOT InferenceEngine_FIND_QUIETLY)
message(${TRACE_LEVEL} "${ARGN}")
endif ()
endmacro()
set(InferenceEngine_FOUND FALSE)
@@ -28,13 +42,17 @@ else()
if (WIN32)
set(_ARCH intel64)
else()
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
set(_ARCH armv7l)
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
set(_ARCH intel64)
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386")
set(_ARCH ia32)
endif()
endif()
set(THREADING "@THREADING@")
# check whether setvars.sh is sourced
if(NOT IE_ROOT_DIR AND (DEFINED ENV{InferenceEngine_DIR} OR InferenceEngine_DIR OR DEFINED ENV{INTEL_CVSDK_DIR}))
if (EXISTS "${InferenceEngine_DIR}")
@@ -57,7 +75,7 @@ else()
set(_OS_PATH "")
else()
if (NOT EXISTS "/etc/lsb-release")
execute_process(COMMAND find /etc/ -maxdepth 1 -type f -name *-release -exec cat {} \;
execute_process(COMMAND find -L /etc/ -maxdepth 1 -type f -name *-release -exec cat {} \;
OUTPUT_VARIABLE release_data RESULT_VARIABLE result)
set(name_regex "NAME=\"([^ \"\n]*).*\"\n")
set(version_regex "VERSION=\"([0-9]+(\\.[0-9]+)?)[^\n]*\"")
@@ -75,12 +93,7 @@ else()
set(os_name "${os_name} ${CMAKE_MATCH_1}")
if (NOT os_name)
if(InferenceEngine_FIND_REQUIRED)
message(FATAL_ERROR "Cannot detect OS via reading /etc/*-release:\n ${release_data}")
elseif(NOT InferenceEngine_FIND_QUIETLY)
message(WARNING "Cannot detect OS via reading /etc/*-release:\n ${release_data}")
endif()
return()
ext_message(FATAL_ERROR "Cannot detect OS via reading /etc/*-release:\n ${release_data}")
endif()
if (NOT InferenceEngine_FIND_QUIETLY)
@@ -91,17 +104,18 @@ else()
set(_OS_PATH "ubuntu_14.04/")
elseif (${os_name} STREQUAL "Ubuntu 16.04")
set(_OS_PATH "ubuntu_16.04/")
elseif (${os_name} STREQUAL "Ubuntu 18.04")
set(_OS_PATH "ubuntu_18.04/")
elseif (${os_name} STREQUAL "CentOS 7")
set(_OS_PATH "centos_7.4/")
elseif (${os_name} STREQUAL "poky 2.0")
set(_OS_PATH "ubuntu_16.04/")
elseif (${os_name} STREQUAL "poky 2.5")
set(_OS_PATH "ubuntu_18.04/")
elseif (${os_name} STREQUAL "Raspbian 9")
set(_OS_PATH "raspbian_9/")
else()
if(InferenceEngine_FIND_REQUIRED)
message(FATAL_ERROR "${os_name} is not supported. List of supported OS: Ubuntu 14.04, Ubuntu 16.04, CentOS 7")
elseif(NOT InferenceEngine_FIND_QUIETLY)
message(WARNING "${os_name} is not supported. List of supported OS: Ubuntu 14.04, Ubuntu 16.04, CentOS 7")
endif()
return()
ext_message(FATAL_ERROR "${os_name} is not supported. List of supported OS: Ubuntu 14.04, Ubuntu 16.04, Ubuntu 18.04, CentOS 7, poky 2.0, poky 2.5, Raspbian 9")
endif()
endif()
endif()
@@ -125,21 +139,31 @@ else()
find_path(IE_INCLUDE_DIR inference_engine.hpp "${_IE_ROOT_INCLUDE_DIR}")
find_path(IE_SRC_DIR extension "${_IE_ROOT_SRC_DIR}")
set(IE_LIB_DIR "${_IE_ROOT_LIBRARY}")
set(IE_LIB_REL_DIR "${IE_LIB_DIR}/Release")
set(IE_LIB_DBG_DIR "${IE_LIB_DIR}/Debug")
set(IE_EXTERNAL_DIR "${IE_ROOT_DIR}/external")
include(FindPackageHandleStandardArgs)
if (WIN32)
find_library(IE_RELEASE_LIBRARY inference_engine "${_IE_ROOT_LIBRARY}/Release")
find_library(IE_DEBUG_LIBRARY inference_engine "${_IE_ROOT_LIBRARY}/Debug")
find_package_handle_standard_args( IE
find_library(IE_RELEASE_LIBRARY inference_engine@IE_RELEASE_POSTFIX_WIN@ "${IE_LIB_REL_DIR}")
find_library(IE_DEBUG_LIBRARY inference_engine@IE_DEBUG_POSTFIX_WIN@ "${IE_LIB_DBG_DIR}")
find_package_handle_standard_args( InferenceEngine
FOUND_VAR INFERENCEENGINE_FOUND
REQUIRED_VARS IE_RELEASE_LIBRARY IE_DEBUG_LIBRARY IE_INCLUDE_DIR
FAIL_MESSAGE "Inference Engine cannot be found at ${_IE_ROOT_LIBRARY}. Please consult InferenceEgnineConfig.cmake module's help page.")
else()
find_library(IE_LIBRARY inference_engine "${_IE_ROOT_LIBRARY}")
find_package_handle_standard_args( IE
find_library(IE_LIBRARY inference_engine@IE_RELEASE_POSTFIX_LIN@ "${IE_LIB_DIR}")
find_package_handle_standard_args( InferenceEngine
FOUND_VAR INFERENCEENGINE_FOUND
REQUIRED_VARS IE_LIBRARY IE_INCLUDE_DIR
FAIL_MESSAGE "Inference Engine cannot be found at ${_IE_ROOT_LIBRARY}. Please consult InferenceEgnineConfig.cmake module's help page.")
endif()
if(IE_FOUND)
if(INFERENCEENGINE_FOUND)
# to keep this line for successful execution in CMake 2.8
set(InferenceEngine_FOUND TRUE)
add_library(IE::inference_engine SHARED IMPORTED GLOBAL)
if (WIN32)
@@ -162,10 +186,10 @@ else()
set(InferenceEngine_INCLUDE_DIRS ${IE_INCLUDE_DIR})
set(InferenceEngine_LIBRARIES IE::inference_engine)
set(InferenceEngine_FOUND TRUE)
include("${IE_ROOT_DIR}/share/ie_parallel.cmake")
add_subdirectory(${IE_SRC_DIR}/extension EXCLUDE_FROM_ALL ie_cpu_extension)
add_library(IE::ie_cpu_extension ALIAS ie_cpu_extension)
endif()
endif()

View File

@@ -1,42 +1,49 @@
# Copyright (C) 2018 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
# Defines the CMake commands/policies
cmake_minimum_required( VERSION 2.8.5 )
cmake_minimum_required (VERSION 3.3)
# Set the project name
project( INFERENCE_ENGINE_DRIVER )
project (ie_python_api)
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}/cmake)
option(COPY_IE_LIBS "Copy Inference Engine libs to package directory" ${WIN32})
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
set (ARCH armv7l)
elseif ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
set (ARCH intel64)
else()
set (ARCH ia32)
endif()
set (IE_DEFAULT_PATH computer_vision_sdk/deployment_tools/inference_engine/share)
find_package(InferenceEngine REQUIRED PATHS /opt/intel/${IE_DEFAULT_PATH} $ENV{HOME}/intel/${IE_DEFAULT_PATH})
# in case of independent python api build (out of Inference Engine root Cmake)
if (NOT(IE_MAIN_SOURCE_DIR))
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
message(STATUS "CMAKE_BUILD_TYPE not defined, 'Release' will be used")
set(CMAKE_BUILD_TYPE "Release")
endif()
message(STATUS "BUILD_CONFIGURATION: ${CMAKE_BUILD_TYPE}")
# Make the scripts available in the 'cmake' directory available for the
# 'include()' command, 'find_package()' command.
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}/cmake )
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin/${ARCH})
if(NOT(WIN32))
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_BUILD_TYPE})
endif()
endif()
# Include the CMake script UseCython.cmake. This defines add_cython_module().
# Instruction for use can be found at the top of cmake/UseCython.cmake.
include( UseCython )
include (UseCython)
# With CMake, a clean separation can be made between the source tree and the
# build tree. When all source is compiled, as with pure C/C++, the source is
# no-longer needed in the build tree. However, with pure *.py source, the
# source is processed directly. To handle this, we reproduce the availability
# of the source files in the build tree.
add_custom_target( ReplicatePythonSourceTree ALL ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_SOURCE_DIR}/cmake/ReplicatePythonSourceTree.cmake
${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
if (PYTHONINTERP_FOUND)
set (PYTHON_VERSION python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR})
else()
message(FATAL_ERROR "Python Interpretator was not found!")
endif()
add_custom_target( CopyIeLibs ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_SOURCE_DIR}/cmake/CopyIeLibs.cmake
${IE_ROOT_DIR}/bin/${_ARCH}/Release ${_IE_ROOT_LIBRARY}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ie_driver )
if(WIN32)
set (PYTHON_BRIDGE_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/$<CONFIG>/python_api/${PYTHON_VERSION}/openvino)
else()
set (PYTHON_BRIDGE_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/python_api/${PYTHON_VERSION}/openvino)
endif()
include_directories( IE::inference_engine )
find_package (InferenceEngine REQUIRED)
# Process the CMakeLists.txt in the 'src' and 'bin' directory.
add_subdirectory( inference_engine )
set (PYTHON_BRIDGE_SRC_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory (src/openvino/inference_engine)
add_subdirectory (src/openvino/inference_engine/dnn_builder)

View File

@@ -7,33 +7,53 @@
## Prerequisites
Install the following Python modules:
- opencv-python
- numpy
- cython
## Building on Windows
```shellscript
mkdir build
cd build
set PATH=C:\Program Files\Python36\Scripts;%PATH%
cmake -G "Visual Studio 14 2015 Win64" -DInferenceEngine_DIR=..\..\..\build ^
-DPYTHON_EXECUTABLE="C:\Program Files\Python36\python.exe" ^
-DPYTHON_INCLUDE_DIR="C:\Program Files\Python36\include" ^
-DPYTHON_LIBRARY="C:\Program Files\Python36\libs\python36.lib" ..
2. Install Inference Engine Python API dependencies:
```bash
pip3 install -r requirements.txt
```
Then build generated solution INFERENCE_ENGINE_DRIVER.sln using Microsoft\* Visual Studio.
## Building on Linux
Build Inference Engine Python API alongside with the Inference Engine build.
You need to run Inference Engine build with the following flags:
```shellscript
cd <IE_ROOT>
mkdir -p build
cd build
cmake -DInferenceEngine_DIR=../../../build -DPYTHON_EXECUTABLE=`which python3.6` \
cmake -DENABLE_PYTHON=ON -DPYTHON_EXECUTABLE=`which python3.6` \
-DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so \
-DPYTHON_INCLUDE_DIR=/usr/include/python3.6 ..
make -j16
```
Note: -DInferenceEngine_DIR parameter is needed to specify the folder with generated make files or Visual Studio solution used to build Inference Engine (see readme file in the inference-engine root folder).
## Building on Windows
You need to run Inference Engine build with the following flags:
```shellscript
cd <IE_ROOT>
mkdir build
cd build
set PATH=C:\Program Files\Python36\Scripts;%PATH%
cmake -G "Visual Studio 15 2017 Win64" -T "Intel C++ Compiler 18.0" ^
-DENABLE_PYTHON=ON ^
-DPYTHON_EXECUTABLE="C:\Program Files\Python36\python.exe" ^
-DPYTHON_INCLUDE_DIR="C:\Program Files\Python36\include" ^
-DPYTHON_LIBRARY="C:\Program Files\Python36\libs\python36.lib" ..
```
Then build generated solution INFERENCE_ENGINE_DRIVER.sln using Microsoft\* Visual Studio or run `cmake --build . --config Release` to build from the command line.
## Running sample
Before running the Python samples:
- add the folder with built `openvino` Python module (located at `inference-engine/bin/intel64/Release/lib/python_api/python3.6`) to the PYTHONPATH environment variable.
- add the folder with Inference Engine libraries to LD_LIBRARY_PATH variable on Linux (or PATH on Windows).
Example of command line to run classification sample:
```bash
python3 sample/classification_sample.py -m <path/to/xml> -i <path/to/input/image> -d CPU
```

View File

@@ -1,10 +0,0 @@
set(IE_WIN_LIBS ${CMAKE_ARGV3})
set(IE_LIBS ${CMAKE_ARGV4})
if (WIN32)
file( GLOB IE_LIBS "${IE_WIN_LIBS}/*.dll")
file( COPY ${IE_LIBS} DESTINATION ${CMAKE_CURRENT_SOURCE_DIR})
else()
file( GLOB IE_LIBS "${IE_LIBS}/*.so")
file( COPY ${IE_LIBS} DESTINATION ${CMAKE_CURRENT_SOURCE_DIR})
endif()

View File

@@ -1,10 +1,19 @@
# Find the Cython compiler.
# Copyright (c) 2016 Intel Corporation
#
# This code sets the following variables:
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# CYTHON_EXECUTABLE
# http://www.apache.org/licenses/LICENSE-2.0
#
# See also UseCython.cmake
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Following changes were done on top of original file:
# Add CYTHON_EXECUTABLE searching hints at lines 50 and 51
#=============================================================================
# Copyright 2011 Kitware, Inc.
@@ -21,7 +30,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
# Find the Cython compiler.
#
# This code sets the following variables:
#
# CYTHON_EXECUTABLE
#
# See also UseCython.cmake
# Use the Cython executable that lives next to the Python executable
# if it is a local installation.
find_package( PythonInterp )

View File

@@ -1,7 +0,0 @@
# Note: when executed in the build dir, then CMAKE_CURRENT_SOURCE_DIR is the
# build dir.
file( COPY setup.py inference_engine tests DESTINATION "${CMAKE_ARGV3}"
FILES_MATCHING PATTERN "*.py" )
file( COPY requirements.txt DESTINATION "${CMAKE_ARGV3}" )

View File

@@ -46,6 +46,23 @@
#
# See also FindCython.cmake
# Copyright (c) 2016 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Following changes were done on top of the original file:
# added PRIVATE linking mode for target_link_libraries call at lines 298 and 336
#=============================================================================
# Copyright 2011 Kitware, Inc.
#

View File

@@ -35,12 +35,15 @@ This class stores main information about the layer and allow to modify some laye
* `name` - Name of the layer
* `type`- Layer type
* `precision` - Layer base operating precision. Provides getter and setter interfaces.
* `layout` - Returns the layout of shape of the layer.
* `shape` - Return the list of the shape of the layer.
* `parents` - Returns a list, which contains names of layers preceding this layer.
* `children` - Returns a list, which contains names of layers following this layer.
* `affinity` - Layer affinity set by user or a default affinity set by the `IEPlugin.set_initial_affinity()` method.
The affinity attribute provides getter and setter interfaces, so the layer affinity can be modified directly.
For example:
For example:
```py
>>> net = IENetwork.from_ir(model=path_to_xml_file, weights=path_to_bin_file)
>>> net = IENetwork(model=path_to_xml_file, weights=path_to_bin_file)
>>> plugin = IEPlugin(device="HETERO:FPGA,CPU")
>>> plugin.set_config({"TARGET_FALLBACK": "HETERO:FPGA,CPU"})
>>> plugin.set_initial_affinity(net)
@@ -82,7 +85,12 @@ layers affinity and output layers.
### Class Constructor
There is no explicit class constructor. Use `from_ir` class method to read the Intermediate Representation (IR) and initialize a correct instance of the `IENetwork` class.
* `__init__(model: str, weights: str)`
* Parameters:
* model - Path to `.xml` file of the IR
* weights - Path to `.bin` file of the IR
### Class attributes:
@@ -91,7 +99,7 @@ There is no explicit class constructor. Use `from_ir` class method to read the I
For example, to get a shape of the input layer:
```py
>>> net = IENetwork.from_ir(model=path_to_xml_file, weights=path_to_bin_file)
>>> net = IENetwork(model=path_to_xml_file, weights=path_to_bin_file)
>>> net.inputs
{'data': <inference_engine.ie_api.InputInfo object at 0x7efe042dedd8>}
>>> net.inputs['data'].shape
@@ -102,7 +110,7 @@ There is no explicit class constructor. Use `from_ir` class method to read the I
For example, to get a shape of the output layer:
```py
>>> net = IENetwork.from_ir(model=path_to_xml_file, weights=path_to_bin_file)
>>> net = IENetwork(model=path_to_xml_file, weights=path_to_bin_file)
>>> net.inputs
{'prob': <inference_engine.ie_api.OutputInfo object at 0x7efe03ab95d0>}
>>> net.outputs['prob'].shape
@@ -113,7 +121,7 @@ There is no explicit class constructor. Use `from_ir` class method to read the I
network batch size. For example:
```py
>>> net = IENetwork.from_ir(model=path_to_xml_file, weights=path_to_bin_file)
>>> net = IENetwork(model=path_to_xml_file, weights=path_to_bin_file)
>>> net.batch_size
1
>>> net.batch_size = 4
@@ -124,20 +132,37 @@ There is no explicit class constructor. Use `from_ir` class method to read the I
```
* `layers` - Return dictionary that maps network layer names to <a name="ienetlayer-class"></a>`IENetLayer`
objects containing layer properties. For example, to list all network layers:
objects containing layer properties in topological order. For example, to list all network layers:
```py
>>> net = IENetwork.from_ir(model=path_to_xml_file, weights=path_to_bin_file)
>>> net = IENetwork(model=path_to_xml_file, weights=path_to_bin_file)
>>> net.layers
{'conv0': <inference_engine.ie_api.IENetLayer object at 0x7f3a4c102370>
...
}
```
* `stats` - Returns `LayersStatsMap` object containing dictionary that maps network layer names to calibration statistics
represented by <a name="layerstats-class"></a> `LayerStats` objects.
`LayersStatsMap` class inherited from built-in python `dict` and overrides default `update()`method to allow
to set or modify layers calibration statistics.
```py
>>> net = IENetwork(model=path_to_xml_file, weights=path_to_bin_file)
>>> net.stats.update({
"conv1_2d" : LayserStats(min=(-25, -1, 0), max=(63, 124, 70)),
"conv2_2d" : LayserStats(min=(-5, -1, 0, 1, -7, 2), max=(63, 124, 70, 174, 99, 106)),
})
```
For more details about low precision inference please refer to "Low-Precision 8-bit Integer Inference"
section in Inference Engine Developers Guide documentation.
### Class Methods
* `from_ir(model: str, weights: str)`
**Note:** The function is deprecated. Please use `IENetwork()` class constructor to create valid instance of `IENetwork`
* Description:
The class method serves to read the model from the `.xml` and `.bin` files of the IR.
@@ -154,7 +179,7 @@ There is no explicit class constructor. Use `from_ir` class method to read the I
* Usage example:
```py
>>> net = IENetwork.from_ir(model=path_to_xml_file, weights=path_to_bin_file)
>>> net = IENetwork(model=path_to_xml_file, weights=path_to_bin_file)
>>> net
<inference_engine.ie_api.IENetwork object at 0x7fd7dbce54b0>
```
@@ -179,7 +204,7 @@ There is no explicit class constructor. Use `from_ir` class method to read the I
* Usage example:
```py
>>> net = IENetwork.from_ir(model=path_to_xml_file, weights=path_to_bin_file)
>>> net = IENetwork(model=path_to_xml_file, weights=path_to_bin_file)
>>> net.add_outputs(["conv5_1/dwise', conv2_1/expand'])]
>>> net.outputs
['prob', 'conv5_1/dwise', 'conv2_1/expand']
@@ -213,12 +238,44 @@ outputs.
* Usage example:
```py
>>> net = IENetwork.from_ir(model=path_to_xml_file, weights=path_to_bin_file)
>>> net = IENetwork(model=path_to_xml_file, weights=path_to_bin_file)
>>> input_layer = next(iter(net.inputs))
>>> n, c, h, w = net.inputs[input_layer]
>>> net.reshape({input_layer: (n, c, h*2, w*2)}]
```
* `serialize(path_to_xml, path_to_bin)`:
* Description:
The method serializes the network and stores it in files.
* Parameters:
* `path_to_xml` - path to a file, where a serialized model will be stored.
* `path_to_bin` - path to a file, where serialized weights will be stored.
* Return value:
None
* Usage example:
```py
>>> net = IENetwork(model=path_to_model, weights=path_to_weights)
>>> net.serialize(path_to_xml, path_to_bin)
```
## <a name="layerstats-class"></a>LayerStats
Layer calibration statistic container
### Class Constructor
* `__init__(min: tuple = (), max: tuple = ())`
* Parameters:
* min - Tuple with per-channel minimum layer activation values
* max - Tuple with per-channel maximum layer activation values
## <a name="inputinfo-class"></a>InputInfo
This class contains the information about the network input layers
@@ -283,7 +340,7 @@ This class is the main plugin interface and serves to initialize and configure t
* Parameters:
* `network` - A valid IENetwork instance created by `IENetwork.from_ir()` method
* `network` - A valid `IENetwork` instance
* `num_requests` - A positive integer value of infer requests to be created. Number of infer requests may be limited
by device capabilities.
* `config` - A dictionary of plugin configuration keys and their values
@@ -295,7 +352,7 @@ This class is the main plugin interface and serves to initialize and configure t
* Usage example:
```py
>>> net = IENetwork.from_ir(model=path_to_xml_file, weights=path_to_bin_file)
>>> net = IENetwork(model=path_to_xml_file, weights=path_to_bin_file)
>>> plugin = IEPlugin(device="CPU")
>>> exec_net = plugin.load(network=net, num_requsts=2)
>>> exec_net
@@ -396,7 +453,7 @@ There is no explicit class constructor. To make a valid instance of `ExecutableN
* Usage example:
```py
>>> net = IENetwork.from_ir(model=path_to_xml_file, weights=path_to_bin_file)
>>> net = IENetwork(model=path_to_xml_file, weights=path_to_bin_file)
>>> plugin = IEPlugin(device="CPU")
>>> exec_net = plugin.load(network=net, num_requsts=3)
>>> exec_net.requests
@@ -424,7 +481,7 @@ There is no explicit class constructor. To make a valid instance of `ExecutableN
* Usage example:
```py
>>> net = IENetwork.from_ir(model=path_to_xml_file, weights=path_to_bin_file)
>>> net = IENetwork(model=path_to_xml_file, weights=path_to_bin_file)
>>> plugin = IEPlugin(device="CPU")
>>> exec_net = plugin.load(network=net, num_requsts=2)
>>> res = exec_net.infer({'data': img})
@@ -609,3 +666,22 @@ array([4.85416055e-01, 1.70385033e-01, 1.21873841e-01, 1.18894853e-01,
...
}
```
* `set_batch(size)`
* Description:
Sets new batch size for certain infer request when dynamic batching is enabled in executable network that created this request.
**Note:** Support of dynamic batch size depends on the target plugin.
* Parameters:
* `batch` - new batch size to be used by all the following inference calls for this request.
* Usage example:
```py
>>> plugin.set_config({"DYN_BATCH_ENABLED": "YES"})
>>> exec_net = plugin.load(network=net)
>>> exec_net.requests[0].set_batch(inputs_count)
```
Please refer to `dynamic_batch_demo.py` to see the full usage example.

View File

@@ -1,69 +0,0 @@
# Copyright (C) 2018 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
# If the pyx file is a C++ file, we should specify that here.
set(CMAKE_INCLUDE_CURRENT_DIR ON)
if (COPY_IE_LIBS)
if (UNIX)
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
SET(CMAKE_INSTALL_RPATH "$ORIGIN")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
endif (UNIX)
endif()
set_source_files_properties(
ie_api_impl_defs.pxd
ie_api_impl.hpp
ie_api_impl.cpp
ie_api.pyx
ie_api.pxd
PROPERTIES CYTHON_IS_CXX TRUE
)
cython_add_module(
ie_api
ie_api_impl_defs.pxd
ie_api_impl.hpp
ie_api_impl.cpp
ie_api.pyx
)
target_link_libraries(ie_api PRIVATE IE::inference_engine)
set_target_properties(ie_api PROPERTIES CXX_STANDARD 11 LINKER_LANGUAGE CXX)
#if (NOT UNIX AND ${PYTHON_VERSION_STRING} MATCHES "^1.4")
# set(python_subdir "python2.7")
#else()
# set(python_subdir "python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
#endif()
#
#
# Copy required build artifacts to structure which will be used in final package
#add_custom_command(TARGET ie_api POST_BUILD
#
# COMMAND ${CMAKE_COMMAND} -E make_directory
# ${CMAKE_SOURCE_DIR}/bin/${python_subdir}/openvino/inference_engine/
#
# COMMAND ${CMAKE_COMMAND} -E touch
# ${CMAKE_SOURCE_DIR}/bin/${python_subdir}/openvino/__init__.py)
#
#if (${WIN32})
#add_custom_command(TARGET ie_api POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy
# ${CMAKE_CURRENT_BINARY_DIR}/Release/ie_api.pyd ${CMAKE_SOURCE_DIR}/bin/${python_subdir}/openvino/inference_engine/
#
# COMMAND ${CMAKE_COMMAND} -E copy
# ${CMAKE_CURRENT_BINARY_DIR}/__init__.py ${CMAKE_SOURCE_DIR}/bin/${python_subdir}/openvino/inference_engine/)
#else()
#add_custom_command(TARGET ie_api POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E copy
# ${CMAKE_CURRENT_BINARY_DIR}/ie_api.so ${CMAKE_SOURCE_DIR}/bin/${python_subdir}/openvino/inference_engine/
#
# COMMAND ${CMAKE_COMMAND} -E copy
# ${CMAKE_CURRENT_BINARY_DIR}/__init__.py ${CMAKE_SOURCE_DIR}/bin/${python_subdir}/openvino/inference_engine/)
#endif()

View File

@@ -1,3 +0,0 @@
from .ie_api import *
__version__ = get_version()
__all__ = ['IENetwork', "IEPlugin", "IENetReader"]

View File

@@ -1,129 +0,0 @@
// Copyright (C) 2018 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
#ifndef INFERENCE_ENGINE_DRIVER_IE_API_IMPL_HPP
#define INFERENCE_ENGINE_DRIVER_IE_API_IMPL_HPP
#include <string>
#include <inference_engine.hpp>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <sstream>
#include "ie_extension.h"
namespace InferenceEnginePython {
struct IENetLayer {
InferenceEngine::CNNLayerPtr layer_ptr;
std::string name;
std::string type;
std::string precision;
std::string affinity;
std::map<std::string, std::string> params;
void setAffinity(const std::string & target_affinity);
void setParams(const std::map<std::string, std::string> & params_map);
std::map<std::string, InferenceEngine::Blob::Ptr> getWeights();
void setPrecision(std::string precision);
};
struct InputInfo{
InferenceEngine::InputInfo actual;
std::vector<size_t> dims;
std::string precision;
std::string layout;
void setPrecision(std::string precision);
void setLayout(std::string layout);
};
struct OutputInfo{
InferenceEngine::DataPtr actual;
std::vector<size_t> dims;
std::string precision;
std::string layout;
void setPrecision(std::string precision);
};
struct ProfileInfo {
std::string status;
std::string exec_type;
std::string layer_type;
long long real_time;
long long cpu_time;
unsigned execution_index;
};
struct IENetwork {
InferenceEngine::CNNNetwork actual;
std::string name;
std::size_t batch_size;
void setBatch(const size_t size);
void addOutputs(const std::vector<std::string> &out_layers, const std::string &precision);
std::map<std::string, InferenceEnginePython::IENetLayer> getLayers();
std::map<std::string, InferenceEnginePython::InputInfo> getInputs();
std::map<std::string, InferenceEnginePython::OutputInfo> getOutputs();
void reshape(const std::map<std::string, std::vector<size_t>> & input_shapes);
};
struct IENetReader {
static IENetwork read(std::string const &model, std::string const &weights);
std::vector<std::pair<std::string, std::string>> getLayers();
};
struct InferRequestWrap {
InferenceEngine::IInferRequest::Ptr request_ptr;
InferenceEngine::BlobMap inputs;
InferenceEngine::BlobMap outputs;
void infer();
void infer_async();
int wait(int64_t timeout);
InferenceEngine::Blob::Ptr &getInputBlob(const std::string &blob_name);
InferenceEngine::Blob::Ptr &getOutputBlob(const std::string &blob_name);
std::vector<std::string> getInputsList();
std::vector<std::string> getOutputsList();
std::map<std::string, InferenceEnginePython::ProfileInfo> getPerformanceCounts();
};
struct IEExecNetwork {
InferenceEngine::IExecutableNetwork::Ptr actual;
std::vector<InferRequestWrap> infer_requests;
IEExecNetwork(const std::string &name, size_t num_requests);
std::string name;
int next_req_index = 0;
bool async;
void infer();
};
struct IEPlugin {
std::unique_ptr<InferenceEnginePython::IEExecNetwork> load(InferenceEnginePython::IENetwork &net,
int num_requests,
const std::map<std::string,std::string> &config);
std::string device_name;
std::string version;
void setConfig(const std::map<std::string, std::string> &);
void addCpuExtension(const std::string &extension_path);
void setInitialAffinity(InferenceEnginePython::IENetwork &net);
IEPlugin(const std::string &device, const std::vector<std::string> &plugin_dirs);
IEPlugin() = default;
std::set<std::string> queryNetwork(InferenceEnginePython::IENetwork &net);
InferenceEngine::InferenceEnginePluginPtr actual;
};
template<class T>
T* get_buffer(InferenceEngine::Blob& blob) {
return blob.buffer().as<T *>();
}
template<class T, class... Args>
std::unique_ptr<T> make_unique(Args&&... args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
std::string get_version();
}; // InferenceEnginePython
#endif //INFERENCE_ENGINE_DRIVER_IE_API_IMPL_HPP

View File

@@ -0,0 +1,81 @@
# Benchmark Application Demo
This topic demonstrates how to run the Benchmark Application demo, which performs inference using convolutional networks.
## How It Works
> **NOTE:** To achieve benchmark results similar to the official published results, set CPU frequency to 2.9GHz and GPU frequency to 1GHz.
Upon the start-up, the application reads command-line parameters and loads a network and images to the Inference Engine plugin. The number of infer requests and execution approach depend on a mode defined with the `-api` command-line parameter.
### Synchronous API
For synchronous mode, the primary metric is latency. The application creates one infer request and executes the `Infer` method. A number of executions is defined by one of the two values:
* Number of iterations defined with the `-niter` command-line argument
* Predefined duration if `-niter` is skipped. Predefined duration value depends on device.
During the execution, the application collects two types of metrics:
* Latency for each infer request executed with `Infer` method
* Duration of all executions
Reported latency value is calculated as mean value of all collected latencies. Reported throughput value is a derivative from reported latency and additionally depends on batch size.
### Asynchronous API
For asynchronous mode, the primary metric is throughput in frames per second (FPS). The application creates a certain number of infer requests and executes the `StartAsync` method. A number of infer is specified with the `-nireq` command-line parameter. A number of executions is defined by one of the two values:
* Number of iterations defined with the `-niter` command-line argument
* Predefined duration if `-niter` is skipped. Predefined duration value depends on device.
The infer requests are executed asynchronously. `Wait` method is used to wait for previous execution to complete. The application measures all infer requests executions and reports the throughput metric based on batch size and total execution duration.
## Running
Running the application with the `-h` or `--help`' option yields the following usage message:
```python3 benchmark_app.py -h
benchmark_app [OPTION]
Options:
-h, --help Print a usage message
-i, --path_to_images "<path>" Required. Path to a folder with images or to image files.
-m, --path_to_model "<path>" Required. Path to an .xml file with a trained model.
-pp "<path>" Path to a plugin folder.
-api, --api_type "<sync/async>" Required. Enable using sync/async API.
-d, --target_device "<device>" Specify a target device to infer on: CPU, GPU, FPGA or MYRIAD. Use "-d HETERO:<comma separated devices list>" format to specify HETERO plugin. The application looks for a suitable plugin for the specified device.
-niter, --number_iterations "<integer>" Optional. Number of iterations. If not specified, the number of iterations is calculated depending on a device.
-nireq, --number_infer_requests "<integer>" Optional. Number of infer requests (default value is 2).
-l, --path_to_extension "<absolute_path>" Required for CPU custom layers. Absolute path to a shared library with the kernels implementations.
Or
-c, --path_to_cldnn_config "<absolute_path>" Required for GPU custom kernels. Absolute path to an .xml file with the kernels description.
-b, --batch_size "<integer>" Optional. Batch size value. If not specified, the batch size value is determined from IR.
-nthreads, --number_threads "<integer>" Number of threads to use for inference on the CPU (including Hetero cases).
-pin {YES,NO}, --infer_threads_pinning {YES,NO} Optional. Enable ("YES" is default value) or disable ("NO")CPU threads pinning for CPU-involved inference.
```
Running the application with the empty list of options yields the usage message given above and an error message.
To run the demo, you can use one-layer public models or one-layer pre-trained and optimized models delivered with the package that support images as input.
For example, to do inference on an image using a trained network with multiple outputs on CPU, run the following command:
```python3 benchmark_app.py -i <path_to_image>/inputImage.bmp -m <path_to_model>/multiple-output.xml -d CPU
```
> **NOTE**: Public models should be first converted to the Inference Engine format (\*.xml + \*.bin) using the [Model Optimizer tool](./docs/MO_DG/Deep_Learning_Model_Optimizer_DevGuide.md).
## Demo Output
Application output depends on a used API. For synchronous API, the application outputs latency and throughput:
```
[ INFO ] Start inference synchronously (10 s duration)
[BENCHMARK RESULT] Latency is 15.5520 msec
[BENCHMARK RESULT] Throughput is 1286.0082 FPS
```
For asynchronous API, the application outputs only throughput:
```
[ INFO ] Start inference asynchronously (10 s duration, 8 inference requests in parallel)
[BENCHMARK RESULT] Throughput is 1444.2591 FPS
```
## See Also
* [Using Inference Engine Samples](./docs/IE_DG/Samples_Overview.md)

View File

@@ -0,0 +1,204 @@
#!/usr/bin/env python
"""
Copyright (c) 2018 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from statistics import median
from openvino.inference_engine import IENetwork, IEPlugin
from utils.benchmark_utils import *
def main(args=None):
try:
if args is None:
args = parse_args()
validate_args(args)
# --------------------------------- 1. Load Plugin for inference engine ---------------------------------
logging.info("Loading plugin")
plugin = IEPlugin(args.target_device)
config = dict()
if CPU_DEVICE_NAME in args.target_device:
if args.path_to_extension:
plugin.add_cpu_extension(args.path_to_extension)
# limit threading for CPU portion of inference
if args.number_threads is not None:
config.update({'CPU_THREADS_NUM': str(args.number_threads)})
# pin threads for CPU portion of inference
config.update({'CPU_BIND_THREAD': args.infer_threads_pinning})
# for pure CPU execution, more throughput-oriented execution via streams
if args.api_type == 'async' and CPU_DEVICE_NAME in args.target_device:
config.update({'CPU_THROUGHPUT_STREAMS': str(args.number_infer_requests)})
elif GPU_DEVICE_NAME in args.target_device:
if args.path_to_cldnn_config:
config.update({'CONFIG_FILE': args.path_to_cldnn_config})
logger.info("GPU extensions is loaded {}".format(args.path_to_cldnn_config))
elif MYRIAD_DEVICE_NAME in args.target_device:
config.update({'LOG_LEVEL': 'LOG_INFO'})
config.update({'VPU_LOG_LEVEL': 'LOG_INFO'})
plugin.set_config(config)
logger.info("Device is {}".format(plugin.device))
logger.info("Plugin version is {}".format(plugin.version))
# --------------------- 2. Read IR Generated by ModelOptimizer (.xml and .bin files) ---------------------
logger.info("Loading network files")
xml_filename = os.path.abspath(args.path_to_model)
head, tail = os.path.splitext(xml_filename)
bin_filename = os.path.abspath(head + BIN_EXTENSION)
ie_network = IENetwork(xml_filename, bin_filename)
input_info = ie_network.inputs
if len(input_info) == 0:
raise AttributeError('No inputs info is provided')
elif len(input_info) != 1:
raise AttributeError("only one input layer network is supported")
# -------------------------------------- 3. Change network batch_size -------------------------------------
batch_size = ie_network.batch_size
key = list(input_info.keys()).pop()
precision = input_info[key].precision
if args.batch_size and args.batch_size != ie_network.batch_size:
# deepcopy input_info
shape = input_info[key].shape
# We support models having only one input layers
if input_info[key].layout != LAYOUT_TYPE:
raise Exception('Unsupported model for batch size changing in automatic mode')
shape[BATCH_SIZE_ELEM] = args.batch_size
ie_network.reshape({key: shape})
input_info = ie_network.inputs
batch_size = args.batch_size
logger_message = "Network batch size was changed to: " if args.batch_size is not None else "Network batch size: "
logger_message += " {}, precision: {}".format(batch_size, precision)
logger.info(logger_message)
# ------------------------------------- 4. Loading model to the plugin -------------------------------------
logger.info("Loading model to the plugin")
exe_network = plugin.load(ie_network, args.number_infer_requests)
# ------------------------------------ 5. Performance measurements stuff -----------------------------------
inputs = get_images(os.path.abspath(args.path_to_images), batch_size)
if batch_size < len(inputs):
logger.warn("Network batch size {} is less then images count {}"
", some input files will be ignored".format(batch_size, len(inputs)))
input_images = {key: fill_blob_with_image(inputs, input_info[key].shape)}
times = list()
duration = 0
if args.number_iterations is None:
duration = get_duration_in_secs(args.target_device)
if args.api_type == 'sync':
# warming up - out of scope
exe_network.infer(input_images)
if args.number_iterations is not None:
logger.info(
"Start inference synchronously ({}) sync inference executions".format(args.number_iterations))
for iteration in range(args.number_iterations):
sync_infer_request(exe_network, times, input_images)
else:
logger.info("Start inference synchronously ({} s duration)".format(duration))
start_time = datetime.now()
current_time = start_time
while (current_time - start_time).total_seconds() < duration:
current_time = sync_infer_request(exe_network, times, input_images)
times.sort()
latency = median(times)
fps = batch_size / latency
print("[BENCHMARK RESULT] Latency is {:.4f} msec".format(latency * 1e3))
print("[BENCHMARK RESULT] Throughput is {:.4f} FPS".format(fps))
else:
infer_requests = exe_network.requests
if args.number_iterations is not None:
logger.info("Start inference asynchronously ({}"
" async inference executions, {} "
" inference requests in parallel".format(args.number_iterations,
args.number_infer_requests))
else:
logger.info("Start inference asynchronously ({} s duration, "
"{} inference requests in parallel)".format(duration, args.number_infer_requests))
current_inference = 0
required_inference_requests_were_executed = False
previous_inference = 1 - args.number_infer_requests
step = 0
steps_count = args.number_infer_requests - 1
if args.number_iterations is not None:
steps_count += args.number_iterations
# warming up - out of scope
infer_requests[0].async_infer(input_images)
infer_requests[0].wait()
start_time = datetime.now()
while not required_inference_requests_were_executed or step < steps_count or \
args.number_iterations is None and (datetime.now() - start_time).total_seconds() < duration:
exe_network.start_async(current_inference, input_images)
if previous_inference >= 0:
status = infer_requests[previous_inference].wait()
if status is not 0:
raise Exception("Infer request not completed successfully")
current_inference += 1
if current_inference >= args.number_infer_requests:
current_inference = 0
required_inference_requests_were_executed = True
previous_inference += 1
if previous_inference >= args.number_infer_requests:
previous_inference = 0
step += 1
# wait the latest inference executions
for not_completed_index in range(args.number_infer_requests):
if infer_requests[not_completed_index].wait(0) != 0:
infer_requests[not_completed_index].wait()
total_duration = (datetime.now() - start_time).total_seconds()
fps = batch_size * step / total_duration
print("[BENCHMARK RESULT] Throughput is {:.4f} FPS".format(fps))
del exe_network
del plugin
except Exception as e:
logging.exception(e)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,122 @@
"""
Copyright (c) 2018 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import logging
import argparse
import os
import cv2
import numpy as np
import sys
from glob import glob
from random import choice
from datetime import datetime
from fnmatch import fnmatch
from . constants import *
logging.basicConfig(format="[ %(levelname)s ] %(message)s", level=logging.INFO, stream=sys.stdout)
logger = logging.getLogger('BenchmarkApp')
def validate_args(args):
if args.number_iterations is not None and args.number_iterations < 0:
raise Exception("Number of iterations should be positive (invalid -niter option value)")
if args.number_infer_requests < 0:
raise Exception("Number of inference requests should be positive (invalid -nireq option value)")
if not fnmatch(args.path_to_model, XML_EXTENSION_PATTERN):
raise Exception('Path {} is not xml file.')
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--path_to_images', type=str, required=True, help=HELP_MESSAGES['IMAGE_MESSAGE'])
parser.add_argument('-m', '--path_to_model', type=str, required=True, help=HELP_MESSAGES['MODEL_MESSAGE'])
parser.add_argument('-c', '--path_to_cldnn_config', type=str, required=False,
help=HELP_MESSAGES['CUSTOM_GPU_LIBRARY_MESSAGE'])
parser.add_argument('-l', '--path_to_extension', type=str, required=False, default=None,
help=HELP_MESSAGES['CUSTOM_GPU_LIBRARY_MESSAGE'])
parser.add_argument('-api', '--api_type', type=str, required=False, default='async', choices=['sync', 'async'],
help=HELP_MESSAGES['API_MESSAGE'])
parser.add_argument('-d', '--target_device', type=str, required=False, default="CPU",
help=HELP_MESSAGES['TARGET_DEVICE_MESSAGE'])
parser.add_argument('-niter', '--number_iterations', type=int, required=False, default=None,
help=HELP_MESSAGES['ITERATIONS_COUNT_MESSAGE'])
parser.add_argument('-nireq', '--number_infer_requests', type=int, required=False, default=2,
help=HELP_MESSAGES['INFER_REQUESTS_COUNT_MESSAGE'])
parser.add_argument('-nthreads', '--number_threads', type=int, required=False, default=None,
help=HELP_MESSAGES['INFER_NUM_THREADS_MESSAGE'])
parser.add_argument('-b', '--batch_size', type=int, required=False, default=None,
help=HELP_MESSAGES['BATCH_SIZE_MESSAGE'])
parser.add_argument('-pin', '--infer_threads_pinning', type=str, required=False, default='YES',
choices=['YES', 'NO'], help=HELP_MESSAGES['INFER_THREADS_PINNING_MESSAGE'])
return parser.parse_args()
def get_images(path_to_images, batch_size):
images = list()
if os.path.isfile(path_to_images):
while len(images) != batch_size:
images.append(path_to_images)
else:
path = os.path.join(path_to_images, '*')
files = glob(path, recursive=True)
for file in files:
file_extension = file.rsplit('.').pop().upper()
if file_extension in IMAGE_EXTENSIONS:
images.append(file)
if len(images) == 0:
raise Exception("No images found in {}".format(path_to_images))
if len(images) < batch_size:
while len(images) != batch_size:
images.append(choice(images))
return images
def get_duration_in_secs(target_device):
duration = 0
for device in DEVICE_DURATION_IN_SECS:
if device in target_device:
duration = max(duration, DEVICE_DURATION_IN_SECS[device])
if duration == 0:
duration = DEVICE_DURATION_IN_SECS[UNKNOWN_DEVICE_TYPE]
logger.warn("Default duration {} seconds for unknown device {} is used".format(duration, target_device))
return duration
def fill_blob_with_image(images_path, shape):
images = np.ndarray(shape)
for item in range(shape[0]):
image = cv2.imread(images_path[item])
new_im_size = tuple(shape[2:])
if image.shape[:-1] != new_im_size:
logger.warn("Image {} is resize from ({}) to ({})".format(images_path[item], image.shape[:-1], new_im_size))
image = cv2.resize(image, new_im_size)
image = image.transpose((2, 0, 1))
images[item] = image
return images
def sync_infer_request(exe_network, times, images):
iteration_start_time = datetime.now()
exe_network.infer(images)
current_time = datetime.now()
times.append((current_time - iteration_start_time).total_seconds())
return current_time

View File

@@ -0,0 +1,63 @@
"""
Copyright (c) 2018 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
HELP_MESSAGES = {
'IMAGE_MESSAGE': "Path to a folder with images or to image files.",
'MULTI_INPUT_MESSAGE': "Path to multi input file containing.",
'MODEL_MESSAGE': "Path to an .xml file with a trained model.",
'PLUGIN_PATH_MESSAGE': "Path to a plugin folder.",
'API_MESSAGE': "Enable using sync/async API. Default value is sync",
'TARGET_DEVICE_MESSAGE': "Specify a target device to infer on: CPU, GPU, FPGA or MYRIAD. "
"Use \"-d HETERO:<comma separated devices list>\" format to specify HETERO plugin. "
"The application looks for a suitable plugin for the specified device.",
'ITERATIONS_COUNT_MESSAGE': "Number of iterations. "
"If not specified, the number of iterations is calculated depending on a device.",
'INFER_REQUESTS_COUNT_MESSAGE': "Number of infer requests (default value is 2).",
'INFER_NUM_THREADS_MESSAGE': "Number of threads to use for inference on the CPU "
"(including Hetero cases).",
'CUSTOM_CPU_LIBRARY_MESSAGE': "Required for CPU custom layers. "
"Absolute path to a shared library with the kernels implementations.",
'CUSTOM_GPU_LIBRARY_MESSAGE': "Required for GPU custom kernels. Absolute path to an .xml file with the kernels description.",
'BATCH_SIZE_MESSAGE': "Optional. Batch size value. If not specified, the batch size value is determined from IR",
'INFER_THREADS_PINNING_MESSAGE': "Optional. Enable (\"YES\" is default value) or disable (\"NO\")"
"CPU threads pinning for CPU-involved inference."
}
DEVICE_DURATION_IN_SECS = {
"CPU": 60,
"GPU": 60,
"VPU": 60,
"MYRIAD": 60,
"FPGA": 120,
"HDDL": 60,
"UNKNOWN": 120
}
IMAGE_EXTENSIONS = ['JPEG', 'JPG', 'PNG', 'BMP']
MYRIAD_DEVICE_NAME = "MYRIAD"
CPU_DEVICE_NAME = "CPU"
GPU_DEVICE_NAME = "GPU"
UNKNOWN_DEVICE_TYPE = "UNKNOWN"
BATCH_SIZE_ELEM = 0
LAYOUT_TYPE = 'NCHW'
XML_EXTENSION = ".xml"
BIN_EXTENSION = ".bin"
XML_EXTENSION_PATTERN = '*' + XML_EXTENSION

View File

@@ -58,7 +58,7 @@ def main():
plugin.add_cpu_extension(args.cpu_extension)
# Read IR
log.info("Loading network files:\n\t{}\n\t{}".format(model_xml, model_bin))
net = IENetwork.from_ir(model=model_xml, weights=model_bin)
net = IENetwork(model=model_xml, weights=model_bin)
if plugin.device == "CPU":
supported_layers = plugin.get_supported_layers(net)
@@ -108,8 +108,8 @@ def main():
log.info("Performance counters:")
print("{:<70} {:<15} {:<15} {:<15} {:<10}".format('name', 'layer_type', 'exet_type', 'status', 'real_time, us'))
for layer, stats in perf_counts.items():
print ("{:<70} {:<15} {:<15} {:<15} {:<10}".format(layer, stats['layer_type'], stats['exec_type'],
stats['status'], stats['real_time']))
print("{:<70} {:<15} {:<15} {:<15} {:<10}".format(layer, stats['layer_type'], stats['exec_type'],
stats['status'], stats['real_time']))
# Processing output blob
log.info("Processing output blob")

View File

@@ -58,7 +58,7 @@ def main():
plugin.add_cpu_extension(args.cpu_extension)
# Read IR
log.info("Loading network files:\n\t{}\n\t{}".format(model_xml, model_bin))
net = IENetwork.from_ir(model=model_xml, weights=model_bin)
net = IENetwork(model=model_xml, weights=model_bin)
if plugin.device == "CPU":
supported_layers = plugin.get_supported_layers(net)
@@ -106,10 +106,10 @@ def main():
if args.perf_counts:
perf_counts = infer_request_handle.get_perf_counts()
log.info("Performance counters:")
print ("{:<70} {:<15} {:<15} {:<15} {:<10}".format('name', 'layer_type', 'exet_type', 'status', 'real_time, us'))
print("{:<70} {:<15} {:<15} {:<15} {:<10}".format('name', 'layer_type', 'exet_type', 'status', 'real_time, us'))
for layer, stats in perf_counts.items():
print ("{:<70} {:<15} {:<15} {:<15} {:<10}".format(layer, stats['layer_type'], stats['exec_type'],
stats['status'], stats['real_time']))
print("{:<70} {:<15} {:<15} {:<15} {:<10}".format(layer, stats['layer_type'], stats['exec_type'],
stats['status'], stats['real_time']))
# Processing output blob
log.info("Processing output blob")
res = infer_request_handle.outputs[out_blob]

View File

@@ -1,7 +1,7 @@
"""
BSD 3-clause "New" or "Revised" license
Copyright (C) 2018 Intel Coporation.
Copyright (C) 2018 Intel Corporation.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
@@ -38,7 +38,7 @@ import boto3
import timeit
import datetime
import json
from collections import OrderedDict
from collections import OrderedDict
from openvino.inference_engine import IENetwork, IEPlugin
@@ -82,6 +82,7 @@ PARAM_LABELMAP_FILE = os.environ.get("PARAM_LABELMAP_FILE")
PARAM_TOPIC_NAME = os.environ.get("PARAM_TOPIC_NAME", "intel/faas/classification")
PARAM_NUM_TOP_RESULTS = int(os.environ.get("PARAM_NUM_TOP_RESULTS", "10"))
def report(res_json, frame):
now = datetime.datetime.now()
date_prefix = str(now).replace(" ", "_")
@@ -89,17 +90,18 @@ def report(res_json, frame):
data = json.dumps(res_json)
client.publish(topic=PARAM_TOPIC_NAME, payload=data)
if enable_kinesis_output:
kinesis_client.put_record(StreamName=kinesis_stream_name, Data=json.dumps(res_json), PartitionKey=kinesis_partition_key)
kinesis_client.put_record(StreamName=kinesis_stream_name, Data=json.dumps(res_json),
PartitionKey=kinesis_partition_key)
if enable_s3_jpeg_output:
temp_image = os.path.join(PARAM_OUTPUT_DIRECTORY, "inference_result.jpeg")
cv2.imwrite(temp_image, frame)
with open(temp_image) as file:
image_contents = file.read()
s3_client.put_object(Body=image_contents, Bucket=s3_bucket_name, Key=date_prefix + ".jpeg")
s3_client.put_object(Body=image_contents, Bucket=s3_bucket_name, Key=date_prefix + ".jpeg")
if enable_local_jpeg_output:
cv2.imwrite(os.path.join(PARAM_OUTPUT_DIRECTORY, date_prefix + ".jpeg"), frame)
def greengrass_classification_sample_run():
client.publish(topic=PARAM_TOPIC_NAME, payload="OpenVINO: Initializing...")
model_bin = os.path.splitext(PARAM_MODEL_XML)[0] + ".bin"
@@ -109,7 +111,7 @@ def greengrass_classification_sample_run():
if "CPU" in PARAM_DEVICE:
plugin.add_cpu_extension(PARAM_CPU_EXTENSION_PATH)
# Read IR
net = IENetwork.from_ir(model=PARAM_MODEL_XML, weights=model_bin)
net = IENetwork(model=PARAM_MODEL_XML, weights=model_bin)
assert len(net.inputs.keys()) == 1, "Sample supports only single input topologies"
assert len(net.outputs) == 1, "Sample supports only single output topologies"
input_blob = next(iter(net.inputs))
@@ -126,9 +128,9 @@ def greengrass_classification_sample_run():
res_json = []
labeldata = None
if PARAM_LABELMAP_FILE is not None:
with open(PARAM_LABELMAP_FILE) as labelmap_file:
with open(PARAM_LABELMAP_FILE) as labelmap_file:
labeldata = json.load(labelmap_file)
while (cap.isOpened()):
ret, frame = cap.read()
if not ret:
@@ -148,17 +150,17 @@ def greengrass_classification_sample_run():
res_json = OrderedDict()
res_json["Candidates"] = OrderedDict()
frame_timestamp = datetime.datetime.now()
for i in top_ind:
classlabel = labeldata[str(i)] if labeldata else str(i)
res_json["Candidates"][classlabel] = round(res[out_blob][0, i], 2)
frame_count += 1
# Measure elapsed seconds since the last report
seconds_elapsed = timeit.default_timer() - start_time
if seconds_elapsed >= reporting_interval:
res_json["timestamp"] = frame_timestamp.isoformat()
res_json["frame_id"] = int(frameid)
res_json["frame_id"] = int(frameid)
res_json["inference_fps"] = frame_count / inf_seconds
start_time = timeit.default_timer()
report(res_json, frame)
@@ -169,8 +171,10 @@ def greengrass_classification_sample_run():
del exec_net
del plugin
greengrass_classification_sample_run()
def function_handler(event, context):
client.publish(topic=PARAM_TOPIC_NAME, payload='HANDLER_CALLED!')
return

View File

@@ -1,7 +1,7 @@
"""
BSD 3-clause "New" or "Revised" license
Copyright (C) 2018 Intel Coporation.
Copyright (C) 2018 Intel Corporation.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
@@ -38,7 +38,7 @@ import boto3
import timeit
import datetime
import json
from collections import OrderedDict
from collections import OrderedDict
from openvino.inference_engine import IENetwork, IEPlugin
@@ -81,6 +81,7 @@ PARAM_CPU_EXTENSION_PATH = os.environ.get("PARAM_CPU_EXTENSION_PATH")
PARAM_LABELMAP_FILE = os.environ.get("PARAM_LABELMAP_FILE")
PARAM_TOPIC_NAME = os.environ.get("PARAM_TOPIC_NAME", "intel/faas/ssd")
def report(res_json, frame):
now = datetime.datetime.now()
date_prefix = str(now).replace(" ", "_")
@@ -88,17 +89,18 @@ def report(res_json, frame):
data = json.dumps(res_json)
client.publish(topic=PARAM_TOPIC_NAME, payload=data)
if enable_kinesis_output:
kinesis_client.put_record(StreamName=kinesis_stream_name, Data=json.dumps(res_json), PartitionKey=kinesis_partition_key)
kinesis_client.put_record(StreamName=kinesis_stream_name, Data=json.dumps(res_json),
PartitionKey=kinesis_partition_key)
if enable_s3_jpeg_output:
temp_image = os.path.join(PARAM_OUTPUT_DIRECTORY, "inference_result.jpeg")
cv2.imwrite(temp_image, frame)
with open(temp_image) as file:
image_contents = file.read()
s3_client.put_object(Body=image_contents, Bucket=s3_bucket_name, Key=date_prefix + ".jpeg")
s3_client.put_object(Body=image_contents, Bucket=s3_bucket_name, Key=date_prefix + ".jpeg")
if enable_local_jpeg_output:
cv2.imwrite(os.path.join(PARAM_OUTPUT_DIRECTORY, date_prefix + ".jpeg"), frame)
def greengrass_object_detection_sample_ssd_run():
client.publish(topic=PARAM_TOPIC_NAME, payload="OpenVINO: Initializing...")
model_bin = os.path.splitext(PARAM_MODEL_XML)[0] + ".bin"
@@ -108,7 +110,7 @@ def greengrass_object_detection_sample_ssd_run():
if "CPU" in PARAM_DEVICE:
plugin.add_cpu_extension(PARAM_CPU_EXTENSION_PATH)
# Read IR
net = IENetwork.from_ir(model=PARAM_MODEL_XML, weights=model_bin)
net = IENetwork(model=PARAM_MODEL_XML, weights=model_bin)
assert len(net.inputs.keys()) == 1, "Sample supports only single input topologies"
assert len(net.outputs) == 1, "Sample supports only single output topologies"
input_blob = next(iter(net.inputs))
@@ -124,9 +126,9 @@ def greengrass_object_detection_sample_ssd_run():
frame_count = 0
labeldata = None
if PARAM_LABELMAP_FILE is not None:
with open(PARAM_LABELMAP_FILE) as labelmap_file:
with open(PARAM_LABELMAP_FILE) as labelmap_file:
labeldata = json.load(labelmap_file)
while (cap.isOpened()):
ret, frame = cap.read()
if not ret:
@@ -142,26 +144,27 @@ def greengrass_object_detection_sample_ssd_run():
res = exec_net.infer(inputs={input_blob: in_frame})
inf_seconds += timeit.default_timer() - inf_start_time
# Parse detection results of the current request
res_json = OrderedDict()
frame_timestamp = datetime.datetime.now()
res_json = OrderedDict()
frame_timestamp = datetime.datetime.now()
object_id = 0
for obj in res[out_blob][0][0]:
if obj[2] > 0.5:
xmin = int(obj[3] * initial_w)
ymin = int(obj[4] * initial_h)
xmax = int(obj[5] * initial_w)
ymax = int(obj[6] * initial_h)
cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), (255, 165, 20), 4)
obj_id = "Object" + str(object_id)
classlabel = labeldata[str(int(obj[1]))] if labeldata else ""
res_json[obj_id] = {"label": int(obj[1]), "class": classlabel, "confidence": round(obj[2], 2), "xmin": round(obj[3], 2), "ymin": round(obj[4], 2), "xmax": round(obj[5], 2), "ymax": round(obj[6], 2)}
object_id += 1
if obj[2] > 0.5:
xmin = int(obj[3] * initial_w)
ymin = int(obj[4] * initial_h)
xmax = int(obj[5] * initial_w)
ymax = int(obj[6] * initial_h)
cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), (255, 165, 20), 4)
obj_id = "Object" + str(object_id)
classlabel = labeldata[str(int(obj[1]))] if labeldata else ""
res_json[obj_id] = {"label": int(obj[1]), "class": classlabel, "confidence": round(obj[2], 2), "xmin": round(
obj[3], 2), "ymin": round(obj[4], 2), "xmax": round(obj[5], 2), "ymax": round(obj[6], 2)}
object_id += 1
frame_count += 1
# Measure elapsed seconds since the last report
seconds_elapsed = timeit.default_timer() - start_time
if seconds_elapsed >= reporting_interval:
res_json["timestamp"] = frame_timestamp.isoformat()
res_json["frame_id"] = int(frameid)
res_json["frame_id"] = int(frameid)
res_json["inference_fps"] = frame_count / inf_seconds
start_time = timeit.default_timer()
report(res_json, frame)
@@ -172,8 +175,10 @@ def greengrass_object_detection_sample_ssd_run():
del exec_net
del plugin
greengrass_object_detection_sample_ssd_run()
def function_handler(event, context):
client.publish(topic=PARAM_TOPIC_NAME, payload='HANDLER_CALLED!')
return

View File

@@ -0,0 +1,463 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook demonstrates the worklflow of a simple image classification task.\n",
"We will go through all the pipeline steps: downloading the model, generating the Intermediate Representation (IR) using the Model Optimizer, running inference in Python, and parsing and interpretating the output results.\n",
"\n",
"To demonstrate the scenario, we will use the pre-trained SquezeNet V1.1 Caffe\\* model. SqueezeNet is a pretty accurate and at the same time lightweight network. For more information about the model, please visit <a href=\"https://github.com/DeepScale/SqueezeNet/\">GitHub</a> page and refer to original <a href=\"https://arxiv.org/abs/1602.07360\">SqueezeNet paper</a>.\n",
"\n",
"Follow the steps to perform image classification with the SquezeNet V1.1 model:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**1. Download the model files:** "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%bash\n",
"echo \"Downloading deploy.protxt ...\"\n",
"if [ -f deploy.prototxt ]; then \n",
" echo \"deploy.protxt file already exists. Downloading skipped\"\n",
"else\n",
" wget https://raw.githubusercontent.com/DeepScale/SqueezeNet/a47b6f13d30985279789d08053d37013d67d131b/SqueezeNet_v1.1/deploy.prototxt -q\n",
" echo \"Finished!\"\n",
"fi"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%bash\n",
"! echo \"Downloading squeezenet_v1.1.caffemodel ...\"\n",
"if [ -f squeezenet_v1.1.caffemodel ]; then\n",
" echo \"squeezenet_v1.1.caffemodel file already exists. Download skipped\"\n",
"else\n",
" wget https://github.com/DeepScale/SqueezeNet/raw/a47b6f13d30985279789d08053d37013d67d131b/SqueezeNet_v1.1/squeezenet_v1.1.caffemodel -q\n",
" echo \"Finished!\"\n",
"fi"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Run the following command to see the model files:**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!ls -la"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* `deploy.prototxt` contains the network toplogy description in text format. \n",
"* `squeezenet_v1.1.caffemodel` contains weights for all network layers"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**2. Optimize and convert the model from intial Caffe representation to the IR representation, which is required for scoring the model using Inference Engine. To convert and optimize the model, use the Model Optimizer command line tool.**\n",
"\n",
"To locate Model Optimizer scripts, specify the path to the Model Optimizer root directory in the `MO_ROOT` variable in the cell bellow and then run it (If you use the installed OpenVINO&trade; package, you can find the Model Optimizer in `<INSTALLATION_ROOT_DIR>/deployment_tools/model_optimizer`)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%bash\n",
"MO_ROOT=/localdisk/repos/model-optimizer-tensorflow/\n",
"echo $MO_ROOT\n",
"python3 $MO_ROOT/mo.py --input_model squeezenet_v1.1.caffemodel --input_proto deploy.prototxt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**3. Now, you have the SqueezeNet model converted to the IR, and you can infer it.**\n",
"\n",
"a. First, import required modules:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from openvino.inference_engine import IENetwork, IEPlugin\n",
"import numpy as np\n",
"import cv2\n",
"import logging as log\n",
"from time import time\n",
"import sys\n",
"import glob\n",
"import os\n",
"from matplotlib import pyplot as plt\n",
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"b. Initialize required constants:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Configure logging format\n",
"log.basicConfig(format=\"[ %(levelname)s ] %(message)s\", level=log.INFO, stream=sys.stdout)\n",
"\n",
"# Path to IR model files\n",
"MODEL_XML = \"./squeezenet_v1.1.xml\"\n",
"MODEL_BIN = \"./squeezenet_v1.1.bin\"\n",
"\n",
"# Target device to run inference\n",
"TARGET_DEVICE = \"CPU\"\n",
"\n",
"# Folder with input images for the model\n",
"IMAGES_FOLDER = \"./images\"\n",
"\n",
"# File containing information about classes names \n",
"LABELS_FILE = \"./image_net_synset.txt\"\n",
"\n",
"# Number of top prediction results to parse\n",
"NTOP = 5\n",
"\n",
"# Required batch size - number of images which will be processed in parallel\n",
"BATCH = 4"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"c. Create a plugin instance for the specified target device \n",
"d. Read the IR files and create an `IENEtwork` instance"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plugin = IEPlugin(TARGET_DEVICE)\n",
"net = IENetwork(model=MODEL_XML, weights=MODEL_BIN)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"e. Set the network batch size to the constatns specified above. \n",
"\n",
"Batch size is an \"amount\" of input data that will be infered in parallel. In this cases it is a number of images, which will be classified in parallel. \n",
"\n",
"You can set the network batch size using one of the following options:\n",
"1. On the IR generation stage, run the Model Optimizer with `-b` command line option. For example, to generate the IR with batch size equal to 4, add `-b 4` to Model Optimizer command line options. By default, it takes the batch size from the original network in framework representation (usually, it is equal to 1, but in this case, the original Caffe model is provided with the batch size equal to 10). \n",
"2. Use Inference Engine after reading IR. We will use this option.\n",
"\n",
"To set the batch size with the Inference Engine:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"log.info(\"Current network batch size is {}, will be changed to {}\".format(net.batch_size, BATCH))\n",
"net.batch_size = BATCH"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"f. After setting batch size, you can get required information about network input layers.\n",
"To preprocess input images, you need to know input layer shape.\n",
"\n",
"`inputs` property of `IENetwork` returns the dicitonary with input layer names and `InputInfo` objects, which contain information about an input layer including its shape.\n",
"\n",
"SqueezeNet is a single-input toplogy, so to get the input layer name and its shape, you can get the first item from the `inputs` dictionary:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"input_layer = next(iter(net.inputs))\n",
"n,c,h,w = net.inputs[input_layer].shape\n",
"layout = net.inputs[input_layer].layout\n",
"log.info(\"Network input layer {} has shape {} and layout {}\".format(input_layer, (n,c,h,w), layout))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"So what do the shape and layout mean? \n",
"Layout will helps to interprete the shape dimsesnions meaning. \n",
"\n",
"`NCHW` input layer layout means:\n",
"* the fisrt dimension of an input data is a batch of **N** images processed in parallel \n",
"* the second dimension is a numnber of **C**hannels expected in the input images\n",
"* the third and the forth are a spatial dimensions - **H**eight and **W**idth of an input image\n",
"\n",
"Our shapes means that the network expects four 3-channel images running in parallel with size 227x227."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"g. Read and preprocess input images.\n",
"\n",
"For it, go to `IMAGES_FOLDER`, find all `.bmp` files, and take four images for inference:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"search_pattern = os.path.join(IMAGES_FOLDER, \"*.bmp\")\n",
"images = glob.glob(search_pattern)[:BATCH]\n",
"log.info(\"Input images:\\n {}\".format(\"\\n\".join(images)))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now you can read and preprocess the image files and create an array with input blob data.\n",
"\n",
"For preprocessing, you must do the following:\n",
"1. Resize the images to fit the HxW input dimenstions.\n",
"2. Transpose the HWC layout.\n",
"\n",
"Transposing is tricky and not really obvious.\n",
"As you alredy saw above, the network has the `NCHW` layout, so each input image should be in `CHW` format. But by deafult, OpenCV\\* reads images in the `HWC` format. That is why you have to swap the axes using the `numpy.transpose()` function:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"input_data = np.ndarray(shape=(n, c, h, w))\n",
"orig_images = [] # Will be used to show image in notebook\n",
"for i, img in enumerate(images):\n",
" image = cv2.imread(img)\n",
" orig_images.append(image)\n",
" if image.shape[:-1] != (h, w):\n",
" log.warning(\"Image {} is resized from {} to {}\".format(img, image.shape[:-1], (h, w)))\n",
" image = cv2.resize(image, (w, h))\n",
" image = image.transpose((2, 0, 1)) # Change data layout from HWC to CHW\n",
" input_data[i] = image"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"i. Infer the model model to classify input images:\n",
"\n",
"1. Load the `IENetwork` object to the plugin to create `ExectuableNEtwork` object. \n",
"2. Start inference using the `infer()` function specifying dictionary with input layer name and prepared data as an argument for the function. \n",
"3. Measure inference time in miliseconds and calculate throughput metric in frames-per-second (FPS)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"exec_net = plugin.load(net)\n",
"t0 = time()\n",
"res_map = exec_net.infer({input_layer: input_data})\n",
"inf_time = (time() - t0) * 1000 \n",
"fps = BATCH * inf_time \n",
"log.info(\"Inference time: {} ms.\".format(inf_time))\n",
"log.info(\"Throughput: {} fps.\".format(fps))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**4. After the inference, you need to parse and interpretate the inference results.**\n",
"\n",
"First, you need to see the shape of the network output layer. It can be done in similar way as for the inputs, but here you need to call `outputs` property of `IENetwork` object:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"output_layer = next(iter(net.outputs))\n",
"n,c,h,w = net.outputs[output_layer].shape\n",
"layout = net.outputs[output_layer].layout\n",
"log.info(\"Network output layer {} has shape {} and layout {}\".format(output_layer, (n,c,h,w), layout))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It is not a common case for classification netowrks to have output layer with *NCHW* layout. Usually, it is just *NC*. However, in this case, the last two dimensions are just a feature of the network and do not have much sense. Ignore them as you will remove them on the final parsing stage. \n",
"\n",
"What are the first and second dimensions of the output layer? \n",
"* The first dimension is a batch. We precoessed four images, and the prediction result for a particular image is stored in the first dimension of the output array. For example, prediction results for the third image is `res[2]` (since numeration starts from 0).\n",
"* The second dimension is an array with normalized probabilities (from 0 to 1) for each class. This network is trained using the <a href=\"http://image-net.org/index\">ImageNet</a> dataset with 1000 classes. Each `n`-th value in the output data for a certain image represent the probability of the image belonging to the `n`-th class. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To parse the output results:\n",
"\n",
"a. Read the `LABELS_FILE`, which maps the class ID to human-readable class names:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with open(LABELS_FILE, 'r') as f:\n",
" labels_map = [x.split(sep=' ', maxsplit=1)[-1].strip() for x in f]\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"b. Parse the output array with prediction results. The parsing algorith is the following:\n",
"0. Squeeze the last two \"extra\" dimensions of the output data.\n",
"1. Iterate over all batches.\n",
"2. Sort the probabilities vector descendingly to get `NTOP` classes with the highest probabilities (by default, the `numpy.argsort` sorts the data in the ascending order, but using the array slicing `[::-1]`, you can reverse the data order).\n",
"3. Map the `NTOP` probabilities to the corresponding labeles in `labeles_map`.\n",
"\n",
"For the vizualization, you also need to store top-1 class and probability."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"top1_res = [] # will be used for the visualization\n",
"res = np.squeeze(res_map[output_layer])\n",
"log.info(\"Top {} results: \".format(NTOP))\n",
"for i, probs in enumerate(res):\n",
" top_ind = np.argsort(probs)[-NTOP:][::-1]\n",
" print(\"Image {}\".format(images[i]))\n",
" top1_ind = top_ind[0]\n",
" top1_res.append((labels_map[top1_ind], probs[top1_ind]))\n",
" for id in top_ind:\n",
" print(\"label: {} probability: {:.2f}% \".format(labels_map[id], probs[id] * 100))\n",
" print(\"\\n\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The code above prints the results as plain text. \n",
"You can also use OpenCV\\* to visualize the results using the `orig_images` and `top1_res` variables, which you created during images reading and results parsing:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.clf()\n",
"for i, img in enumerate(orig_images):\n",
" label_str = \"{}\".format(top1_res[i][0].split(',')[0])\n",
" prob_str = \"{:.2f}%\".format(top1_res[i][1])\n",
" cv2.putText(img, label_str, (5, 15), cv2.FONT_HERSHEY_COMPLEX, 0.6, (220,100,10), 1)\n",
" cv2.putText(img, prob_str, (5, 35), cv2.FONT_HERSHEY_COMPLEX, 0.6, (220,100,10), 1)\n",
" plt.figure()\n",
" plt.axis(\"off\")\n",
" \n",
" # We have to convert colors, because matplotlib expects an image in RGB color format \n",
" # but by default, the OpenCV read images in BRG format\n",
" im_to_show = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n",
" plt.imshow(im_to_show)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.6.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@@ -1,154 +0,0 @@
#!/usr/bin/env python
"""
Copyright (c) 2018 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from __future__ import print_function
import sys
import os
from argparse import ArgumentParser
import cv2
import numpy as np
import logging as log
from time import time
from openvino.inference_engine import IENetwork, IEPlugin
classes_color_map = [
(150, 150, 150),
(58, 55, 169),
(211, 51, 17),
(157, 80, 44),
(23, 95, 189),
(210, 133, 34),
(76, 226, 202),
(101, 138, 127),
(223, 91, 182),
(80, 128, 113),
(235, 155, 55),
(44, 151, 243),
(159, 80, 170),
(239, 208, 44),
(128, 50, 51),
(82, 141, 193),
(9, 107, 10),
(223, 90, 142),
(50, 248, 83),
(178, 101, 130),
(71, 30, 204)
]
def build_argparser():
parser = ArgumentParser()
parser.add_argument("-m", "--model", help="Path to an .xml file with a trained model.", required=True, type=str)
parser.add_argument("-i", "--input", help="Path to a folder with images or path to an image files", required=True,
type=str, nargs="+")
parser.add_argument("-l", "--cpu_extension",
help="MKLDNN (CPU)-targeted custom layers.Absolute path to a shared library with the kernels "
"impl.", type=str, default=None)
parser.add_argument("-pp", "--plugin_dir", help="Path to a plugin folder", type=str, default=None)
parser.add_argument("-d", "--device",
help="Specify the target device to infer on; CPU, GPU, FPGA or MYRIAD is acceptable. Sample "
"will look for a suitable plugin for device specified (CPU by default)", default="CPU",
type=str)
parser.add_argument("-nt", "--number_top", help="Number of top results", default=10, type=int)
parser.add_argument("-ni", "--number_iter", help="Number of inference iterations", default=1, type=int)
parser.add_argument("-pc", "--perf_counts", help="Report performance counters", default=False, action="store_true")
return parser
def main():
log.basicConfig(format="[ %(levelname)s ] %(message)s", level=log.INFO, stream=sys.stdout)
args = build_argparser().parse_args()
model_xml = args.model
model_bin = os.path.splitext(model_xml)[0] + ".bin"
# Plugin initialization for specified device and load extensions library if specified
plugin = IEPlugin(device=args.device, plugin_dirs=args.plugin_dir)
if args.cpu_extension and 'CPU' in args.device:
plugin.add_cpu_extension(args.cpu_extension)
# Read IR
log.info("Loading network files:\n\t{}\n\t{}".format(model_xml, model_bin))
net = IENetwork.from_ir(model=model_xml, weights=model_bin)
if plugin.device == "CPU":
supported_layers = plugin.get_supported_layers(net)
not_supported_layers = [l for l in net.layers.keys() if l not in supported_layers]
if len(not_supported_layers) != 0:
log.error("Following layers are not supported by the plugin for specified device {}:\n {}".
format(plugin.device, ', '.join(not_supported_layers)))
log.error("Please try to specify cpu extensions library path in sample's command line parameters using -l "
"or --cpu_extension command line argument")
sys.exit(1)
assert len(net.inputs.keys()) == 1, "Sample supports only single input topologies"
assert len(net.outputs) == 1, "Sample supports only single output topologies"
log.info("Preparing input blobs")
input_blob = next(iter(net.inputs))
out_blob = next(iter(net.outputs))
net.batch_size = len(args.input)
# Read and pre-process input images
n, c, h, w = net.inputs[input_blob].shape
images = np.ndarray(shape=(n, c, h, w))
for i in range(n):
image = cv2.imread(args.input[i])
if image.shape[:-1] != (h, w):
log.warning("Image {} is resized from {} to {}".format(args.input[i], image.shape[:-1], (h, w)))
image = cv2.resize(image, (w, h))
image = image.transpose((2, 0, 1)) # Change data layout from HWC to CHW
images[i] = image
log.info("Batch size is {}".format(n))
# Loading model to the plugin
log.info("Loading model to the plugin")
exec_net = plugin.load(network=net)
del net
# Start sync inference
log.info("Starting inference ({} iterations)".format(args.number_iter))
infer_time = []
for i in range(args.number_iter):
t0 = time()
res = exec_net.infer(inputs={input_blob: images})
infer_time.append((time() - t0) * 1000)
log.info("Average running time of one iteration: {} ms".format(np.average(np.asarray(infer_time))))
if args.perf_counts:
perf_counts = exec_net.requests[0].get_perf_counts()
log.info("Performance counters:")
print("{:<70} {:<15} {:<15} {:<15} {:<10}".format('name', 'layer_type', 'exet_type', 'status', 'real_time, us'))
for layer, stats in perf_counts.items():
print ("{:<70} {:<15} {:<15} {:<15} {:<10}".format(layer, stats['layer_type'], stats['exec_type'],
stats['status'], stats['real_time']))
# Processing output blob
log.info("Processing output blob")
res = res[out_blob]
for batch, data in enumerate(res):
classes_map = np.zeros(shape=(h, w, c), dtype=np.int)
for i in range(h):
for j in range(w):
if len(data[:, i, j]) == 1:
pixel_class = int(data[:, i, j])
else:
pixel_class = np.argmax(data[:, i, j])
classes_map[i, j, :] = classes_color_map[min(pixel_class, 20)]
out_img = os.path.join(os.path.dirname(__file__), "out_{}.bmp".format(batch))
cv2.imwrite(out_img, classes_map)
log.info("Result image was saved to {}".format(out_img))
del exec_net
del plugin
if __name__ == '__main__':
sys.exit(main() or 0)

View File

@@ -51,7 +51,6 @@ def build_argparser():
type=float)
parser.add_argument("-pc", "--perf_counts", help="Report performance counters", default=False, action="store_true")
return parser
@@ -67,7 +66,7 @@ def main():
plugin.add_cpu_extension(args.cpu_extension)
# Read IR
log.info("Loading network files:\n\t{}\n\t{}".format(model_xml, model_bin))
net = IENetwork.from_ir(model=model_xml, weights=model_bin)
net = IENetwork(model=model_xml, weights=model_bin)
if plugin.device == "CPU":
supported_layers = plugin.get_supported_layers(net)
@@ -117,8 +116,8 @@ def main():
log.info("Performance counters:")
print("{:<70} {:<15} {:<15} {:<15} {:<10}".format('name', 'layer_type', 'exet_type', 'status', 'real_time, us'))
for layer, stats in perf_counts.items():
print ("{:<70} {:<15} {:<15} {:<15} {:<10}".format(layer, stats['layer_type'], stats['exec_type'],
stats['status'], stats['real_time']))
print("{:<70} {:<15} {:<15} {:<15} {:<10}".format(layer, stats['layer_type'], stats['exec_type'],
stats['status'], stats['real_time']))
# Processing output blob
log.info("Processing output blob")
res = res[out_blob]

View File

@@ -51,8 +51,8 @@ def parse_command_line_options(cls):
base_init_options(self)
def run(self):
global INFERENCE_ENGINE_DIR
global BUNDLE_INFERENCE_ENGINE
global INFERENCE_ENGINE_DIR
global BUNDLE_INFERENCE_ENGINE
if self.copy_ie_libs:
BUNDLE_INFERENCE_ENGINE = True
@@ -187,16 +187,14 @@ cmdclass = {
}
setup(
name="inference_engine",
version='0.1.1',
name="src",
version='1.0',
description='Python inference for Inference Engine',
packages=find_packages(exclude=['tests']),
package_data={PACKAGE_NAME: ['*.so', '*.dll', '*dylib*', '*.pyd']},
include_package_data=True,
ext_modules=extensions,
cmdclass=cmdclass,
author='', author_email='',
tests_require=['pytest'],
install_requires=list(requirements),
zip_safe=False,
)

View File

@@ -0,0 +1,36 @@
# If the pyx file is a C++ file, we should specify that here.
set (CMAKE_INCLUDE_CURRENT_DIR ON)
set (TARGET_NAME "ie_api")
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}/inference_engine)
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set_source_files_properties(
ie_api_impl_defs.pxd
ie_api_impl.hpp
ie_api_impl.cpp
ie_api.pyx
ie_api.pxd
PROPERTIES CYTHON_IS_CXX TRUE
)
cython_add_module (
${TARGET_NAME}
ie_api_impl_defs.pxd
ie_api_impl.hpp
ie_api_impl.cpp
ie_api.pyx
)
set_target_properties (${TARGET_NAME} PROPERTIES CXX_STANDARD 11 LINKER_LANGUAGE CXX)
target_link_libraries (${TARGET_NAME} PRIVATE ${InferenceEngine_LIBRARIES})
# perform copy
ADD_CUSTOM_COMMAND (TARGET ${TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${PYTHON_BRIDGE_SRC_ROOT}/src/openvino/inference_engine/__init__.py ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/__init__.py
COMMAND ${CMAKE_COMMAND} -E copy ${PYTHON_BRIDGE_SRC_ROOT}/requirements.txt ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/../../requirements.txt
COMMAND ${CMAKE_COMMAND} -E copy ${PYTHON_BRIDGE_SRC_ROOT}/src/openvino/__init__.py ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/../__init__.py
)

View File

@@ -0,0 +1,3 @@
from .ie_api import *
__version__ = get_version()
__all__ = ['IENetwork', "IEPlugin", "IENetReader"]

View File

@@ -0,0 +1,37 @@
# If the pyx file is a C++ file, we should specify that here.
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(TARGET_NAME "dnn_builder")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}/inference_engine/${TARGET_NAME})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set_source_files_properties(
dnn_builder_defs.pxd
dnn_builder_impl.hpp
dnn_builder_impl.cpp
dnn_builder.pyx
dnn_builder.pxd
PROPERTIES CYTHON_IS_CXX TRUE
)
cython_add_module(
${TARGET_NAME}
dnn_builder_impl_defs.pxd
dnn_builder_impl.hpp
dnn_builder_impl.cpp
dnn_builder.pyx
)
set_target_properties (${TARGET_NAME} PROPERTIES CXX_STANDARD 11 LINKER_LANGUAGE CXX)
add_dependencies (${TARGET_NAME} ie_api)
target_include_directories (${TARGET_NAME} PRIVATE ${PYTHON_BRIDGE_SRC_ROOT}/src/openvino/inference_engine )
target_link_libraries (${TARGET_NAME} PRIVATE ${InferenceEngine_LIBRARIES})
# perform copy
ADD_CUSTOM_COMMAND (TARGET ${TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${PYTHON_BRIDGE_SRC_ROOT}/src/openvino/inference_engine/${TARGET_NAME}/__init__.py ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
)

View File

@@ -0,0 +1,2 @@
from .dnn_builder import *
__all__ = ["NetworkBuilder", "LayerBuilder"]

View File

@@ -0,0 +1,26 @@
from .cimport dnn_builder_impl_defs as C
from libcpp.memory cimport shared_ptr
cdef class NetworkBuilder:
cdef C.NetworkBuilder impl
cdef class INetwork:
cdef C.INetwork impl
cdef class ILayer:
cdef C.ILayer impl
cdef class Port:
cdef C.Port impl
cdef class PortInfo:
cdef C.PortInfo impl
cdef class Connection:
cdef C.Connection impl
cdef class LayerBuilder:
cdef C.LayerBuilder impl
cdef class LayerConstantData(dict):
cdef shared_ptr[C.LayerBuilder] impl

View File

@@ -0,0 +1,423 @@
# #distutils: language=c++
#from cython.operator cimport dereference as deref
from libcpp.vector cimport vector
from libcpp.map cimport map
from libcpp.string cimport string
from ..ie_api cimport IENetwork, BlobBuffer
from .cimport dnn_builder_impl_defs as C
from .dnn_builder_impl_defs cimport Blob
import numpy as np
np_precision_map = {
"float32": "FP32",
"float16": "FP16",
"int32": "I32",
"int16": "I16",
"uint16": "U16",
"int8": "I8",
"uint8": "U8",
}
cdef class NetworkBuilder:
def __cinit__(self, name=None, IENetwork ie_net=None):
if name is not None and ie_net is not None:
raise AttributeError("Both name and ie_net arguments are defined")
elif name is not None:
self.impl = C.NetworkBuilder(name.encode())
elif ie_net is not None:
self.impl = C.NetworkBuilder().from_ie_network(ie_net.impl)
def build(self):
cdef INetwork i_net = INetwork()
i_net.impl = self.impl.build()
return i_net
def get_layer(self, id: int):
cdef LayerBuilder py_layer = LayerBuilder()
py_layer.impl = self.impl.getLayer(id)
return py_layer
@property
def layers(self):
cdef vector[C.LayerBuilder] c_layers = self.impl.getLayers()
cdef LayerBuilder py_layer
py_layers = {}
for l in c_layers:
py_layer = LayerBuilder()
py_layer.impl = l
py_layers[l.getName().decode()] = py_layer
return py_layers
def remove_layer(self, LayerBuilder layer):
self.impl.removeLayer(layer.impl)
def get_layer_connection(self, LayerBuilder layer):
cdef vector[C.Connection] c_connections = self.impl.getLayerConnections(layer.impl)
cdef Connection connection
connections = []
for con in c_connections:
connection = Connection()
connection.impl = con
connections.append(connection)
return connections
def disconnect(self, Connection connection):
self.impl.disconnect(connection.impl)
def connect(self, PortInfo input, PortInfo output):
self.impl.connect(input.impl, output.impl)
def add_layer(self, LayerBuilder layer, input_ports: list = None):
cdef vector[C.PortInfo] c_ports
cdef PortInfo c_port
if not input_ports:
return self.impl.addLayer(layer.impl)
else:
for p in input_ports:
c_port = PortInfo(p.layer_id, p.port_id)
c_ports.push_back(c_port.impl)
return self.impl.addAndConnectLayer(c_ports, layer.impl)
cdef class INetwork:
def __iter__(self):
cdef ILayer layer
layers = []
cdef vector[C.ILayer] c_layers = self.impl.layers
for l in c_layers:
layer = ILayer()
layer.impl = l
layers.append(layer)
return iter(layers)
@property
def layers(self):
cdef ILayer layer
layers = {}
cdef vector[C.ILayer] c_layers = self.impl.layers
for l in c_layers:
layer = ILayer()
layer.impl = l
layers[l.name.decode()] = layer
return layers
@property
def inputs(self):
cdef ILayer layer
layers = {}
cdef vector[C.ILayer] c_layers = self.impl.inputs
for l in c_layers:
layer = ILayer()
layer.impl = l
layers[l.name.decode()] = layer
return layers
@property
def outputs(self):
cdef ILayer layer
layers = {}
cdef vector[C.ILayer] c_layers = self.impl.outputs
for l in c_layers:
layer = ILayer()
layer.impl = l
layers[l.name.decode()] = layer
return layers
@property
def name(self):
return self.impl.name.decode()
@property
def size(self):
return self.impl.size
def get_layer_connection(self, layer: ILayer):
cdef Connection connection
connections = []
cdef vector[C.Connection] c_connections = self.impl.getLayerConnections(layer.id)
for con in c_connections:
connection = Connection()
connection.impl = con
connections.append(connection)
return connections
def to_ie_network(self):
cdef IENetwork net = IENetwork()
net.impl = self.impl.to_ie_network()
return net
cdef class ILayer:
@property
def name(self):
return self.impl.name.decode()
@property
def id(self):
return self.impl.id
@property
def type(self):
return self.impl.type.decode()
@property
def params(self):
return {k.decode(): v.decode() for k, v in self.impl.parameters}
@property
def input_ports(self):
cdef Port port
cdef vector[C.Port] c_ports = self.impl.in_ports
ports = []
for p in c_ports:
port = Port()
port.impl = p
ports.append(port)
return ports
@property
def output_ports(self):
cdef Port port
cdef vector[C.Port] c_ports = self.impl.out_ports
ports = []
for p in c_ports:
port = Port()
port.impl = p
ports.append(port)
return ports
@property
def constant_data(self):
cdef map[string, Blob.Ptr] c_constant_data
c_constant_data = self.impl.constant_data
constant_data = {}
cdef BlobBuffer weights_buffer
for weights in c_constant_data:
weights_buffer = BlobBuffer()
weights_buffer.reset(weights.second)
constant_data[weights.first.decode()] = weights_buffer.to_numpy()
return constant_data
cdef class Port:
def __cinit__(self, shape: list=[]):
cdef vector[size_t] c_shape
for d in shape:
c_shape.push_back(d)
self.impl = C.Port(c_shape)
@property
def shape(self):
return self.impl.shape
cdef class PortInfo:
def __cinit__(self, layer_id: int = -1, port_id: int = -1):
if layer_id != -1 and port_id != -1:
self.impl = C.PortInfo(layer_id, port_id)
else:
self.impl = C.PortInfo()
@property
def layer_id(self):
return self.impl.layer_id
@property
def port_id(self):
return self.impl.port_id
def __eq__(self, other):
return self.layer_id == other.layer_id and self.port_id == other.port_id
def __ne__(self, other):
return self.layer_id != other.layer_id and self.port_id != other.port_id
cdef class Connection:
def __cinit__(self, PortInfo input = None, PortInfo output = None):
if input and output:
self.impl = C.Connection(input.impl, output.impl)
else:
self.impl = C.Connection()
@property
def _from(self):
cdef PortInfo port_info = PortInfo()
port_info.impl = self.impl._from
return port_info
@property
def to(self):
cdef PortInfo port_info = PortInfo()
port_info.impl = self.impl.to
return port_info
def __eq__(self, other):
return self._from == other._from and self.to == other.to
def __ne__(self, other):
return self._from != other._from and self.to != other.to
def check_constant_data(data):
for k, v in data.items():
if not all([isinstance(x, type(v[0])) for x in v]):
raise TypeError("Elements of list for key {} have different data types! "
"Please specify list of 'int' or 'float' values.".format(k))
if isinstance(v, list):
if isinstance(v[0], float):
dtype = np.float32
elif isinstance(v[0], int):
dtype = np.int32
else:
raise TypeError("Unsupported precision of the data for key {}! Given {} but 'float or 'int' precision expected".
format(k, str(v.dtype)))
data[k] = np.asanyarray(v, dtype=dtype)
elif isinstance(v, np.ndarray):
pass
else:
raise TypeError("Unsupported data type for key '{}'. {} given but 'list' or 'numpy.ndarray' expected".
format(k, type(v)))
return data
# TODO: Fix LAyerBuilder object copying - pass by reference
# cdef class LayerConstantData(dict):
# def update(self, other=None, **kwargs):
# if other:
# other = check_constant_data(other)
# cdef vector[size_t] dims
# cdef Blob.Ptr blob_ptr
# cdef BlobBuffer buffer
# for k, v in other.items():
# if k in self.keys() and (v.shape == self[k].shape and v.dtype == self[k].dtype):
# print("Reuse blob for {}\n".format(k))
# self[k][:] = v
# else:
# for dim in v.shape:
# dims.push_back(dim)
# ie_precision = np_precision_map.get(str(v.dtype), None)
# if not ie_precision:
# raise BufferError("Unsupported precision of the data for key {}! Given {} but one of the {} precisions expected".
# format(k, str(v.dtype), ", ".join(np_precision_map.keys())))
# blob_ptr = deref(self.impl).allocateBlob(dims, ie_precision.encode())
# buffer = BlobBuffer()
# buffer.reset(blob_ptr)
# np_buffer = buffer.to_numpy()
# np_buffer[:] = v
# deref(self.impl).addConstantData(k.encode(), blob_ptr)
cdef class LayerBuilder:
def __cinit__(self, type: str=None, name: str=None):
if name and type:
self.impl = C.LayerBuilder(name.encode(), type.encode())
else:
self.impl = C.LayerBuilder()
@property
def id(self):
return self.impl.id
@property
def name(self):
return self.impl.getName().decode()
@name.setter
def name(self, name: str):
self.impl.setName(name.encode())
@property
def type(self):
return self.impl.getType().decode()
@type.setter
def type(self, type: str):
self.impl.setType(type.encode())
@property
def input_ports(self):
cdef Port port
cdef vector[C.Port] c_ports = self.impl.getInputPorts()
py_ports = []
for p in c_ports:
port = Port()
port.impl = p
py_ports.append(port)
return py_ports
@input_ports.setter
def input_ports(self, ports: list):
cdef vector[C.Port] c_ports
cdef Port c_port
for p in ports:
c_port = Port(p.shape)
c_ports.push_back(c_port.impl)
self.impl.setInputPorts(c_ports)
@property
def output_ports(self):
cdef Port port
cdef vector[C.Port] c_ports = self.impl.getOutputPorts()
py_ports = []
for p in c_ports:
port = Port()
port.impl = p
py_ports.append(port)
return py_ports
@output_ports.setter
def output_ports(self, ports: list):
cdef vector[C.Port] c_ports
cdef Port c_port
for p in ports:
c_port = Port(p.shape)
c_ports.push_back(c_port.impl)
self.impl.setOutputPorts(c_ports)
@property
def params(self):
return {k.decode(): v.decode() for k, v in self.impl.getParameters()}
@params.setter
def params(self, params_map: dict):
cdef map[string, string] c_params_map
for k, v in params_map.items():
c_params_map[k.encode()] = str(v).encode()
self.impl.setParameters(c_params_map)
def build(self):
cdef ILayer layer = ILayer()
layer.impl = self.impl.build()
return layer
@property
def constant_data(self):
cdef map[string, Blob.Ptr] c_constant_data
c_constant_data = self.impl.getConstantData()
constant_data = {}
# TODO: Fix LAyerBuilder object copying - pass by reference
# constant_data = LayerConstantData()
# constant_data.impl = make_shared[C.LayerBuilder](self.impl)
cdef BlobBuffer weights_buffer
for weights in c_constant_data:
weights_buffer = BlobBuffer()
weights_buffer.reset(weights.second)
constant_data[weights.first.decode()] = weights_buffer.to_numpy()
return constant_data
@constant_data.setter
def constant_data(self, data: dict):
cdef vector[size_t] dims
cdef map[string, Blob.Ptr] c_constant_data
cdef Blob.Ptr blob_ptr
cdef BlobBuffer buffer
data = check_constant_data(data)
for k, v in data.items():
for dim in v.shape:
dims.push_back(dim)
ie_precision = np_precision_map.get(str(v.dtype), None)
if not ie_precision:
raise BufferError("Unsupported precision of the data for key {}! Given {} but one of the {} precisions expected".
format(k, str(v.dtype), ", ".join(np_precision_map.keys())))
blob_ptr = self.impl.allocateBlob(dims, ie_precision.encode())
buffer = BlobBuffer()
buffer.reset(blob_ptr)
np_buffer = buffer.to_numpy()
np_buffer[:] = v
c_constant_data[k.encode()] = blob_ptr
self.impl.setConstantData(c_constant_data)
# TODO: Implement get\setGraph when will be supported

View File

@@ -0,0 +1,330 @@
// Copyright (c) 2018 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "dnn_builder_impl.hpp"
// using namespace InferenceEnginePython;
// using namespace std;
std::map<std::string, InferenceEngine::Precision> precision_map = {{"FP32", InferenceEngine::Precision::FP32},
{"FP16", InferenceEngine::Precision::FP16},
{"Q78", InferenceEngine::Precision::Q78},
{"I32", InferenceEngine::Precision::I32},
{"I16", InferenceEngine::Precision::I16},
{"I8", InferenceEngine::Precision::I8},
{"U16", InferenceEngine::Precision::U16},
{"U8", InferenceEngine::Precision::U8}};
InferenceEnginePython::ILayer buildILayer(InferenceEngine::ILayer::CPtr it) {
std::vector<InferenceEnginePython::Port> in_ports;
std::vector<InferenceEnginePython::Port> out_ports;
for (const auto &port : it->getInputPorts()) {
in_ports.push_back(InferenceEnginePython::Port(port.shape()));
}
for (const auto &port : it->getOutputPorts()) {
out_ports.push_back(InferenceEnginePython::Port(port.shape()));
}
std::map<std::string, std::string> params_map;
for (const auto &params : it->getParameters()->getParameters()) {
params_map.emplace(params.first, params.second);
}
std::map<std::string, InferenceEngine::Blob::Ptr> data_map;
for (const auto &data : it->getParameters()->getConstantData()) {
data_map.emplace(data.first, std::const_pointer_cast<InferenceEngine::Blob>(data.second));
}
return {it,
it->getName(),
it->getId(),
it->getType(),
params_map,
data_map,
in_ports,
out_ports,
};
}
// NetworkBuilder
InferenceEnginePython::NetworkBuilder::NetworkBuilder(const std::string &name) {
// TODO( ): std::move or instance in heap? Please check in other places.
InferenceEngine::Builder::Network network(name);
network_ptr = std::make_shared<InferenceEngine::Builder::Network>(network);
}
InferenceEnginePython::NetworkBuilder InferenceEnginePython::NetworkBuilder::from_ie_network(
const InferenceEnginePython::IENetwork &icnn_net) {
InferenceEngine::Builder::Network network((InferenceEngine::ICNNNetwork &) icnn_net.actual);
NetworkBuilder net_builder = NetworkBuilder();
net_builder.network_ptr = std::make_shared<InferenceEngine::Builder::Network>(network);
return net_builder;
}
InferenceEnginePython::INetwork InferenceEnginePython::NetworkBuilder::build() {
InferenceEngine::INetwork::Ptr i_net = network_ptr->build();
std::vector<ILayer> layers;
for (const auto &it : *i_net) {
layers.push_back(buildILayer(it));
}
std::vector<ILayer> inputs;
for (const auto &it : i_net->getInputs()) {
inputs.push_back(buildILayer(it));
}
std::vector<ILayer> outputs;
for (const auto &it : i_net->getInputs()) {
outputs.push_back(buildILayer(it));
}
return {i_net, // INetwork ptr
i_net->getName(), // name
i_net->size(), // Number of layers
layers,
inputs,
outputs
};
}
std::vector<InferenceEnginePython::LayerBuilder> InferenceEnginePython::NetworkBuilder::getLayers() {
std::vector<LayerBuilder> layers;
for (const auto &it : network_ptr->getLayers()) {
LayerBuilder layer;
layer.actual = it;
layer.id = it.getId();
layers.push_back(layer);
}
return layers;
}
InferenceEnginePython::LayerBuilder InferenceEnginePython::NetworkBuilder::getLayer(size_t layer_id) {
LayerBuilder layer;
InferenceEngine::Builder::Layer ie_layer = network_ptr->getLayer(layer_id);
layer.actual = ie_layer;
layer.id = ie_layer.getId();
return layer;
}
void InferenceEnginePython::NetworkBuilder::removeLayer(const LayerBuilder &layer) {
network_ptr->removeLayer(layer.id);
}
const std::vector<InferenceEnginePython::Connection> InferenceEnginePython::NetworkBuilder::getLayerConnections(
const LayerBuilder &layer) {
std::vector<InferenceEngine::Connection> ie_connections = network_ptr->getLayerConnections(layer.id);
std::vector<Connection> connections;
for (auto const &it : ie_connections) {
PortInfo input(it.from().layerId(), it.from().portId());
PortInfo output(it.to().layerId(), it.to().portId());
connections.push_back(Connection(input, output));
}
return connections;
}
void InferenceEnginePython::NetworkBuilder::disconnect(const Connection &connection) {
network_ptr->disconnect(connection.actual);
}
void InferenceEnginePython::NetworkBuilder::connect(const PortInfo &input, const PortInfo &output) {
network_ptr->connect(input.actual, output.actual);
}
size_t InferenceEnginePython::NetworkBuilder::addLayer(const LayerBuilder &layer) {
return network_ptr->addLayer(layer.actual);
}
size_t InferenceEnginePython::NetworkBuilder::addAndConnectLayer(const std::vector<PortInfo> &input,
const LayerBuilder &layer) {
std::vector<InferenceEngine::PortInfo> ie_ports;
for (const auto &it : input) {
ie_ports.push_back(it.actual);
}
return network_ptr->addLayer(ie_ports, layer.actual);
}
// NetworkBuilder end
// NetworkBuilder end
// Port
InferenceEnginePython::Port::Port(const std::vector<size_t> &shapes) {
actual = InferenceEngine::Port(shapes);
shape = actual.shape();
}
InferenceEnginePython::PortInfo::PortInfo(size_t layer_id, size_t port_id) : PortInfo() {
this->actual = InferenceEngine::PortInfo(layer_id, port_id);
this->layer_id = layer_id;
this->port_id = port_id;
}
// Port end
// INetwork
std::vector<InferenceEnginePython::Connection> InferenceEnginePython::INetwork::getLayerConnections(size_t layer_id) {
std::vector<Connection> connections;
for (const auto &it : actual->getLayerConnections(layer_id)) {
PortInfo input = PortInfo(it.from().layerId(), it.from().portId());
PortInfo output = PortInfo(it.to().layerId(), it.to().portId());
connections.push_back(Connection(input, output));
}
return connections;
}
InferenceEnginePython::IENetwork InferenceEnginePython::INetwork::to_ie_network() {
std::shared_ptr<InferenceEngine::ICNNNetwork> icnn_net = InferenceEngine::Builder::convertToICNNNetwork(actual);
InferenceEngine::CNNNetwork cnn_net(icnn_net);
IENetwork ie_net = IENetwork();
ie_net.actual = cnn_net;
ie_net.name = name;
ie_net.batch_size = cnn_net.getBatchSize();
return ie_net;
}
// INetwork end
// Connection
InferenceEnginePython::Connection::Connection(PortInfo input, PortInfo output) : Connection() {
this->actual = InferenceEngine::Connection(InferenceEngine::PortInfo(input.layer_id, input.port_id),
InferenceEngine::PortInfo(output.layer_id, output.port_id));
this->_from = PortInfo(actual.from().layerId(), actual.from().portId());
this->to = PortInfo(actual.to().layerId(), actual.to().portId());
}
// Connection end
// LayerBuilder
InferenceEnginePython::LayerBuilder::LayerBuilder(const std::string &type, const std::string &name) : LayerBuilder() {
InferenceEngine::Builder::Layer layer(type, name);
this->actual = layer;
this->id = layer.getId();
}
const std::string &InferenceEnginePython::LayerBuilder::getName() {
return actual.getName();
}
const std::string &InferenceEnginePython::LayerBuilder::getType() {
return actual.getType();
}
std::vector<InferenceEnginePython::Port> InferenceEnginePython::LayerBuilder::getInputPorts() {
std::vector<Port> ports;
for (const auto &it : actual.getInputPorts()) {
ports.push_back(Port(it.shape()));
}
return ports;
}
std::vector<InferenceEnginePython::Port> InferenceEnginePython::LayerBuilder::getOutputPorts() {
std::vector<Port> ports;
for (const auto &it : actual.getOutputPorts()) {
ports.push_back(Port(it.shape()));
}
return ports;
}
std::map<std::string, std::string> InferenceEnginePython::LayerBuilder::getParameters() {
std::map<std::string, std::string> params_map;
for (const auto &it : actual.getParameters()) {
params_map.emplace(it.first, it.second);
}
return params_map;
}
void InferenceEnginePython::LayerBuilder::setParameters(std::map<std::string, std::string> params_map) {
std::map<std::string, InferenceEngine::Parameter> ie_params_map;
for (const auto &it : params_map) {
InferenceEngine::Parameter ie_param((it.second));
ie_params_map.emplace(it.first, ie_param);
}
actual = actual.setParameters(ie_params_map);
}
void InferenceEnginePython::LayerBuilder::setName(const std::string &name) {
actual = actual.setName(name);
}
void InferenceEnginePython::LayerBuilder::setType(const std::string &type) {
actual = actual.setType(type);
}
void InferenceEnginePython::LayerBuilder::setInputPorts(const std::vector<Port> ports) {
std::vector<InferenceEngine::Port> ie_ports;
for (const auto &it : ports) {
ie_ports.push_back(it.actual);
}
actual = actual.setInputPorts(ie_ports);
}
void InferenceEnginePython::LayerBuilder::setOutputPorts(const std::vector<Port> ports) {
std::vector<InferenceEngine::Port> ie_ports;
for (const auto &it : ports) {
ie_ports.push_back(it.actual);
}
actual = actual.setOutputPorts(ie_ports);
}
InferenceEnginePython::ILayer InferenceEnginePython::LayerBuilder::build() {
return buildILayer(actual.build());
}
std::map<std::string, InferenceEngine::Blob::Ptr> InferenceEnginePython::LayerBuilder::getConstantData() {
std::map<std::string, InferenceEngine::Blob::Ptr> data_map;
for (const auto &it : actual.getConstantData()) {
data_map.emplace(it.first, std::const_pointer_cast<InferenceEngine::Blob>(it.second));
}
return data_map;
}
InferenceEngine::Blob::Ptr InferenceEnginePython::LayerBuilder::allocateBlob(std::vector<size_t> dims,
const std::string &precision) {
InferenceEngine::Layout ie_layout;
ie_layout = InferenceEngine::TensorDesc::getLayoutByDims(dims);
InferenceEngine::Precision ie_precision = precision_map.at(precision);
const InferenceEngine::TensorDesc &tdesc = InferenceEngine::TensorDesc(ie_precision, dims, ie_layout);
InferenceEngine::Blob::Ptr blob;
switch (ie_precision) {
case InferenceEngine::Precision::FP32:
blob = InferenceEngine::make_shared_blob<float>(tdesc);
break;
case InferenceEngine::Precision::FP16:
blob = InferenceEngine::make_shared_blob<int>(tdesc);
break;
case InferenceEngine::Precision::I16:
blob = InferenceEngine::make_shared_blob<int>(tdesc);
break;
case InferenceEngine::Precision::U16:
blob = InferenceEngine::make_shared_blob<int>(tdesc);
break;
case InferenceEngine::Precision::U8:
blob = InferenceEngine::make_shared_blob<unsigned char>(tdesc);
break;
case InferenceEngine::Precision::I8:
blob = InferenceEngine::make_shared_blob<signed char>(tdesc);
break;
case InferenceEngine::Precision::I32:
blob = InferenceEngine::make_shared_blob<signed int>(tdesc);
break;
default:
blob = InferenceEngine::make_shared_blob<float>(tdesc);
break;
}
blob->allocate();
return blob;
}
void InferenceEnginePython::LayerBuilder::setConstantData(const std::map<std::string,
InferenceEngine::Blob::Ptr> &const_data) {
actual.setConstantData(const_data);
}
// TODO( ): Fix LAyerBuilder object copying - pass by reference
// void LayerBuilder::addConstantData(const std::string & name, InferenceEngine::Blob::Ptr data){
// InferenceEngine::Blob::CPtr c_data = const_pointer_cast<const InferenceEngine::Blob>(data);
// actual.addConstantData(name, c_data);
// }
// LayerBuilder end

View File

@@ -0,0 +1,161 @@
// Copyright (c) 2018 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <ie_blob.h>
#include <iterator>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <sstream>
#include <ie_builders.hpp>
#include <inference_engine.hpp>
#include <ie_api_impl.hpp>
// namespace IE Python
namespace InferenceEnginePython {
struct LayerBuilder;
struct Port {
Port() = default;
explicit Port(const std::vector<size_t> &shapes);
InferenceEngine::Port actual;
std::vector<size_t> shape;
};
struct ILayer {
InferenceEngine::ILayer::CPtr layer_ptr;
std::string name;
size_t id;
std::string type;
std::map<std::string, std::string> parameters;
std::map<std::string, InferenceEngine::Blob::Ptr> constant_data;
std::vector<Port> in_ports;
std::vector<Port> out_ports;
};
struct PortInfo {
PortInfo(size_t layer_id, size_t port_id);
PortInfo() : actual(0, 0) {}
InferenceEngine::PortInfo actual;
size_t layer_id;
size_t port_id;
};
struct Connection {
Connection() : actual(InferenceEngine::PortInfo(0), InferenceEngine::PortInfo(0)) {}
Connection(PortInfo input, PortInfo output);
InferenceEngine::Connection actual;
PortInfo _from;
PortInfo to;
};
struct INetwork {
InferenceEngine::INetwork::Ptr actual;
std::string name;
size_t size;
std::vector<ILayer> layers;
std::vector<ILayer> inputs;
std::vector<ILayer> outputs;
std::vector<Connection> getLayerConnections(size_t layer_id);
IENetwork to_ie_network();
};
struct NetworkBuilder {
InferenceEngine::Builder::Network::Ptr network_ptr;
explicit NetworkBuilder(const std::string &name);
NetworkBuilder() = default;
NetworkBuilder from_ie_network(const InferenceEnginePython::IENetwork &icnn_net);
INetwork build();
std::vector<LayerBuilder> getLayers();
LayerBuilder getLayer(size_t layer_id);
void removeLayer(const LayerBuilder &layer);
size_t addLayer(const LayerBuilder &layer);
size_t addAndConnectLayer(const std::vector<PortInfo> &input, const LayerBuilder &layer);
const std::vector<Connection> getLayerConnections(const LayerBuilder &layer);
void disconnect(const Connection &connection);
void connect(const PortInfo &input, const PortInfo &output);
};
struct LayerBuilder {
InferenceEngine::Builder::Layer actual;
size_t id;
LayerBuilder(const std::string &type, const std::string &name);
LayerBuilder() : actual("", "") {}
LayerBuilder from_ilayer(const ILayer &ilayer);
const std::string &getName();
void setName(const std::string &name);
const std::string &getType();
void setType(const std::string &type);
std::vector<Port> getInputPorts();
void setInputPorts(const std::vector<Port> ports);
std::vector<Port> getOutputPorts();
void setOutputPorts(const std::vector<Port> ports);
std::map<std::string, std::string> getParameters();
void setParameters(std::map<std::string, std::string> params_map);
ILayer build();
std::map<std::string, InferenceEngine::Blob::Ptr> getConstantData();
InferenceEngine::Blob::Ptr allocateBlob(std::vector<size_t> dims, const std::string &precision);
void setConstantData(const std::map<std::string, InferenceEngine::Blob::Ptr> &const_data);
// TODO( ): Fix LAyerBuilder object copying - pass by reference
// void addConstantData(const std::string & name, InferenceEngine::Blob::Ptr data);
};
} // namespace InferenceEnginePython

View File

@@ -0,0 +1,97 @@
from libcpp.string cimport string
from libcpp.vector cimport vector
from libc.stddef cimport size_t
from libcpp.memory cimport shared_ptr
from libcpp.map cimport map
from ..ie_api_impl_defs cimport IENetwork
cdef extern from "<inference_engine.hpp>" namespace "InferenceEngine":
ctypedef vector[size_t] SizeVector
cdef cppclass TensorDesc:
SizeVector& getDims()
const Precision& getPrecision() const
cdef cppclass Blob:
ctypedef shared_ptr[Blob] Ptr
const TensorDesc& getTensorDesc() const
size_t element_size() const
cdef cppclass Precision:
const char*name() const
cdef extern from "dnn_builder_impl.hpp" namespace "InferenceEnginePython":
cdef cppclass ILayer:
const string name
size_t id
string type
map[string, string] parameters
vector[Port] in_ports
vector[Port] out_ports
map[string, Blob.Ptr] constant_data;
cdef cppclass INetwork:
string name
size_t size
vector[ILayer] layers
vector[ILayer] inputs
vector[ILayer] outputs
vector[Port] in_ports;
vector[Port] out_ports;
vector[Connection] getLayerConnections(size_t layer_id);
IENetwork to_ie_network();
cdef cppclass NetworkBuilder:
NetworkBuilder() except +
NetworkBuilder(string name) except +
NetworkBuilder from_ie_network(IENetwork &icnn_net) except +
INetwork build() except +
vector[LayerBuilder] getLayers() except +
LayerBuilder getLayer(size_t layer_id) except +
void removeLayer(const LayerBuilder& layer) except +
const vector[Connection] getLayerConnections(const LayerBuilder& layer) except +
void disconnect(const Connection& connection) except +
void connect(const PortInfo& input, const PortInfo& output) except +
size_t addLayer(const LayerBuilder& layer) except +
size_t addAndConnectLayer(const vector[PortInfo]& input, const LayerBuilder& layer);
cdef cppclass Port:
Port() except +
Port(const vector[size_t] & shapes) except +
const vector[size_t] shape
cdef cppclass PortInfo:
PortInfo(size_t layer_id, size_t port_id) except +
PortInfo() except +
size_t layer_id
size_t port_id
cdef cppclass Connection:
Connection(PortInfo input, PortInfo output) except +
Connection() except +
PortInfo _from
PortInfo to
cdef cppclass LayerBuilder:
LayerBuilder()
LayerBuilder(const string& type, const string& name ) except +
size_t id
LayerBuilder from_ilayer(const ILayer& ilayer) except +
string getName() except +
string getType() except +
vector[Port] getInputPorts() except +
vector[Port] getOutputPorts() except +
map[string, string] getParameters() except +
void setParameters(map[string, string] params_map) except +
void setName(const string & name) except +
void setType(const string & type) except +
void setInputPorts(const vector[Port] ports) except +
void setOutputPorts(const vector[Port] ports) except +
ILayer build() except +
map[string, Blob.Ptr] getConstantData()
void setConstantData(map[string, Blob.Ptr] &const_data)
# TODO: Fix LAyerBuilder object copying - pass by reference
# void addConstantData(const string & name, Blob.Ptr data)
Blob.Ptr allocateBlob(vector[size_t] dims, const string & precision)

View File

@@ -1,8 +1,3 @@
# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
from .cimport ie_api_impl_defs as C
from .ie_api_impl_defs cimport Blob, TensorDesc
@@ -24,24 +19,22 @@ cdef class BlobBuffer:
cdef class InferRequest:
cdef C.InferRequestWrap *impl
cpdef BlobBuffer _get_input_buffer(self, const string & blob_name)
cpdef BlobBuffer _get_output_buffer(self, const string & blob_name)
cpdef BlobBuffer _get_blob_buffer(self, const string & blob_name)
cpdef infer(self, inputs = ?)
cpdef async_infer(self, inputs = ?)
cpdef wait(self, timeout = ?)
cpdef get_perf_counts(self)
cdef public:
_inputs, _outputs
_inputs_list, _outputs_list
cdef class IENetwork:
cdef C.IENetwork impl
cdef class ExecutableNetwork:
cdef unique_ptr[C.IEExecNetwork] impl
cdef public:
_requests, async, _request_iterator
_requests, inputs, outputs
cdef class IEPlugin:
cdef C.IEPlugin impl
@@ -51,9 +44,6 @@ cdef class IEPlugin:
cpdef void set_initial_affinity(self, IENetwork network) except *
cpdef set get_supported_layers(self, IENetwork net)
cdef class IENetReader:
cdef C.IENetReader impl
cdef class IENetLayer:
cdef C.IENetLayer impl
@@ -61,4 +51,7 @@ cdef class InputInfo:
cdef C.InputInfo impl
cdef class OutputInfo:
cdef C.OutputInfo impl
cdef C.OutputInfo impl
cdef class LayersStatsMap(dict):
cdef C.IENetwork net_impl

View File

@@ -1,20 +1,18 @@
# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
#distutils: language=c++
from cython.operator cimport dereference as deref
from .cimport ie_api_impl_defs as C
from .ie_api_impl_defs cimport Blob, TensorDesc, SizeVector, Precision
from libcpp.string cimport string
from libcpp.vector cimport vector
from libcpp.pair cimport pair
from libcpp.map cimport map
from libcpp.memory cimport unique_ptr
from libc.stdint cimport int64_t
import os
import numpy as np
from copy import deepcopy
import warnings
from collections import OrderedDict
cdef extern from "<utility>" namespace "std" nogil:
cdef unique_ptr[C.IEExecNetwork] move(unique_ptr[C.IEExecNetwork])
@@ -35,7 +33,7 @@ cdef dict_to_c_map(py_dict):
supported_precisions = ["FP32", "FP16", "Q78", "I32", "I16", "I8", "U32", "U16"]
supported_layouts = ["NCHW", "NHWC", "OIHW", "C", "CHW", "HW", "NC", "CN", "BLOCKED"]
known_plugins = ['CPU', 'GPU', 'FPGA', 'MYRIAD', 'HETERO']
known_plugins = ['CPU', 'GPU', 'FPGA', 'MYRIAD', 'HETERO', 'HDDL']
def get_version():
return C.get_version().decode()
@@ -68,7 +66,23 @@ cdef class IENetLayer:
@property
def params(self):
return {k.decode(): v.decode() for k, v in self.impl.params}
@property
def parents(self):
cdef vector[string] c_parents = self.impl.parents
parents = []
return [parent.decode() for parent in c_parents]
@property
def children(self):
cdef vector[string] c_children = self.impl.children
children = []
return [child.decode() for child in c_children]
@property
def shape(self):
string_shape = self.impl.shape.decode()
return [int(i) for i in string_shape.split(' ')]
@property
def layout(self):
return self.impl.layout.decode()
@affinity.setter
def affinity(self, target_affinity):
self.impl.setAffinity(target_affinity.encode())
@@ -80,7 +94,6 @@ cdef class IENetLayer:
def precision(self, precision: str):
self.impl.setPrecision(precision.upper().encode())
cdef class InputInfo:
@property
def precision(self):
@@ -105,7 +118,6 @@ cdef class InputInfo:
"Unsupported layout {}! List of supported layouts: {}".format(layout, supported_layouts))
self.impl.setLayout(layout.encode())
cdef class OutputInfo:
@property
def precision(self):
@@ -122,20 +134,18 @@ cdef class OutputInfo:
raise AttributeError(
"Unsupported precision {}! List of supported precisions: {}".format(precision, supported_precisions))
self.impl.setPrecision(precision.encode())
# @layout.setter
# def layout(self, layout):
# self.impl.setLayout(layout.encode())
cdef class ExecutableNetwork:
def __init__(self):
self._requests = []
self.inputs = []
self.outputs = []
def infer(self, inputs=None):
current_request = self.requests[0]
current_request.infer(inputs)
return deepcopy(current_request.outputs)
def start_async(self, request_id, inputs=None):
if request_id not in list(range(len(self.requests))):
raise ValueError("Incorrect request_id specified!")
@@ -145,21 +155,25 @@ cdef class ExecutableNetwork:
@property
def requests(self):
return self._requests
requests = []
for i in range(deref(self.impl).infer_requests.size()):
infer_request = InferRequest()
infer_request.impl = &(deref(self.impl).infer_requests[i])
infer_request._inputs_list = self.inputs
infer_request._outputs_list = self.outputs
requests.append(infer_request)
return requests
cdef class InferRequest:
def __init__(self):
self._inputs = {}
self._outputs = {}
self._inputs_list = []
self._outputs_list = []
cpdef BlobBuffer _get_input_buffer(self, const string & blob_name):
cpdef BlobBuffer _get_blob_buffer(self, const string & blob_name):
cdef BlobBuffer buffer = BlobBuffer()
buffer.reset(deref(self.impl).getInputBlob(blob_name))
return buffer
cpdef BlobBuffer _get_output_buffer(self, const string & blob_name):
cdef BlobBuffer buffer = BlobBuffer()
buffer.reset(deref(self.impl).getOutputBlob(blob_name))
cdef Blob.Ptr blob_ptr
deref(self.impl).getBlobPtr(blob_name, blob_ptr)
buffer.reset(blob_ptr)
return buffer
cpdef infer(self, inputs=None):
@@ -192,17 +206,66 @@ cdef class InferRequest:
@property
def inputs(self):
return self._inputs
inputs = {}
for input in self._inputs_list:
inputs[input] = self._get_blob_buffer(input.encode()).to_numpy()
return inputs
@property
def outputs(self):
return self._outputs
outputs = {}
for output in self._outputs_list:
outputs[output] = self._get_blob_buffer(output.encode()).to_numpy()
return deepcopy(outputs)
def set_batch(self, size):
if size <= 0:
raise ValueError("Batch size should be positive integer number but {} specified".format(size))
deref(self.impl).setBatch(size)
def _fill_inputs(self, inputs):
for k, v in inputs.items():
self._inputs[k][:] = v
self.inputs[k][:] = v
class LayerStats:
def __init__(self, min: tuple = (), max: tuple = ()):
self._min = min
self._max = max
@property
def min(self):
return self._min
@property
def max(self):
return self._max
cdef class LayersStatsMap(dict):
def update(self, other=None, **kwargs):
super(LayersStatsMap, self).update(other, **kwargs)
cdef map[string, map[string, vector[float]]] c_stats_map
cdef map[string, vector[float]] c_node_stats
for k, v in self.items():
c_node_stats["min".encode()] = v.min
c_node_stats["max".encode()] = v.max
c_stats_map[k.encode()] = c_node_stats
self.net_impl.setStats(c_stats_map)
cdef class IENetwork:
def __cinit__(self, model: str="", weights: str=""):
cdef string model_
cdef string weights_
if model and weights:
if not os.path.isfile(model):
raise Exception("Path to the model {} doesn't exists or it's a directory".format(model))
if not os.path.isfile(weights):
raise Exception("Path to the weights {} doesn't exists or it's a directory".format(weights))
model_ = model.encode()
weights_ = weights.encode()
self.impl = C.IENetwork(model_, weights_)
else:
self.impl = C.IENetwork()
@property
def name(self):
name = bytes(self.impl.name)
@@ -213,7 +276,7 @@ cdef class IENetwork:
cdef map[string, C.InputInfo] c_inputs = self.impl.getInputs()
inputs = {}
cdef InputInfo in_info
for input in c_inputs:
for input in c_inputs:
in_info = InputInfo()
in_info.impl = input.second
inputs[input.first.decode()] = in_info
@@ -224,7 +287,7 @@ cdef class IENetwork:
cdef map[string, C.OutputInfo] c_outputs = self.impl.getOutputs()
outputs = {}
cdef OutputInfo out_info
for out in c_outputs:
for out in c_outputs:
out_info = OutputInfo()
out_info.impl = out.second
outputs[out.first.decode()] = out_info
@@ -243,23 +306,37 @@ cdef class IENetwork:
@property
def layers(self):
cdef map[string, C.IENetLayer] c_layers = <map[string, C.IENetLayer]> self.impl.getLayers()
layers = {}
cdef vector[pair[string, C.IENetLayer]] c_layers = self.impl.getLayers()
layers = OrderedDict()
cdef IENetLayer net_l = IENetLayer()
for l in c_layers:
net_l = IENetLayer()
net_l.impl = l.second
layers[l.first.decode()] = net_l
return layers
@property
def stats(self):
cdef map[string, map[string, vector[float]]] c_stats_map = self.impl.getStats()
py_stats_map = LayersStatsMap()
py_stats_map.net_impl = self.impl
for it in c_stats_map:
stats_map = LayersStatsMap()
py_stats_map[it.first.decode()] = LayerStats(min=tuple(it.second["min".encode()]),
max=tuple(it.second["max".encode()]))
return py_stats_map
@classmethod
def from_ir(cls, model: str, weights: str):
warnings.filterwarnings("always",category=DeprecationWarning)
warnings.warn("from_ir() method of IENetwork is deprecated. "
"Please use IENetwork class constructor to create valid IENetwork instance",
DeprecationWarning)
if not os.path.isfile(model):
raise Exception("Path to the model {} doesn't exists or it's a directory".format(model))
if not os.path.isfile(weights):
raise Exception("Path to the weights {} doesn't exists or it's a directory".format(weights))
net_reader = IENetReader()
return net_reader.read(model, weights)
cdef IENetwork net = IENetwork(model, weights)
return net
# TODO: Use enum with precision type instead of srting parameter when python2 support will not be required.
def add_outputs(self, outputs, precision="FP32"):
@@ -273,6 +350,8 @@ cdef class IENetwork:
_outputs.push_back(l.encode())
self.impl.addOutputs(_outputs, precision.upper().encode())
def serialize(self, path_to_xml, path_to_bin):
self.impl.serialize(path_to_xml.encode(), path_to_bin.encode())
def reshape(self, input_shapes: dict):
cdef map[string, vector[size_t]] c_input_shapes;
cdef vector[size_t] c_shape
@@ -312,8 +391,6 @@ cdef class IEPlugin:
raise ValueError(
"Incorrect number of requests specified: {}. Expected positive integer number.".format(num_requests))
cdef ExecutableNetwork exec_net = ExecutableNetwork()
cdef vector[string] inputs_list
cdef vector[string] outputs_list
cdef map[string, string] c_config
if config:
@@ -321,27 +398,8 @@ cdef class IEPlugin:
c_config[to_std_string(k)] = to_std_string(v)
exec_net.impl = move(self.impl.load(network.impl, num_requests, c_config))
requests = []
for i in range(deref(exec_net.impl).infer_requests.size()):
infer_request = InferRequest()
infer_request.impl = &(deref(exec_net.impl).infer_requests[i])
inputs_list = infer_request.impl.getInputsList()
outputs_list = infer_request.impl.getOutputsList()
for input_b in inputs_list:
input_s = input_b.decode()
infer_request._inputs[input_s] = infer_request._get_input_buffer(input_b).to_numpy()
for output_b in outputs_list:
output_s = output_b.decode()
infer_request._outputs[output_s] = infer_request._get_output_buffer(output_b).to_numpy()
# create blob buffers
requests.append(infer_request)
exec_net._requests = tuple(requests)
exec_net.inputs = network.inputs.keys()
exec_net.outputs = list(network.outputs.keys())
return exec_net
cpdef void set_initial_affinity(self, IENetwork net) except *:
@@ -374,11 +432,6 @@ cdef class IEPlugin:
c_config[to_std_string(k)] = to_std_string(v)
self.impl.setConfig(c_config)
cdef class IENetReader:
def read(self, model: str, weights: str) -> IENetwork:
cdef IENetwork net = IENetwork()
net.impl = self.impl.read(model.encode(), weights.encode())
return net
cdef class BlobBuffer:
"""Copy-less accessor for Inference Engine Blob"""

View File

@@ -1,31 +1,42 @@
// Copyright (C) 2018 Intel Corporation
// Copyright (c) 2018 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "ie_api_impl.hpp"
#include "hetero/hetero_plugin_config.hpp"
#include "ie_iinfer_request.hpp"
std::map <std::string,InferenceEngine::Precision> precision_map = {{"FP32", InferenceEngine::Precision::FP32},
{"FP16", InferenceEngine::Precision::FP16},
{"Q78", InferenceEngine::Precision::Q78},
{"I32", InferenceEngine::Precision::I32},
{"I16", InferenceEngine::Precision::I16},
{"I8", InferenceEngine::Precision::I8},
{"U16", InferenceEngine::Precision::U16},
{"U8", InferenceEngine::Precision::U8}};
#include "details/ie_cnn_network_tools.h"
std::map <std::string,InferenceEngine::Layout> layout_map = {{"ANY", InferenceEngine::Layout::ANY},
{"NCHW", InferenceEngine::Layout::NCHW},
{"NHWC", InferenceEngine::Layout::NHWC},
{"OIHW", InferenceEngine::Layout::OIHW},
{"C", InferenceEngine::Layout::C},
{"CHW", InferenceEngine::Layout::CHW},
{"HW", InferenceEngine::Layout::HW},
{"NC", InferenceEngine::Layout::NC},
{"CN", InferenceEngine::Layout::CN},
{"BLOCKED", InferenceEngine::Layout::BLOCKED}};
#define stringify( name ) # name
std::map<std::string, InferenceEngine::Precision> precision_map = {{"FP32", InferenceEngine::Precision::FP32},
{"FP16", InferenceEngine::Precision::FP16},
{"Q78", InferenceEngine::Precision::Q78},
{"I32", InferenceEngine::Precision::I32},
{"I16", InferenceEngine::Precision::I16},
{"I8", InferenceEngine::Precision::I8},
{"U16", InferenceEngine::Precision::U16},
{"U8", InferenceEngine::Precision::U8}};
std::map<std::string, InferenceEngine::Layout> layout_map = {{"ANY", InferenceEngine::Layout::ANY},
{"NCHW", InferenceEngine::Layout::NCHW},
{"NHWC", InferenceEngine::Layout::NHWC},
{"OIHW", InferenceEngine::Layout::OIHW},
{"C", InferenceEngine::Layout::C},
{"CHW", InferenceEngine::Layout::CHW},
{"HW", InferenceEngine::Layout::HW},
{"NC", InferenceEngine::Layout::NC},
{"CN", InferenceEngine::Layout::CN},
{"BLOCKED", InferenceEngine::Layout::BLOCKED}};
#define stringify(name) # name
#define IE_CHECK_CALL(expr) { \
auto ret = (expr); \
if (ret != InferenceEngine::StatusCode::OK) { \
@@ -34,119 +45,121 @@ std::map <std::string,InferenceEngine::Layout> layout_map = {{"ANY", InferenceEn
} \
InferenceEnginePython::IENetwork InferenceEnginePython::IENetReader::read(std::string const &model,
std::string const &weights)
{
InferenceEnginePython::IENetwork::IENetwork(const std::string &model, const std::string &weights) {
InferenceEngine::CNNNetReader net_reader;
net_reader.ReadNetwork(model);
net_reader.ReadWeights(weights);
const std::string &net_name = net_reader.getName();
InferenceEngine::CNNNetwork network = net_reader.getNetwork();
std::size_t batch_size = network.getBatchSize();
return {network, net_name, batch_size};
name = net_reader.getName();
actual = net_reader.getNetwork();
batch_size = actual.getBatchSize();
}
std::map<std::string, InferenceEnginePython::IENetLayer> InferenceEnginePython::IENetwork::getLayers()
{
std::map<std::string, InferenceEnginePython::IENetLayer> result;
std::unordered_set<std::string> visisted;
const InferenceEngine::InputsDataMap &networkInputs = actual.getInputsInfo();
void InferenceEnginePython::IENetwork::serialize(const std::string &path_to_xml, const std::string &path_to_bin) {
actual.serialize(path_to_xml, path_to_bin);
}
using CNNLayerPtrCref = const InferenceEngine::CNNLayerPtr &;
std::function<void(CNNLayerPtrCref)> DFS = [&](CNNLayerPtrCref layer) {
const std::vector<std::pair<std::string, InferenceEnginePython::IENetLayer>>
InferenceEnginePython::IENetwork::getLayers() {
std::vector<std::pair<std::string, InferenceEnginePython::IENetLayer>> result;
std::vector<InferenceEngine::CNNLayerPtr> sorted_layers = InferenceEngine::details::CNNNetSortTopologically(actual);
for (const auto &layer : sorted_layers) {
InferenceEnginePython::IENetLayer layer_info;
/* Assumes no cycles in graph */
for (auto &od : layer->outData)
{
for (auto nl : od->getInputTo())
{
auto i = visisted.find(nl.second->name);
if (i != visisted.end())
{
continue;
}
DFS(nl.second);
}
}
visisted.emplace(layer->name);
layer_info.layer_ptr = layer;
layer_info.network_ptr = actual;
layer_info.name = layer->name;
layer_info.type = layer->type;
std::string precision = layer->precision.name();
layer_info.precision = precision;
layer_info.precision = layer->precision.name();
layer_info.params = layer->params;
layer_info.affinity = layer->affinity;
result[layer->name] = layer_info;
};
std::set<InferenceEngine::CNNLayerPtr> inputs;
for (auto input : networkInputs) {
for (auto l : input.second->getInputData()->inputTo) {
inputs.insert(l.second);
std::vector<std::string> parents;
for (const auto &i : layer->insData) {
auto data = i.lock();
if (data) {
parents.emplace_back(data->getName());
}
}
layer_info.parents = parents;
std::vector<std::string> children;
for (const auto &data : layer->outData) {
auto inputTo = data->getInputTo();
for (auto layer_iter : inputTo) {
InferenceEngine::CNNLayerPtr layer_in_data = layer_iter.second;
if (!layer_in_data) {
THROW_IE_EXCEPTION << "Layer which takes data " << data->name << " is nullptr";
}
children.emplace_back(layer_in_data->name);
}
}
layer_info.children = children;
const InferenceEngine::TensorDesc &inputTensorDesc = layer->outData[0]->getTensorDesc();
for (const auto &it : layout_map) {
if (it.second == inputTensorDesc.getLayout()) {
layer_info.layout = it.first;
}
}
auto dims = inputTensorDesc.getDims();
std::string string_dims = "";
for (const auto &it : dims) {
string_dims += std::to_string(it) + " ";
}
string_dims = string_dims.substr(0, string_dims.size() - 1);
layer_info.shape = string_dims;
result.emplace_back(std::make_pair(layer->name, layer_info));
}
for (auto &layer : inputs)
{
DFS(layer);
}
return result;
}
std::map<std::string, InferenceEnginePython::InputInfo> InferenceEnginePython::IENetwork::getInputs(){
const std::map<std::string, InferenceEnginePython::InputInfo> InferenceEnginePython::IENetwork::getInputs() {
std::map<std::string, InferenceEnginePython::InputInfo> inputs;
const InferenceEngine::InputsDataMap &inputsInfo = actual.getInputsInfo();
for (auto & in : inputsInfo){
for (auto &in : inputsInfo) {
InferenceEnginePython::InputInfo info;
info.actual = *in.second;
const InferenceEngine::TensorDesc &inputTensorDesc = in.second->getTensorDesc();
info.dims = inputTensorDesc.getDims();
for (auto it : precision_map )
for (auto it : precision_map)
if (it.second == in.second->getPrecision())
info.precision = it.first;
for (auto it : layout_map )
info.precision = it.first;
for (auto it : layout_map)
if (it.second == in.second->getLayout())
info.layout = it.first;
info.layout = it.first;
inputs[in.first] = info;
}
return inputs;
}
std::map<std::string, InferenceEnginePython::OutputInfo> InferenceEnginePython::IENetwork::getOutputs(){
const std::map<std::string, InferenceEnginePython::OutputInfo> InferenceEnginePython::IENetwork::getOutputs() {
std::map<std::string, InferenceEnginePython::OutputInfo> outputs;
const InferenceEngine::OutputsDataMap &outputsInfo = actual.getOutputsInfo();
for (auto & out : outputsInfo){
for (auto &out : outputsInfo) {
InferenceEnginePython::OutputInfo info;
info.actual = out.second;
const InferenceEngine::TensorDesc &inputTensorDesc = out.second->getTensorDesc();
info.dims = inputTensorDesc.getDims();
for (auto it : precision_map )
for (auto it : precision_map)
if (it.second == out.second->getPrecision())
info.precision = it.first;
for (auto it : layout_map )
info.precision = it.first;
for (auto it : layout_map)
if (it.second == out.second->getLayout())
info.layout = it.first;
info.layout = it.first;
outputs[out.first] = info;
}
return outputs;
}
void InferenceEnginePython::IENetwork::addOutputs(const std::vector<std::string> & out_layers, const std::string &precision)
{
for (auto && l : out_layers)
{
void
InferenceEnginePython::IENetwork::addOutputs(const std::vector<std::string> &out_layers, const std::string &precision) {
for (auto &&l : out_layers) {
InferenceEngine::OutputsDataMap outputsDataMap = actual.getOutputsInfo();
if (outputsDataMap.find(l) != outputsDataMap.end())
{
if (outputsDataMap.find(l) != outputsDataMap.end()) {
continue;
}
InferenceEngine::CNNLayerPtr cnnLayer = actual.getLayerByName(l.c_str());
std::vector<InferenceEngine::DataPtr> outData = cnnLayer->outData;
if (outData.size() != 1) {
std::cout << "Layer " << l << " has " << outData.size() << " output blobs and can not be set as output." << std::endl;
std::cout << "Layer " << l << " has " << outData.size() << " output blobs and can not be set as output."
<< std::endl;
continue;
}
actual.addOutput(l);
@@ -155,29 +168,59 @@ void InferenceEnginePython::IENetwork::addOutputs(const std::vector<std::string>
}
}
void InferenceEnginePython::IENetwork::setBatch(const size_t size)
{
void InferenceEnginePython::IENetwork::setBatch(const size_t size) {
actual.setBatchSize(size);
}
void InferenceEnginePython::IENetwork::reshape(const std::map<std::string, std::vector<size_t>> & input_shapes){
void InferenceEnginePython::IENetwork::reshape(const std::map<std::string, std::vector<size_t>> &input_shapes) {
actual.reshape(input_shapes);
}
void InferenceEnginePython::InputInfo::setPrecision(std::string precision){
const std::map<std::string, std::map<std::string, std::vector<float>>> InferenceEnginePython::IENetwork::getStats() {
InferenceEngine::ICNNNetworkStats *pstats = nullptr;
InferenceEngine::ResponseDesc response;
IE_CHECK_CALL(((InferenceEngine::ICNNNetwork &) actual).getStats(&pstats, &response));
auto statsMap = pstats->getNodesStats();
std::map<std::string, std::map<std::string, std::vector<float>>> map;
for (const auto &it : statsMap) {
std::map<std::string, std::vector<float>> stats;
stats.emplace("min", it.second->_minOutputs);
stats.emplace("max", it.second->_maxOutputs);
map.emplace(it.first, stats);
}
return map;
}
void
InferenceEnginePython::IENetwork::setStats(
const std::map<std::string, std::map<std::string, std::vector<float>>> &stats) {
InferenceEngine::ICNNNetworkStats *pstats = nullptr;
InferenceEngine::ResponseDesc response;
IE_CHECK_CALL(((InferenceEngine::ICNNNetwork &) actual).getStats(&pstats, &response));
std::map<std::string, InferenceEngine::NetworkNodeStatsPtr> newNetNodesStats;
for (const auto &it : stats) {
InferenceEngine::NetworkNodeStatsPtr nodeStats = InferenceEngine::NetworkNodeStatsPtr(
new InferenceEngine::NetworkNodeStats());
newNetNodesStats.emplace(it.first, nodeStats);
nodeStats->_minOutputs = it.second.at("min");
nodeStats->_maxOutputs = it.second.at("max");
}
pstats->setNodesStats(newNetNodesStats);
}
void InferenceEnginePython::InputInfo::setPrecision(std::string precision) {
actual.setPrecision(precision_map[precision]);
}
void InferenceEnginePython::InputInfo::setLayout(std::string layout){
void InferenceEnginePython::InputInfo::setLayout(std::string layout) {
actual.setLayout(layout_map[layout]);
}
void InferenceEnginePython::OutputInfo::setPrecision(std::string precision){
void InferenceEnginePython::OutputInfo::setPrecision(std::string precision) {
actual->setPrecision(precision_map[precision]);
}
InferenceEnginePython::IEPlugin::IEPlugin(const std::string &device, const std::vector<std::string> &plugin_dirs)
{
InferenceEnginePython::IEPlugin::IEPlugin(const std::string &device, const std::vector<std::string> &plugin_dirs) {
InferenceEngine::PluginDispatcher dispatcher{plugin_dirs};
actual = dispatcher.getPluginByDevice(device);
const InferenceEngine::Version *pluginVersion;
@@ -188,65 +231,63 @@ InferenceEnginePython::IEPlugin::IEPlugin(const std::string &device, const std::
device_name = device;
}
void InferenceEnginePython::IEPlugin::setInitialAffinity(InferenceEnginePython::IENetwork &net)
{
void InferenceEnginePython::IEPlugin::setInitialAffinity(const InferenceEnginePython::IENetwork &net) {
InferenceEngine::HeteroPluginPtr hetero_plugin(actual);
InferenceEngine::ResponseDesc response;
auto &network = net.actual;
IE_CHECK_CALL(hetero_plugin->SetAffinity(network, {}, &response));
}
std::set<std::string> InferenceEnginePython::IEPlugin::queryNetwork(InferenceEnginePython::IENetwork &net)
{
InferenceEngine::CNNNetwork &network = net.actual;
std::set<std::string> InferenceEnginePython::IEPlugin::queryNetwork(const InferenceEnginePython::IENetwork &net) {
const InferenceEngine::CNNNetwork &network = net.actual;
InferenceEngine::QueryNetworkResult queryRes;
actual->QueryNetwork(network, queryRes);
return queryRes.supportedLayers;
}
void InferenceEnginePython::IENetLayer::setAffinity(const std::string & target_affinity){
void InferenceEnginePython::IENetLayer::setAffinity(const std::string &target_affinity) {
layer_ptr->affinity = target_affinity;
}
void InferenceEnginePython::IENetLayer::setParams(const std::map<std::string, std::string> & params_map){
void InferenceEnginePython::IENetLayer::setParams(const std::map<std::string, std::string> &params_map) {
layer_ptr->params = params_map;
}
std::map<std::string, InferenceEngine::Blob::Ptr> InferenceEnginePython::IENetLayer::getWeights(){
std::map<std::string, InferenceEngine::Blob::Ptr> InferenceEnginePython::IENetLayer::getWeights() {
auto w_layer = std::dynamic_pointer_cast<InferenceEngine::WeightableLayer>(layer_ptr);
// IF current layer is weightable gather weights and biases from casted WeightableLayer and all other blobs
// considered as custom and gathered from blobs field pf CNNLayer.
std::map<std::string, InferenceEngine::Blob::Ptr> weights;
if (w_layer != nullptr){
if (w_layer->_weights != nullptr){
if (w_layer != nullptr) {
if (w_layer->_weights != nullptr) {
weights["weights"] = w_layer->_weights;
}
if (w_layer->_biases != nullptr){
if (w_layer->_biases != nullptr) {
weights["biases"] = w_layer->_biases;
}
for (auto it : w_layer->blobs){
if (it.first == "weights" || it.first == "biases"){
for (auto it : w_layer->blobs) {
if (it.first == "weights" || it.first == "biases") {
continue;
}
weights[it.first] = it.second;
}
}
// Otherwise all layer's blobs are considered as custom and gathered from CNNLayer
else {
} else {
// Otherwise all layer's blobs are considered as custom and gathered from CNNLayer
std::map<std::string, InferenceEngine::Blob::Ptr> map_placeholder;
weights = map_placeholder; // If layer has no blobs it should not be missed from weights map
for (auto it : layer_ptr->blobs){
weights = map_placeholder; // If layer has no blobs it should not be missed from weights map
for (auto it : layer_ptr->blobs) {
weights[it.first] = it.second;
}
}
return weights;
}
void InferenceEnginePython::IENetLayer::setPrecision(std::string precision){
void InferenceEnginePython::IENetLayer::setPrecision(std::string precision) {
layer_ptr->precision = precision_map[precision];
}
void InferenceEnginePython::IEPlugin::addCpuExtension(const std::string &extension_path)
{
void InferenceEnginePython::IEPlugin::addCpuExtension(const std::string &extension_path) {
InferenceEngine::ResponseDesc response;
auto extension_ptr = InferenceEngine::make_so_pointer<InferenceEngine::IExtension>(extension_path);
auto extension = std::dynamic_pointer_cast<InferenceEngine::IExtension>(extension_ptr);
@@ -254,78 +295,49 @@ void InferenceEnginePython::IEPlugin::addCpuExtension(const std::string &extensi
}
std::unique_ptr<InferenceEnginePython::IEExecNetwork>
InferenceEnginePython::IEPlugin::load(InferenceEnginePython::IENetwork &net,
InferenceEnginePython::IEPlugin::load(const InferenceEnginePython::IENetwork &net,
int num_requests,
const std::map<std::string, std::string> &config)
{
const std::map<std::string, std::string> &config) {
InferenceEngine::ResponseDesc response;
auto exec_network = InferenceEnginePython::make_unique<InferenceEnginePython::IEExecNetwork>(net.name, num_requests);
auto exec_network = InferenceEnginePython::make_unique<InferenceEnginePython::IEExecNetwork>(net.name,
num_requests);
IE_CHECK_CALL(actual->LoadNetwork(exec_network->actual, net.actual, config, &response))
const InferenceEngine::InputsDataMap &inputs_info = net.actual.getInputsInfo();
const InferenceEngine::OutputsDataMap &outputs_info = net.actual.getOutputsInfo();
for (size_t i = 0; i < num_requests; ++i) {
InferRequestWrap &infer_request = exec_network->infer_requests[i];
IE_CHECK_CALL(exec_network->actual->CreateInferRequest(infer_request.request_ptr, &response))
for (const auto& input : inputs_info) {
infer_request.inputs[input.first] = nullptr;
infer_request.request_ptr->GetBlob(input.first.c_str(), infer_request.inputs[input.first], &response);
}
for (const auto& output : outputs_info) {
infer_request.request_ptr->GetBlob(output.first.c_str(), infer_request.outputs[output.first], &response);
}
}
return exec_network;
}
void InferenceEnginePython::IEPlugin::setConfig(const std::map<std::string, std::string> & config) {
void InferenceEnginePython::IEPlugin::setConfig(const std::map<std::string, std::string> &config) {
InferenceEngine::ResponseDesc response;
IE_CHECK_CALL(actual->SetConfig(config, &response))
}
InferenceEnginePython::IEExecNetwork::IEExecNetwork(const std::string &name, size_t num_requests) :
infer_requests(num_requests), name(name)
{
infer_requests(num_requests), name(name) {
}
void InferenceEnginePython::IEExecNetwork::infer()
{
void InferenceEnginePython::IEExecNetwork::infer() {
InferenceEngine::ResponseDesc response;
InferRequestWrap &request = infer_requests[0];
request.request_ptr->Infer(&response);
}
InferenceEngine::Blob::Ptr &InferenceEnginePython::InferRequestWrap::getInputBlob(const std::string &blob_name)
void InferenceEnginePython::InferRequestWrap::getBlobPtr(const std::string &blob_name, InferenceEngine::Blob::Ptr &blob_ptr)
{
return inputs.at(blob_name);
InferenceEngine::ResponseDesc response;
IE_CHECK_CALL(request_ptr->GetBlob(blob_name.c_str(), blob_ptr, &response));
}
InferenceEngine::Blob::Ptr &InferenceEnginePython::InferRequestWrap::getOutputBlob(const std::string &blob_name)
{
return outputs.at(blob_name);
}
std::vector<std::string> InferenceEnginePython::InferRequestWrap::getInputsList() {
std::vector<std::string> inputs_list;
inputs_list.reserve(inputs.size());
std::transform(inputs.begin(), inputs.end(), std::back_inserter(inputs_list), [] (InferenceEngine::BlobMap::value_type it) -> std::string {
return it.first;
});
return inputs_list;
}
std::vector<std::string> InferenceEnginePython::InferRequestWrap::getOutputsList() {
std::vector<std::string> outputs_list;
outputs_list.reserve(inputs.size());
std::transform(outputs.begin(), outputs.end(), std::back_inserter(outputs_list), [] (InferenceEngine::BlobMap::value_type it) -> std::string {
return it.first;
});
return outputs_list;
void InferenceEnginePython::InferRequestWrap::setBatch(int size) {
InferenceEngine::ResponseDesc response;
IE_CHECK_CALL(request_ptr->SetBatch(size, &response));
}
void InferenceEnginePython::InferRequestWrap::infer() {
@@ -344,13 +356,14 @@ int InferenceEnginePython::InferRequestWrap::wait(int64_t timeout) {
return static_cast<int >(code);
}
std::map<std::string, InferenceEnginePython::ProfileInfo> InferenceEnginePython::InferRequestWrap::getPerformanceCounts(){
std::map<std::string, InferenceEnginePython::ProfileInfo>
InferenceEnginePython::InferRequestWrap::getPerformanceCounts() {
std::map<std::string, InferenceEngine::InferenceEngineProfileInfo> perf_counts;
InferenceEngine::ResponseDesc response;
request_ptr->GetPerformanceCounts(perf_counts, &response);
std::map<std::string, InferenceEnginePython::ProfileInfo> perf_map;
for (auto it : perf_counts){
for (auto it : perf_counts) {
InferenceEnginePython::ProfileInfo profile_info;
switch (it.second.status) {
case InferenceEngine::InferenceEngineProfileInfo::EXECUTED:

View File

@@ -0,0 +1,174 @@
// Copyright (c) 2018 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <ie_extension.h>
#include <iterator>
#include <string>
#include <utility>
#include <map>
#include <vector>
#include <set>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <inference_engine.hpp>
namespace InferenceEnginePython {
struct IENetLayer {
InferenceEngine::CNNLayerPtr layer_ptr;
InferenceEngine::CNNNetwork network_ptr;
std::string name;
std::string type;
std::string precision;
std::string shape;
std::string layout;
std::vector<std::string> children;
std::vector<std::string> parents;
std::string affinity;
std::map<std::string, std::string> params;
void setAffinity(const std::string &target_affinity);
void setParams(const std::map<std::string, std::string> &params_map);
std::map<std::string, InferenceEngine::Blob::Ptr> getWeights();
void setPrecision(std::string precision);
};
struct InputInfo {
InferenceEngine::InputInfo actual;
std::vector<size_t> dims;
std::string precision;
std::string layout;
void setPrecision(std::string precision);
void setLayout(std::string layout);
};
struct OutputInfo {
InferenceEngine::DataPtr actual;
std::vector<size_t> dims;
std::string precision;
std::string layout;
void setPrecision(std::string precision);
};
struct ProfileInfo {
std::string status;
std::string exec_type;
std::string layer_type;
int64_t real_time;
int64_t cpu_time;
unsigned execution_index;
};
struct IENetwork {
InferenceEngine::CNNNetwork actual;
std::string name;
std::size_t batch_size;
void setBatch(const size_t size);
void addOutputs(const std::vector<std::string> &out_layers, const std::string &precision);
const std::vector<std::pair<std::string, InferenceEnginePython::IENetLayer>> getLayers();
const std::map<std::string, InferenceEnginePython::InputInfo> getInputs();
const std::map<std::string, InferenceEnginePython::OutputInfo> getOutputs();
void reshape(const std::map<std::string, std::vector<size_t>> &input_shapes);
void serialize(const std::string &path_to_xml, const std::string &path_to_bin);
void setStats(const std::map<std::string, std::map<std::string, std::vector<float>>> &stats);
const std::map<std::string, std::map<std::string, std::vector<float>>> getStats();
IENetwork(const std::string &model, const std::string &weights);
IENetwork() = default;
};
struct InferRequestWrap {
InferenceEngine::IInferRequest::Ptr request_ptr;
void infer();
void infer_async();
int wait(int64_t timeout);
void getBlobPtr(const std::string &blob_name, InferenceEngine::Blob::Ptr &blob_ptr);
void setBatch(int size);
std::map<std::string, InferenceEnginePython::ProfileInfo> getPerformanceCounts();
};
struct IEExecNetwork {
InferenceEngine::IExecutableNetwork::Ptr actual;
std::vector<InferRequestWrap> infer_requests;
std::string name;
IEExecNetwork(const std::string &name, size_t num_requests);
void infer();
};
struct IEPlugin {
std::unique_ptr<InferenceEnginePython::IEExecNetwork> load(const InferenceEnginePython::IENetwork &net,
int num_requests,
const std::map<std::string, std::string> &config);
std::string device_name;
std::string version;
void setConfig(const std::map<std::string, std::string> &);
void addCpuExtension(const std::string &extension_path);
void setInitialAffinity(const InferenceEnginePython::IENetwork &net);
IEPlugin(const std::string &device, const std::vector<std::string> &plugin_dirs);
IEPlugin() = default;
std::set<std::string> queryNetwork(const InferenceEnginePython::IENetwork &net);
InferenceEngine::InferenceEnginePluginPtr actual;
};
template<class T>
T *get_buffer(InferenceEngine::Blob &blob) {
return blob.buffer().as<T *>();
}
template<class T, class... Args>
std::unique_ptr<T> make_unique(Args &&... args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
std::string get_version();
}; // namespace InferenceEnginePython

View File

@@ -1,8 +1,3 @@
# Copyright (C) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
from libc.stddef cimport size_t
from libcpp.string cimport string
from libcpp.vector cimport vector
@@ -10,7 +5,6 @@ from libcpp.map cimport map
from libcpp.set cimport set
from libcpp.pair cimport pair
from libcpp.memory cimport unique_ptr, shared_ptr
from libcpp cimport bool
from libc.stdint cimport int64_t
@@ -28,7 +22,7 @@ cdef extern from "<inference_engine.hpp>" namespace "InferenceEngine":
size_t element_size() const
cdef cppclass Precision:
const char* name() const
const char*name() const
cdef extern from "ie_api_impl.hpp" namespace "InferenceEnginePython":
@@ -37,9 +31,11 @@ cdef extern from "ie_api_impl.hpp" namespace "InferenceEnginePython":
string type
string precision
string affinity
string shape
string layout
vector[string] children
vector[string] parents
map[string, string] params
# map[string, BlobInfo] blob_info
# map[string, Blob.Ptr] weights;
void setAffinity(const string & target_affinity) except +
void setParams(const map[string, string] & params_map) except +
map[string, Blob.Ptr] getWeights() except +
@@ -58,7 +54,6 @@ cdef extern from "ie_api_impl.hpp" namespace "InferenceEnginePython":
string layout
void setPrecision(string precision)
cdef cppclass ProfileInfo:
string status
string exec_type
@@ -68,51 +63,50 @@ cdef extern from "ie_api_impl.hpp" namespace "InferenceEnginePython":
unsigned int execution_index
cdef cppclass WeightsInfo:
Blob.Ptr &weights;
Blob.Ptr &biases;
Blob.Ptr & weights;
Blob.Ptr & biases;
map[string, Blob.Ptr] custom_blobs;
cdef cppclass IEExecNetwork:
vector[InferRequestWrap] infer_requests
cdef cppclass IENetwork:
IENetwork() except +
IENetwork(const string &, const string &) except +
string name
size_t batch_size
map[string, vector[size_t]] inputs
map[string, IENetLayer] getLayers() except +
const vector[pair[string, IENetLayer]] getLayers() except +
map[string, InputInfo] getInputs() except +
map[string, OutputInfo] getOutputs() except +
void addOutputs(vector[string] &, string &) except +
void setAffinity(map[string, string] &types_affinity_map, map[string, string] &layers_affinity_map) except +
void setAffinity(map[string, string] & types_affinity_map, map[string, string] & layers_affinity_map) except +
void setBatch(size_t size) except +
void setLayerParams(map[string, map[string, string]] params_map) except +
void serialize(const string& path_to_xml, const string& path_to_bin) except +
void reshape(map[string, vector[size_t]] input_shapes) except +
void setStats(map[string, map[string, vector[float]]] & stats) except +
map[string, map[string, vector[float]]] getStats() except +
cdef cppclass IEPlugin:
IEPlugin() except +
IEPlugin(const string &, const vector[string] &) except +
unique_ptr[IEExecNetwork] load(IENetwork & net, int num_requests, const map[string, string]& config) except +
void addCpuExtension(const string &) except +
void setConfig(const map[string, string]&) except +
void setConfig(const map[string, string] &) except +
void setInitialAffinity(IENetwork & net) except +
set[string] queryNetwork(const IENetwork &net) except +
set[string] queryNetwork(const IENetwork & net) except +
string device_name
string version
cdef cppclass IENetReader:
IENetwork read(const string &, const string &) except +
cdef cppclass InferRequestWrap:
vector[string] getInputsList() except +
vector[string] getOutputsList() except +
Blob.Ptr& getOutputBlob(const string &blob_name) except +
Blob.Ptr& getInputBlob(const string &blob_name) except +
void getBlobPtr(const string &blob_name, Blob.Ptr &blob_ptr)
map[string, ProfileInfo] getPerformanceCounts() except +
void infer() except +
void infer_async() except +
int wait(int64_t timeout) except +
void setBatch(int size) except +
cdef T* get_buffer[T](Blob &)
cdef T*get_buffer[T](Blob &)
cdef string get_version()

View File

@@ -0,0 +1,83 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for ArgMax layer
*/
class INFERENCE_ENGINE_API_CLASS(ArgMaxLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit ArgMaxLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit ArgMaxLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
ArgMaxLayer& setName(const std::string& name);
/**
* @brief Returns port with shapes for the layer
* @return Port with shapes
*/
const Port& getPort() const;
/**
* @brief Sets port shapes for the layer
* @param port Port with shapes
* @return reference to layer builder
*/
ArgMaxLayer& setPort(const Port& port);
/**
* @brief Returns axis
* @return Axis
*/
int getAxis() const;
/**
* @brief Sets axis
* @param axis Axis
* @return reference to layer builder
*/
ArgMaxLayer& setAxis(int axis);
/**
* @brief Returns top K
* @return Top K
*/
size_t getTopK() const;
/**
* @brief Sets top K
* @param topK Top K
* @return reference to layer builder
*/
ArgMaxLayer& setTopK(size_t topK);
/**
* @brief Returns output maximum value
* @return Output maximum value
*/
size_t getOutMaxVal() const;
/**
* @brief Sets output maximum value
* @param size Maximum value
* @return reference to layer builder
*/
ArgMaxLayer& setOutMaxVal(size_t size);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,81 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for BatchNormalization layer
*/
class INFERENCE_ENGINE_API_CLASS(BatchNormalizationLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit BatchNormalizationLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit BatchNormalizationLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
BatchNormalizationLayer& setName(const std::string& name);
/**
* @brief Returns port with shapes for the layer
* @return Port with shapes
*/
const Port& getPort() const;
/**
* @brief Sets port shapes for the layer
* @param port Port with shapes
* @return reference to layer builder
*/
BatchNormalizationLayer& setPort(const Port &port);
/**
* @brief Sets weights for layer
* @param weights Constant blob with weights
* @return reference to layer builder
*/
BatchNormalizationLayer& setWeights(const Blob::CPtr& weights);
/**
* @brief Sets biases for layer
* @param biases Constant blob with biases
* @return reference to layer builder
*/
BatchNormalizationLayer& setBiases(const Blob::CPtr& biases);
/**
* @brief Returns epsilon
* @return Epsilon
*/
float getEpsilon() const;
/**
* @brief Sets epsilon
* @param eps Epsilon
* @return reference to layer builder
*/
BatchNormalizationLayer& setEpsilon(float eps);
/**
* @brief Validates layer before creation
* @param layer generic layer builder
*/
static void validate(const Layer& layer);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,72 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for Clamp layer
*/
class INFERENCE_ENGINE_API_CLASS(ClampLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit ClampLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit ClampLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
ClampLayer& setName(const std::string& name);
/**
* @brief Returns port with shapes for the layer
* @return Port with shapes
*/
const Port& getPort() const;
/**
* @brief Sets port shapes for the layer
* @param port Port with shapes
* @return reference to layer builder
*/
ClampLayer& setPort(const Port& port);
/**
* @brief Returns minimum value
* @return minimum value
*/
float getMinValue() const;
/**
* @brief Sets minimum value
* @param minValue Minimum value
* @return reference to layer builder
*/
ClampLayer& setMinValue(float minValue);
/**
* @brief Returns maximum value
* @return Maximum value
*/
float getMaxValue() const;
/**
* @brief Sets maximum value
* @param maxValue Maximum value
* @return reference to layer builder
*/
ClampLayer& setMaxValue(float maxValue);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,76 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
#include <vector>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for Concat layer
*/
class INFERENCE_ENGINE_API_CLASS(ConcatLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit ConcatLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit ConcatLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
ConcatLayer& setName(const std::string& name);
/**
* @brief Returns vector with input ports
* @return vector with ports
*/
const std::vector<Port>& getInputPorts() const;
/**
* @brief Sets input ports
* @param ports Vector of input ports
* @return reference to layer builder
*/
ConcatLayer& setInputPorts(const std::vector<Port>& ports);
/**
* @brief Returns output port
* @return Output port
*/
const Port& getOutputPort() const;
/**
* @brief Sets output port
* @param port Output port
* @return reference to layer builder
*/
ConcatLayer& setOutputPort(const Port& port);
/**
* @brief Returns axis
* @return Axis
*/
size_t getAxis() const;
/**
* @brief Sets axis
* @param axis Axis
* @return reference to layer builder
*/
ConcatLayer& setAxis(size_t axis);
private:
size_t axis;
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,57 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for Const layer
*/
class INFERENCE_ENGINE_API_CLASS(ConstLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit ConstLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit ConstLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
ConstLayer& setName(const std::string& name);
/**
* @brief Returns port with shapes for the layer
* @return Port with shapes
*/
const Port& getPort() const;
/**
* @brief Sets port shapes for the layer
* @param port Port with shapes
* @return reference to layer builder
*/
ConstLayer& setPort(const Port& port);
/**
* @brief Sets constant data
* @param data constant blob with data
* @return reference to layer builder
*/
ConstLayer& setData(const Blob::CPtr& data);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,163 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <vector>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for ArgMax layer
*/
class INFERENCE_ENGINE_API_CLASS(ConvolutionLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit ConvolutionLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit ConvolutionLayer(Layer& genLayer);
/**
* @brief Operator creates generic layer builder
* @return Generic layer builder
*/
operator Layer() const override;
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
ConvolutionLayer& setName(const std::string& name);
/**
* @brief Sets weights for layer
* @param weights Constant blob with weights
* @return reference to layer builder
*/
ConvolutionLayer& setWeights(const Blob::CPtr& weights);
/**
* @brief Sets biases for layer
* @param biases Constant blob with biases
* @return reference to layer builder
*/
ConvolutionLayer& setBiases(const Blob::CPtr& biases);
/**
* @brief Returns input port
* @return Input port
*/
const Port& getInputPort() const;
/**
* @brief Sets input port
* @param port Input port
* @return reference to layer builder
*/
ConvolutionLayer& setInputPort(const Port& port);
/**
* @brief Returns output port
* @return Output port
*/
const Port& getOutputPort() const;
/**
* @brief Sets output port
* @param port Output port
* @return reference to layer builder
*/
ConvolutionLayer& setOutputPort(const Port& port);
/**
* @brief Returns kernel size
* @return Kernel size
*/
const std::vector<size_t> getKernel() const;
/**
* @brief Sets kernel size
* @param kernel Kernel size
* @return reference to layer builder
*/
ConvolutionLayer& setKernel(const std::vector<size_t>& kernel);
/**
* @brief Returns vector of strides
* @return vector of strides
*/
const std::vector<size_t> getStrides() const;
/**
* @brief Sets strides
* @param strides vector of strides
* @return reference to layer builder
*/
ConvolutionLayer& setStrides(const std::vector<size_t>& strides);
/**
* @brief Returns dilations
* @return vector of dilations
*/
const std::vector<size_t> getDilation() const;
/**
* @brief Sets dilations
* @param dilation Vector of dilations
* @return reference to layer builder
*/
ConvolutionLayer& setDilation(const std::vector<size_t>& dilation);
/**
* @brief Returns begin paddings
* @return vector of paddings
*/
const std::vector<size_t> getPaddingsBegin() const;
/**
* @brief Sets begin paddings
* @param paddings Vector of paddings
* @return reference to layer builder
*/
ConvolutionLayer& setPaddingsBegin(const std::vector<size_t>& paddings);
/**
* @brief Return end paddings
* @return Vector of paddings
*/
const std::vector<size_t> getPaddingsEnd() const;
/**
* @brief Sets end paddings
* @param paddings Vector of paddings
* @return reference to layer builder
*/
ConvolutionLayer& setPaddingsEnd(const std::vector<size_t>& paddings);
/**
* @brief Returns group
* @return Group
*/
size_t getGroup() const;
/**
* @brief Sets group
* @param group Group
* @return reference to layer builder
*/
ConvolutionLayer& setGroup(size_t group);
/**
* @brief Return output depth
* @return Output depth
*/
size_t getOutDepth() const;
/**
* @brief Sets output depth
* @param outDepth Output depth
* @return reference to layer builder
*/
ConvolutionLayer& setOutDepth(size_t outDepth);
/**
* @brief Validates layer before creation
* @param layer generic layer builder
*/
static void validate(const Layer& layer);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,90 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
#include <vector>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for Crop layer
*/
class INFERENCE_ENGINE_API_CLASS(CropLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit CropLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit CropLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
CropLayer& setName(const std::string& name);
/**
* @brief Returns input ports
* @return Vector of input ports
*/
const std::vector<Port>& getInputPorts() const;
/**
* @brief Sets input ports
* @param port Vector of input ports
* @return reference to layer builder
*/
CropLayer& setInputPorts(const std::vector<Port>& ports);
/**
* @brief Return output port
* @return Output port
*/
const Port& getOutputPort() const;
/**
* @brief Sets output port
* @param port Output port
* @return reference to layer builder
*/
CropLayer& setOutputPort(const Port& port);
/**
* @brief Returns axis
* @return Vector of axis
*/
const std::vector<size_t> getAxis() const;
/**
* @brief Sets axis
* @param axis Vector of axis
* @return reference to layer builder
*/
CropLayer& setAxis(const std::vector<size_t>& axis);
/**
* @brief Returns offsets
* @return Vector of offsets
*/
const std::vector<size_t> getOffset() const;
/**
* @brief Sets offsets
* @param offsets Vector of offsets
* @return reference to layer builder
*/
CropLayer& setOffset(const std::vector<size_t>& offsets);
/**
* @brief Validates layer before creation
* @param layer generic layer builder
*/
static void validate(const Layer& layer);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,74 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
#include <vector>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for CTCGreedyDecoder layer
*/
class INFERENCE_ENGINE_API_CLASS(CTCGreedyDecoderLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit CTCGreedyDecoderLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit CTCGreedyDecoderLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
CTCGreedyDecoderLayer& setName(const std::string& name);
/**
* @brief Returns input ports
* @return Vector of input ports
*/
const std::vector<Port>& getInputPorts() const;
/**
* @brief Sets input ports
* @param ports Vector of input ports
* @return reference to layer builder
*/
CTCGreedyDecoderLayer& setInputPorts(const std::vector<Port>& ports);
/**
* @brief Returns output port
* @return Output port
*/
const Port& getOutputPort() const;
/**
* @brief Sets output port
* @param port Output port
* @return reference to layer builder
*/
CTCGreedyDecoderLayer& setOutputPort(const Port& port);
/**
* @brief Returns CTCMergeRepeated
* @return true if merge repeated
*/
bool getCTCMergeRepeated() const;
/**
* @brief Sets CTCMergeRepeated
* @param flag bool value
* @return reference to layer builder
*/
CTCGreedyDecoderLayer& setCTCMergeRepeated(bool flag);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,32 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_convolution_layer.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for Deconvolution layer
*/
class INFERENCE_ENGINE_API_CLASS(DeconvolutionLayer): public ConvolutionLayer {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit DeconvolutionLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit DeconvolutionLayer(Layer& genLayer);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,183 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
#include <vector>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for ArgMax layer
*/
class INFERENCE_ENGINE_API_CLASS(DetectionOutputLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit DetectionOutputLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit DetectionOutputLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
DetectionOutputLayer& setName(const std::string& name);
/**
* @brief Returns output port
* @return Output port
*/
const Port& getOutputPort() const;
/**
* @brief Sets output port
* @param port Output port
* @return reference to layer builder
*/
DetectionOutputLayer& setOutputPort(const Port& port);
/**
* @brief Returns input ports
* @return Vector of input ports
*/
const std::vector<Port>& getInputPorts() const;
/**
* @brief Sets input ports
* @param ports Vector of input ports
* @return reference to layer builder
*/
DetectionOutputLayer& setInputPorts(const std::vector<Port>& ports);
/**
* @brief Returns number of classes
* @return Number of classes
*/
size_t getNumClasses() const;
/**
* @brief Sets number of classes to be predict
* @param num Number of classes
* @return reference to layer builder
*/
DetectionOutputLayer& setNumClasses(size_t num);
/**
* @brief Returns background label ID
* @return Background ID
*/
int getBackgroudLabelId() const;
/**
* @brief Sets background label ID
* @param labelId Background ID if there is no background class, set it to -1.
* @return reference to layer builder
*/
DetectionOutputLayer& setBackgroudLabelId(int labelId);
/**
* @brief Returns maximum number of results to be kept on NMS stage
* @return Top K
*/
int getTopK() const;
/**
* @brief Sets maximum number of results to be kept on NMS stage
* @param topK Top K
* @return reference to layer builder
*/
DetectionOutputLayer& setTopK(int topK);
/**
* @brief Returns number of total boxes to be kept per image after NMS step
* @return Keep top K
*/
int getKeepTopK() const;
/**
* @brief Sets number of total boxes to be kept per image after NMS step
* @param topK Keep top K
* @return reference to layer builder
*/
DetectionOutputLayer& setKeepTopK(int topK);
/**
* @brief Returns number of oriented classes
* @return Number of oriented classes
*/
int getNumOrientClasses() const;
/**
* @brief Sets number of oriented classes
* @param numClasses Number of classes
* @return reference to layer builder
*/
DetectionOutputLayer& setNumOrientClasses(int numClasses);
/**
* @brief Returns type of coding method for bounding boxes
* @return String with code type
*/
std::string getCodeType() const;
/**
* @brief Sets type of coding method for bounding boxes
* @param type Type
* @return reference to layer builder
*/
DetectionOutputLayer& setCodeType(std::string type);
/**
* @brief Returns interpolate orientation
* @return Interpolate orientation
*/
int getInterpolateOrientation() const;
/**
* @brief Sets interpolate orientation
* @param orient Orientation
* @return reference to layer builder
*/
DetectionOutputLayer& setInterpolateOrientation(int orient);
/**
* @brief Returns threshold to be used in NMS stage
* @return Threshold
*/
float getNMSThreshold() const;
/**
* @brief Sets threshold to be used in NMS stage
* @param threshold NMS threshold
* @return reference to layer builder
*/
DetectionOutputLayer& setNMSThreshold(float threshold);
/**
* @brief Returns confidence threshold
* @return Threshold
*/
float getConfidenceThreshold() const;
/**
* @brief Sets confidence threshold
* @param threshold Threshold
* @return reference to layer builder
*/
DetectionOutputLayer& setConfidenceThreshold(float threshold);
/**
* @brief Returns share location
* @return true if bounding boxes are shared among different classes
*/
bool getShareLocation() const;
/**
* @brief Sets share location
* @param flag true if bounding boxes are shared among different classes
* @return reference to layer builder
*/
DetectionOutputLayer& setShareLocation(bool flag);
/**
* @brief Returns encoded settings
* @return true if variance is encoded in target
*/
bool getVariantEncodedInTarget() const;
/**
* @brief Sets encoded settings
* @param flag true if variance is encoded in target
* @return reference to layer builder
*/
DetectionOutputLayer& setVariantEncodedInTarget(bool flag);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,96 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
#include <vector>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for Eltwise layer
*/
class INFERENCE_ENGINE_API_CLASS(EltwiseLayer): public LayerFragment {
public:
/**
* @brief The enum defines all Eltwise types
*/
enum EltwiseType {
SUM = 1,
MAX,
MUL
};
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit EltwiseLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit EltwiseLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
EltwiseLayer& setName(const std::string& name);
/**
* @brief Returns input ports
* @return Vector of input ports
*/
const std::vector<Port>& getInputPorts() const;
/**
* @brief Sets input ports
* @param ports Vector of input ports
* @return reference to layer builder
*/
EltwiseLayer& setInputPorts(const std::vector<Port>& ports);
/**
* @brief Returns output port
* @return Output port
*/
const Port& getOutputPort() const;
/**
* @brief Sets output port
* @param port Output port
* @return reference to layer builder
*/
EltwiseLayer& setOutputPort(const Port& port);
/**
* @brief Returns eltwise type
* @return Eltwise type
*/
EltwiseType getEltwiseType() const;
/**
* @brief Sets eltwise type
* @param type Eltwise type
* @return reference to layer builder
*/
EltwiseLayer& setEltwiseType(EltwiseType type);
/**
* @brief Returns eltwise scales
* @return Vector of scales
*/
const std::vector<float> getScales() const;
/**
* @brief Sets eltwise scales
* @param scales Vector of scales
* @return reference to layer builder
*/
EltwiseLayer& setScales(const std::vector<float>& scales);
private:
EltwiseType type;
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,62 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for ELU layer
*/
class INFERENCE_ENGINE_API_CLASS(ELULayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit ELULayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit ELULayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
ELULayer& setName(const std::string& name);
/**
* @brief Returns port with shapes for the layer
* @return Port with shapes
*/
const Port& getPort() const;
/**
* @brief Sets port shapes for the layer
* @param port Port with shapes
* @return reference to layer builder
*/
ELULayer& setPort(const Port& port);
/**
* @brief Returns alpha
* @return alpha
*/
float getAlpha() const;
/**
* @brief Sets alpha
* @param alpha Alpha
* @return reference to layer builder
*/
ELULayer& setAlpha(float alpha);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,85 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for FullyConnected layer
*/
class INFERENCE_ENGINE_API_CLASS(FullyConnectedLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit FullyConnectedLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit FullyConnectedLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
FullyConnectedLayer& setName(const std::string& name);
/**
* @brief Sets weights for layer
* @param weights Constant blob with weights
* @return reference to layer builder
*/
FullyConnectedLayer& setWeights(const Blob::CPtr& weights);
/**
* @brief Sets biases for layer
* @param biases Constant blob with biases
* @return reference to layer builder
*/
FullyConnectedLayer& setBiases(const Blob::CPtr& biases);
/**
* @brief Returns input port
* @return Input port
*/
const Port& getInputPort() const;
/**
* @brief Sets input port
* @param port Input port
* @return reference to layer builder
*/
FullyConnectedLayer& setInputPort(const Port& port);
/**
* @brief Returns output port
* @return Output port
*/
const Port& getOutputPort() const;
/**
* @brief Sets output port
* @param port Output port
* @return reference to layer builder
*/
FullyConnectedLayer& setOutputPort(const Port& port);
/**
* @brief Return output size
* @return Output size
*/
size_t getOutputNum() const;
/**
* @brief Sets output size
* @param outNum Output size
* @return reference to layer builder
*/
FullyConnectedLayer& setOutputNum(size_t outNum);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,61 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for ArgMax layer
*/
class INFERENCE_ENGINE_API_CLASS(GRNLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit GRNLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit GRNLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
GRNLayer& setName(const std::string& name);
/**
* @brief Returns port with shapes for the layer
* @return Port with shapes
*/
const Port& getPort() const;
/**
* @brief Sets port shapes for the layer
* @param port Port with shapes
* @return reference to layer builder
*/
GRNLayer& setPort(const Port& port);
/**
* @brief Returns beta
* @return Beta
*/
float getBeta() const;
/**
* @brief Sets beta
* @param beta Beta
* @return reference to layer builder
*/
GRNLayer& setBeta(float beta);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,56 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for Input layer
*/
class INFERENCE_ENGINE_API_CLASS(InputLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit InputLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit InputLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
InputLayer& setName(const std::string& name);
/**
* @brief Returns port with shapes for the layer
* @return Port with shapes
*/
const Port& getPort() const;
/**
* @brief Sets port shapes for the layer
* @param port Port with shapes
* @return reference to layer builder
*/
InputLayer& setPort(const Port &port);
/**
* @brief Validates layer before creation
* @param layer generic layer builder
*/
static void validate(const Layer& layer);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,247 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <details/caseless.hpp>
#include <ie_parameter.hpp>
#include <ie_inetwork.hpp>
#include <ie_blob.h>
#include <string>
#include <vector>
#include <memory>
#include <map>
namespace InferenceEngine {
namespace Builder {
class Layer;
/**
* @brief This structure implements a holder for validators
*/
struct ValidatorsHolder {
/**
* @brief Caseless map connects type with validator
*/
details::caseless_map<std::string, std::function<void(const Layer&)>> validators;
};
/**
* @brief This class implements a builder for IE Layer
*/
class INFERENCE_ENGINE_API_CLASS(Layer) {
public:
/**
* @brief The constructor creates a Layer builder with layer type and layer name
* @param type Layer type
* @param name Layer name
*/
explicit Layer(const std::string& type, const std::string& name = "");
/**
* @brief The constructor creates a Layer builder from shared pointer to ILayer
* @param layer shared pointer to ILayer
*/
explicit Layer(const ILayer::Ptr& layer);
/**
* @brief The constructor creates a Layer builder from shared pointer to constant ILayer
* @param layer shared pointer to constant ILayer
*/
explicit Layer(const ILayer::CPtr& layer);
/**
* @brief The constructor creates a Layer builder with layer ID and layer builder
* @param id Layer ID
* @param layer layer builder
*/
Layer(idx_t id, const Layer& layer);
/**
* @brief Returns layer builder ID
* @return ID
*/
idx_t getId() const;
/**
* @brief Returns a reference to layer type
* @return Layer type
*/
std::string& getType();
/**
* @brief Returns a reference to constant layer type
* @return constant layer type
*/
const std::string& getType() const;
/**
* @brief Sets layer type
* @param type Layer type
* @return Reference to Layer builder
*/
Layer& setType(const std::string& type);
/**
* @brief Returns a reference to layer name
* @return Layer name
*/
std::string& getName();
/**
* @brief Returns a reference to constant layer name
* @return constant layer name
*/
const std::string& getName() const;
/**
* @brief Sets layer name
* @param name Layer name
* @return Reference to Layer builder
*/
Layer& setName(const std::string& name);
/**
* @brief Returns layer subgraph
* @return shared pointer to INetwork
*/
INetwork::Ptr& getGraph();
/**
* @brief Returns constant layer subgraph
* @return constant shared pointer to INetwork
*/
const INetwork::Ptr& getGraph() const;
/**
* @brief Sets layer subgraph
* @param graph constant shared pointer to INetwork
* @return Reference to Layer builder
*/
Layer& setGraph(const INetwork::Ptr& graph);
/**
* @brief Returns map of parameters
* @return map of parameters
*/
std::map<std::string, Parameter>& getParameters();
/**
* @brief Returns constant map of parameters
* @return constant map of parameters
*/
const std::map<std::string, Parameter>& getParameters() const;
/**
* @brief Sets parameters for layer
* @param params constant map of parameters
* @return Reference to Layer builder
*/
Layer& setParameters(const std::map<std::string, Parameter>& params);
/**
* @brief Returns map of internal blobs
* @return map of internal blobs
*/
std::map<std::string, Blob::CPtr>& getConstantData();
/**
* @brief Returns constant map of internal blobs
* @return constant map of internal blobs
*/
const std::map<std::string, Blob::CPtr>& getConstantData() const;
/**
* @brief Sets constant data for layer
* @param constData constant map of shared pointers to blobs
* @return Reference to Layer builder
*/
Layer& setConstantData(const std::map<std::string, Blob::Ptr>& constData);
/**
* @brief Sets constant data for layer
* @param constData constant map of shared pointers to constant blobs
* @return Reference to Layer builder
*/
Layer& setConstantData(const std::map<std::string, Blob::CPtr>& constData);
/**
* @brief Adds constant data for layer by name
* @param name Name of constant data
* @param data shared pointer to constant blob
* @return Reference to Layer builder
*/
Layer& addConstantData(const std::string& name, const Blob::CPtr& data);
/**
* @brief Returns vector of input ports
* @return Vector of input ports
*/
std::vector<Port>& getInputPorts();
/**
* @brief Returns constant vector of input ports
* @return constant vector of input ports
*/
const std::vector<Port>& getInputPorts() const;
/**
* @brief Sets input ports
* @param ports vector of ports
* @return Reference to Layer builder
*/
Layer& setInputPorts(const std::vector<Port> &ports);
/**
* @brief Returns vector of output ports
* @return Vector of output ports
*/
std::vector<Port>& getOutputPorts();
/**
* @brief Returns constant vector of output ports
* @return constant vector of output ports
*/
const std::vector<Port>& getOutputPorts() const;
/**
* @brief Sets output ports
* @param ports vector of ports
* @return Reference to Layer builder
*/
Layer& setOutputPorts(const std::vector<Port> &ports);
/**
* @brief Validates the current builder and generates ILayer object
* @return constant shared pointer to ILayer
*/
const ILayer::Ptr build() const;
/**
* @brief Validates layer builder
*/
void validate() const;
/**
* @brief Registers a new validator for type
* @param type Layer type
* @param validator Layer validator
*/
static void addValidator(const std::string& type, const std::function<void(const Layer&)>& validator);
private:
idx_t id;
std::string type;
std::string name;
INetwork::Ptr graph;
std::vector<Port> inPorts;
std::vector<Port> outPorts;
std::map<std::string, Parameter> params;
std::map<std::string, Blob::CPtr> constData;
static std::shared_ptr<ValidatorsHolder> getValidatorsHolder();
};
/**
* @brief This class registers layer validators
*/
class ValidatorRegisterBase {
public:
/**
* @brief The constructor registers new layer validator
* @param type Layer type
* @param validator Layer validator
*/
explicit ValidatorRegisterBase(const std::string& type, const std::function<void(const Layer&)>& validator) {
InferenceEngine::Builder::Layer::addValidator(type, validator);
}
};
#define REG_VALIDATOR_FOR(__type, __validator) \
static InferenceEngine::Builder::ValidatorRegisterBase _reg_##__type(#__type, __validator)
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,76 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_builder.hpp>
#include <string>
#include <vector>
namespace InferenceEngine {
namespace Builder {
/**
* @brief This class defines the basic functional for layer builders
*/
class INFERENCE_ENGINE_API_CLASS(LayerFragment) {
public:
/**
* @brief The constructor creates layer builders with layer type and layer name
* @param type Layer type
* @param name Layer name
*/
LayerFragment(const std::string& type, const std::string& name);
/**
* @brief The constructor creates layer builders from reference to generic layer builder
* @param genLayer Generic layer builder
*/
explicit LayerFragment(Layer& genLayer);
/**
* @brief The copy constructor
* @param rval Source builder
*/
explicit LayerFragment(const LayerFragment& rval);
/**
* @brief Copy operator for LayerFragment
* @param rval
* @return Layer builder
*/
LayerFragment& operator=(const LayerFragment& rval);
/**
* @brief Virtual destructor
*/
virtual ~LayerFragment() = default;
/**
* @brief The operator creates generic builder
* @return Generic builder
*/
virtual operator Layer() const;
/**
* @brief Returns layer type
* @return Layer type
*/
const std::string& getType() const;
/**
* @brief Returns layer name
* @return Layer name
*/
const std::string& getName() const;
protected:
const std::vector<size_t> uInts2size_t(const std::vector<unsigned int>& vector) const;
Layer& getLayer() const;
private:
Layer layer;
Layer& refLayer;
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,94 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for Memory layer
*/
class INFERENCE_ENGINE_API_CLASS(MemoryLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit MemoryLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit MemoryLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
MemoryLayer& setName(const std::string& name);
/**
* @brief Returns output port
* @return Output port
*/
const Port& getOutputPort() const;
/**
* @brief Sets output port
* @param port Output port
* @return reference to layer builder
*/
MemoryLayer& setOutputPort(const Port& port);
/**
* @brief Returns input port
* @return Input port
*/
const Port& getInputPort() const;
/**
* @brief Sets input port
* @param port Input port
* @return reference to layer builder
*/
MemoryLayer& setInputPort(const Port& port);
/**
* @brief Returns memory ID
* @return String with memory ID
*/
const std::string getId() const;
/**
* @brief Sets memory ID
* @param id Memory ID
* @return reference to layer builder
*/
MemoryLayer& setId(const std::string& id);
/**
* @brief Returns the index of memory layer
* @return Index
*/
size_t getIndex() const;
/**
* @brief Sets the index of memory layer
* @param index Index equal 0 means this layer is output one.
* @return reference to layer builder
*/
MemoryLayer& setIndex(size_t index);
/**
* @brief Returns size of the group
* @return Size of the group
*/
size_t getSize() const;
/**
* @brief Sets size of the group
* @param size Size if size equals 2 means this group is a pair (only 2 is supported).
* @return reference to layer builder
*/
MemoryLayer& setSize(size_t size);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,83 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for MVN layer
*/
class INFERENCE_ENGINE_API_CLASS(MVNLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit MVNLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit MVNLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
MVNLayer& setName(const std::string& name);
/**
* @brief Returns port with shapes for the layer
* @return Port with shapes
*/
const Port& getPort() const;
/**
* @brief Sets port shapes for the layer
* @param port Port with shapes
* @return reference to layer builder
*/
MVNLayer& setPort(const Port& port);
/**
* @brief Returns across channels value
* @return true if mean values are shared across channels
*/
bool getAcrossChannels() const;
/**
* @brief Sets across channels
* @param flag true if mean values are shared across channels
* @return reference to layer builder
*/
MVNLayer& setAcrossChannels(bool flag);
/**
* @brief Returns normalize variance
* @return true if variance normalization is performed
*/
bool getNormalize() const;
/**
* @brief Sets normalize variance
* @param flag true if variance normalization is performed
* @return reference to layer builder
*/
MVNLayer& setNormalize(bool flag);
/**
* @brief Return epsilon
* @return Epsilon
*/
float getEpsilon() const;
/**
* @brief Sets epsilon
* @param eps Epsilon
* @return reference to layer builder
*/
MVNLayer& setEpsilon(float eps);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,185 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_builder.hpp>
#include <ie_icnn_network.hpp>
#include <cpp/ie_cnn_network.h>
#include <ie_inetwork.hpp>
#include <ie_context.hpp>
#include <ie_common.h>
#include <ie_blob.h>
#include <utility>
#include <memory>
#include <string>
#include <vector>
#include <map>
namespace InferenceEngine {
namespace Builder {
/**
* @brief This class implements a builder for IE Network
*/
class INFERENCE_ENGINE_API_CLASS(Network) {
public:
/**
* @brief A shared pointer to the Network builder
*/
using Ptr = std::shared_ptr<Network>;
/**
* @brief The constructor creates a builder based on ICNNNetwork
*
* @param network constant reference to ICNNNetwork object
*/
explicit Network(const ICNNNetwork& network);
/**
* @brief The constructor creates a empty builder with network name
*
* @param name Network name
*/
explicit Network(const std::string& name);
/**
* @brief The constructor creates a builder based on INetwork
*
* @param network constant reference to INetwork object
*/
explicit Network(const INetwork& network);
/**
* @brief The constructor creates a builder based on ICNNNetwork with custom Context
*
* @param network constant reference to ICNNNetwork object
*/
Network(const Context& ieContext, const ICNNNetwork& network);
/**
* @brief The constructor creates a empty builder with network name and custom Context
*
* @param name Network name
*/
Network(const Context& ieContext, const std::string& name);
/**
* @brief The constructor creates a builder based on INetwork with custom Context
*
* @param network constant reference to INetwork object
*/
Network(const Context& ieContext, const INetwork& network);
/**
* @brief Virtual destructor
*/
virtual ~Network() = default;
/**
* @brief Adds new layer and connects it with previous layers
*
* @param inputs Vector with PortInfo objects from previous layers
* @param layer Layer builder for new layer
*
* @return Id of new builder for the current network
*/
idx_t addLayer(const std::vector<PortInfo>& inputs, const Layer& layer);
/**
* @brief Adds new layer
*
* @param layer Layer builder for new layer
*
* @return Id of new builder for the current network
*/
idx_t addLayer(const Layer& layer);
/**
* @brief Removes a layer by ID
*
* @param layerId Layer ID
*/
void removeLayer(idx_t layerId);
/**
* @brief Connects two layers
*
* @param input PortInfo object from previous layer
* @param output PortInfo object from next layer
*/
void connect(const PortInfo& input, const PortInfo& output);
/**
* @brief Removes connection from the network
*
* @param connection Connection
*/
void disconnect(const Connection& connection);
/**
* @brief Returns layer builder by ID
*
* @param layerId Layer ID
*
* @return Layer buider
*/
Layer& getLayer(idx_t layerId);
/**
* @brief Returns constant layer builder by ID
*
* @param layerId Layer ID
*
* @return constant layer builder
*/
const Layer& getLayer(idx_t layerId) const;
/**
* @brief Returns vector of layer builders
*
* @return Vector of layer builders
*/
std::vector<Layer>& getLayers();
/**
* @brief Returns constant vector of layer builders
*
* @return constant vector of layer builders
*/
const std::vector<Layer>& getLayers() const;
/**
* @brief Returns all connections for layer
*
* @param layerId Layer ID
*
* @return Vector of connections for the current layer
*/
const std::vector<Connection> getLayerConnections(idx_t layerId) const noexcept;
/**
* @brief Builds and validate networks
*
* @return const shared pointer to INetwork
*/
const INetwork::Ptr build() const;
/**
* @brief The operator builds network
*
* @return const shared pointer to INetwork
*/
explicit operator const INetwork::Ptr() const;
private:
const Context ctx;
const size_t version;
std::string name;
std::vector<Layer> layers;
std::vector<Connection> connections;
};
/**
* @brief This function converts INetwork to ICNNNetwork
*
* @param network constant shared pointer to INetwork object
* @return constant shared pointer to ICNNNetwork
*/
INFERENCE_ENGINE_API_CPP(const std::shared_ptr<ICNNNetwork>) convertToICNNNetwork(const INetwork::Ptr& network);
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,112 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for Norm layer
*/
class INFERENCE_ENGINE_API_CLASS(NormLayer): public LayerFragment {
public:
/**
* @brief The enum defines all Norm types
*/
enum NormType {
WITHIN_CHANNEL = 0,
ACROSS_CHANNELS = 1
};
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit NormLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit NormLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
NormLayer& setName(const std::string& name);
/**
* @brief Returns port with shapes for the layer
* @return Port with shapes
*/
const Port& getPort() const;
/**
* @brief Sets port shapes for the layer
* @param port Port with shapes
* @return reference to layer builder
*/
NormLayer& setPort(const Port& port);
/**
* @brief Returns side length of the region
* @return Size
*/
size_t getSize() const;
/**
* @brief Sets side length of the region
* @param size Size
* @return reference to layer builder
*/
NormLayer& setSize(size_t size);
/**
* @brief Returns scaling parameter for the normalizing sum
* @return Scaling parameter
*/
float getAlpha() const;
/**
* @brief Sets scaling parameter for the normalizing sum
* @param alpha Scaling parameter
* @return reference to layer builder
*/
NormLayer& setAlpha(float alpha);
/**
* @brief Returns exponent for the normalizing sum
* @return Exponent
*/
float getBeta() const;
/**
* @brief Sets exponent for the normalizing sum
* @param beta Exponent
* @return reference to layer builder
*/
NormLayer& setBeta(float beta);
/**
* @brief Returns region type
* @return true if normalizing sum is performed over adjacent channels
*/
bool getAcrossMaps() const;
/**
* @brief Sets region type
* @param acrossMap true if normalizing sum is performed over adjacent channels
* @return reference to layer builder
*/
NormLayer& setAcrossMaps(bool acrossMap);
/**
* @brief Returns region type
* @return Norm type
*/
NormType getRegion() const;
/**
* @brief Sets region type
* @param type region type
* @return reference to layer builder
*/
NormLayer& setRegion(NormType type);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,85 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for Normalize layer
*/
class INFERENCE_ENGINE_API_CLASS(NormalizeLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit NormalizeLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit NormalizeLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
NormalizeLayer& setName(const std::string& name);
/**
* @brief Returns port with shapes for the layer
* @return Port with shapes
*/
const Port& getPort() const;
/**
* @brief Sets port shapes for the layer
* @param port Port with shapes
* @return reference to layer builder
*/
NormalizeLayer& setPort(const Port& port);
/**
* @brief Returns channel shared flag
* @return true if scale parameters are shared across channels
*/
bool getChannelShared() const;
/**
* @brief Sets channel shared flag
* @param acrossMap true if scale parameters are shared across channels
* @return reference to layer builder
*/
NormalizeLayer& setChannelShared(bool acrossMap);
/**
* @brief Returns across maps
* @return true if normalization is shared across channels
*/
bool getAcrossMaps() const;
/**
* @brief Sets across map
* @param acrossMap true if normalization is shared across channels
* @return reference to layer builder
*/
NormalizeLayer& setAcrossMaps(bool acrossMap);
/**
* @brief Returns epsilon
* @return Epsilon
*/
float getEpsilon() const;
/**
* @brief Sets epsilon
* @param eps Epsilon
* @return reference to layer builder
*/
NormalizeLayer& setEpsilon(float eps);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,50 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for Output layer
*/
class INFERENCE_ENGINE_API_CLASS(OutputLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit OutputLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit OutputLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
OutputLayer& setName(const std::string& name);
/**
* @brief Returns port with shapes for the layer
* @return Port with shapes
*/
const Port& getPort() const;
/**
* @brief Sets port shapes for the layer
* @param port Port with shapes
* @return reference to layer builder
*/
OutputLayer& setPort(const Port &port);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,86 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <vector>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for Permute layer
*/
class INFERENCE_ENGINE_API_CLASS(PermuteLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit PermuteLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit PermuteLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
PermuteLayer& setName(const std::string& name);
/**
* @brief Sets weights for layer
* @param weights Constant blob with weights
* @return reference to layer builder
*/
PermuteLayer& setWeights(const Blob::CPtr& weights);
/**
* @brief Sets biases for layer
* @param biases Constant blob with biases
* @return reference to layer builder
*/
PermuteLayer& setBiases(const Blob::CPtr& biases);
/**
* @brief Returns input port
* @return Input port
*/
const Port& getInputPort() const;
/**
* @brief Sets input port
* @param port Input port
* @return reference to layer builder
*/
PermuteLayer& setInputPort(const Port& port);
/**
* @brief Returns output port
* @return Output port
*/
const Port& getOutputPort() const;
/**
* @brief Sets output port
* @param port Output port
* @return reference to layer builder
*/
PermuteLayer& setOutputPort(const Port& port);
/**
* @brief Return vector of dimensions indexes for output blob
* @return Order of dimensions for output blob
*/
const std::vector<size_t> getOrder() const;
/**
* @brief Sets the order of dimensions for output blob
* @param order dimensions indexes for output blob
* @return reference to layer builder
*/
PermuteLayer& setOrder(const std::vector<size_t>& order);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,170 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <vector>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for Pooling layer
*/
class INFERENCE_ENGINE_API_CLASS(PoolingLayer): public LayerFragment {
public:
/**
* @brief The enum defines available pooling types
*/
enum PoolingType {
MAX = 1,
AVG = 2
};
/**
* @brief The enum defines available rounding types
*/
enum RoundingType {
CEIL = 1,
FLOOR = 2
};
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit PoolingLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit PoolingLayer(Layer& genLayer);
/**
* @brief Operator creates generic layer builder
* @return Generic layer builder
*/
operator Layer() const override;
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
PoolingLayer& setName(const std::string& name);
/**
* @brief Returns input port
* @return Input port
*/
const Port& getInputPort() const;
/**
* @brief Sets input port
* @param port Input port
* @return reference to layer builder
*/
PoolingLayer& setInputPort(const Port& port);
/**
* @brief Returns output port
* @return Output port
*/
const Port& getOutputPort() const;
/**
* @brief Sets output port
* @param port Output port
* @return reference to layer builder
*/
PoolingLayer& setOutputPort(const Port& port);
/**
* @brief Returns kernel size
* @return Kernel size
*/
const std::vector<size_t> getKernel() const;
/**
* @brief Sets kernel size
* @param kernel Kernel size
* @return reference to layer builder
*/
PoolingLayer& setKernel(const std::vector<size_t>& kernel);
/**
* @brief Returns vector of strides
* @return vector of strides
*/
const std::vector<size_t> getStrides() const;
/**
* @brief Sets strides
* @param strides vector of strides
* @return reference to layer builder
*/
PoolingLayer& setStrides(const std::vector<size_t>& strides);
/**
* @brief Returns begin paddings
* @return vector of paddings
*/
const std::vector<size_t> getPaddingsBegin() const;
/**
* @brief Sets begin paddings
* @param paddings Vector of paddings
* @return reference to layer builder
*/
PoolingLayer& setPaddingsBegin(const std::vector<size_t>& paddings);
/**
* @brief Return end paddings
* @return Vector of paddings
*/
const std::vector<size_t> getPaddingsEnd() const;
/**
* @brief Sets end paddings
* @param paddings Vector of paddings
* @return reference to layer builder
*/
PoolingLayer& setPaddingsEnd(const std::vector<size_t>& paddings);
/**
* @brief Returns pooling type
* @return Pooling type
*/
PoolingType getPoolingType() const;
/**
* @brief Sets pooling type
* @param type Pooling type
* @return reference to layer builder
*/
PoolingLayer& setPoolingType(PoolingType type);
/**
* @brief Returns rounding type
* @return Rounding type
*/
RoundingType getRoundingType() const;
/**
* @brief Sets rounding types
* @param type Rounding type
* @return reference to layer builder
*/
PoolingLayer& setRoundingType(RoundingType type);
/**
* @brief Returns a type of pooling strategy
* @return true if zero-values in the padding are not used
*/
bool getExcludePad() const;
/**
* @brief Sets a type of pooling strategy
* @param exclude zero-values in the padding are not used if true
* @return reference to layer builder
*/
PoolingLayer& setExcludePad(bool exclude);
/**
* @brief Validates layer before creation
* @param layer generic layer builder
*/
static void validate(const Layer& layer);
private:
PoolingType type;
RoundingType roundingType;
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,83 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for Power layer
*/
class INFERENCE_ENGINE_API_CLASS(PowerLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit PowerLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit PowerLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
PowerLayer& setName(const std::string& name);
/**
* @brief Returns port with shapes for the layer
* @return Port with shapes
*/
const Port& getPort() const;
/**
* @brief Sets port shapes for the layer
* @param port Port with shapes
* @return reference to layer builder
*/
PowerLayer& setPort(const Port& port);
/**
* @brief Returns power
* @return Power parameter
*/
float getPower() const;
/**
* @brief Sets the power parameter
* @param power Power parameter
* @return reference to layer builder
*/
PowerLayer& setPower(float power);
/**
* @brief Returns scaling parameter
* @return Scaling
*/
float getScale() const;
/**
* @brief Sets scaling parameter
* @param scale Scaling parameter
* @return reference to layer builder
*/
PowerLayer& setScale(float scale);
/**
* @brief Returns shifting parameter
* @return Shift
*/
float getShift() const;
/**
* @brief Sets shift for the layer
* @param shift Shifting parameter
* @return reference to layer builder
*/
PowerLayer& setShift(float shift);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,67 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for PReLU layer
*/
class INFERENCE_ENGINE_API_CLASS(PReLULayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit PReLULayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit PReLULayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
PReLULayer& setName(const std::string& name);
/**
* @brief Sets weights for layer
* @param weights Constant blob with weights
* @return reference to layer builder
*/
PReLULayer& setWeights(const Blob::CPtr& weights);
/**
* @brief Returns port with shapes for the layer
* @return Port with shapes
*/
const Port& getPort() const;
/**
* @brief Sets port shapes for the layer
* @param port Port with shapes
* @return reference to layer builder
*/
PReLULayer& setPort(const Port& port);
/**
* @brief Returns channel shared flag
* @return true if negative slope shared across channels
*/
bool getChannelShared() const;
/**
* @brief Sets channel shared flag
* @param flag true if negative slope shared across channels
* @return reference to layer builder
*/
PReLULayer& setChannelShared(bool flag);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,161 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
#include <vector>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for PriorBoxClustered layer
*/
class INFERENCE_ENGINE_API_CLASS(PriorBoxClusteredLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit PriorBoxClusteredLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit PriorBoxClusteredLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
PriorBoxClusteredLayer& setName(const std::string& name);
/**
* @brief Returns output port
* @return Output port
*/
const Port& getOutputPort() const;
/**
* @brief Sets output port
* @param port Output port
* @return reference to layer builder
*/
PriorBoxClusteredLayer& setOutputPort(const Port& port);
/**
* @brief Returns input ports
* @return Vector of input ports
*/
const std::vector<Port>& getInputPorts() const;
/**
* @brief Sets input ports
* @param port Vector of input ports
* @return reference to layer builder
*/
PriorBoxClusteredLayer& setInputPorts(const std::vector<Port>& port);
/**
* @brief Returns height and width of input image
* @return input image sizes
*/
const std::vector<float> getImgSizes() const;
/**
* @brief Sets height and width sizes
* @param sizes Height and width sizes
* @return reference to layer builder
*/
PriorBoxClusteredLayer& setImgSizes(const std::vector<float> sizes);
/**
* @brief returns distances between (height and width) box centers
* @return distances
*/
const std::vector<float> getSteps() const;
/**
* @brief Sets distances between box centers for height and width
* @param steps Distances between box centers
* @return reference to layer builder
*/
PriorBoxClusteredLayer& setSteps(const std::vector<float> steps);
/**
* @brief returns a distance between box centers
* @return distance
*/
float getStep() const;
/**
* @brief Sets a distance between box centers
* @param steps A distance between box centers
* @return reference to layer builder
*/
PriorBoxClusteredLayer& setStep(float step);
/**
* @brief Returns shift of box respectively to top left corner
* @return Shift
*/
float getOffset() const;
/**
* @brief Sets shift of box respectively to top left corner
* @param offset Shift
* @return reference to layer builder
*/
PriorBoxClusteredLayer& setOffset(float offset);
/**
* @brief Returns a variance of adjusting bounding boxes
* @return Variance
*/
float getVariance() const;
/**
* @brief Sets a variance of adjusting bounding boxes
* @param variance Variance
* @return reference to layer builder
*/
PriorBoxClusteredLayer& setVariance(float variance);
/**
* @brief Returns desired boxes width in pixels
* @return width of desired boxes
*/
float getWidth() const;
/**
* @brief Sets desired boxes width in pixels
* @param width Width of desired boxes
* @return reference to layer builder
*/
PriorBoxClusteredLayer& setWidth(float width);
/**
* @brief Returns desired boxes height in pixels
* @return height of desired boxes
*/
float getHeight() const;
/**
* @brief Sets desired boxes height in pixels
* @param height Height of desired boxes
* @return reference to layer builder
*/
PriorBoxClusteredLayer& setHeight(float height);
/**
* @brief Returns clip flag
* @return true if each value in the output blob is within [0,1]
*/
bool getClip() const;
/**
* @brief sets clip flag
* @param flag true if each value in the output blob is within [0,1]
* @return reference to layer builder
*/
PriorBoxClusteredLayer& setClip(bool flag);
/**
* @brief Returns flip flag
* @return list of boxes is augmented with the flipped ones if true
*/
bool getFlip() const;
/**
* @brief Sets flip flag
* @param flag true if list of boxes is augmented with the flipped ones
* @return reference to layer builder
*/
PriorBoxClusteredLayer& setFlip(bool flag);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,161 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
#include <vector>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for PriorBox layer
*/
class INFERENCE_ENGINE_API_CLASS(PriorBoxLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit PriorBoxLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit PriorBoxLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
PriorBoxLayer& setName(const std::string& name);
/**
* @brief Returns output port
* @return Output port
*/
const Port& getOutputPort() const;
/**
* @brief Sets output port
* @param port Output port
* @return reference to layer builder
*/
PriorBoxLayer& setOutputPort(const Port& port);
/**
* @brief Returns input ports
* @return Vector of input ports
*/
const std::vector<Port>& getInputPorts() const;
/**
* @brief Sets input ports
* @param ports Vector of input ports
* @return reference to layer builder
*/
PriorBoxLayer& setInputPorts(const std::vector<Port>& ports);
/**
* @brief Returns the minimum box size in pixels
* @return Minimum box size
*/
size_t getMinSize() const;
/**
* @brief Sets the minimum box size in pixels
* @param minSize Minimum size
* @return reference to layer builder
*/
PriorBoxLayer& setMinSize(size_t minSize);
/**
* @brief Returns the maximum box size in pixels
* @return maximum size
*/
size_t getMaxSize() const;
/**
* @brief Sets the maximum box size in pixels
* @param maxSize Maximum size
* @return reference to layer builder
*/
PriorBoxLayer& setMaxSize(size_t maxSize);
/**
* @brief Returns a distance between box centers
* @return Distance
*/
float getStep() const;
/**
* @brief Sets a distance between box centers
* @param step Distance
* @return reference to layer builder
*/
PriorBoxLayer& setStep(float step);
/**
* @brief Returns a shift of box respectively to top left corner
* @return Shift
*/
float getOffset() const;
/**
* @brief Sets a shift of box respectively to top left corner
* @param offset Shift
* @return reference to layer builder
*/
PriorBoxLayer& setOffset(float offset);
/**
* @brief Returns a variance of adjusting bounding boxes
* @return Variance
*/
float getVariance() const;
/**
* @brief Sets a variance of adjusting bounding boxes
* @param variance Variance
* @return reference to layer builder
*/
PriorBoxLayer& setVariance(float variance);
/**
* @brief Returns a flag that denotes type of inference
* @return true if max_size is used
*/
bool getScaleAllSizes() const;
/**
* @brief Sets a flag that denotes a type of inference
* @param flag max_size is used if true
* @return reference to layer builder
*/
PriorBoxLayer& setScaleAllSizes(bool flag);
/**
* @brief Returns clip flag
* @return true if each value in the output blob is within [0,1]
*/
bool getClip() const;
/**
* @brief sets clip flag
* @param flag true if each value in the output blob is within [0,1]
* @return reference to layer builder
*/
PriorBoxLayer& setClip(bool flag);
/**
* @brief Returns flip flag
* @return list of boxes is augmented with the flipped ones if true
*/
bool getFlip() const;
/**
* @brief Sets flip flag
* @param flag true if list of boxes is augmented with the flipped ones
* @return reference to layer builder
*/
PriorBoxLayer& setFlip(bool flag);
/**
* @brief Returns a variance of aspect ratios
* @return Vector of aspect ratios
*/
const std::vector<size_t> getAspectRatio() const;
/**
* @brief Sets a variance of aspect ratios
* @param aspectRatio Vector of aspect ratios
* @return reference to layer builder
*/
PriorBoxLayer& setAspectRatio(const std::vector<size_t>& aspectRatio);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,151 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
#include <vector>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for Proposal layer
*/
class INFERENCE_ENGINE_API_CLASS(ProposalLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit ProposalLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit ProposalLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
ProposalLayer& setName(const std::string& name);
/**
* @brief Returns output port
* @return Output port
*/
const Port& getOutputPort() const;
/**
* @brief Sets output port
* @param port Output port
* @return reference to layer builder
*/
ProposalLayer& setOutputPort(const Port& port);
/**
* @brief Returns input ports
* @return Vector of input ports
*/
const std::vector<Port>& getInputPorts() const;
/**
* @brief Sets input ports
* @param ports Vector of input ports
* @return reference to layer builder
*/
ProposalLayer& setInputPorts(const std::vector<Port>& ports);
/**
* @brief Returns the quantity of bounding boxes after applying NMS
* @return Quantity of bounding boxes
*/
size_t getPostNMSTopN() const;
/**
* @brief Sets the quantity of bounding boxes after applying NMS
* @param topN Quantity of bounding boxes
* @return reference to layer builder
*/
ProposalLayer& setPostNMSTopN(size_t topN);
/**
* @brief Returns the quantity of bounding boxes before applying NMS
* @return Quantity of bounding boxes
*/
size_t getPreNMSTopN() const;
/**
* @brief Sets the quantity of bounding boxes before applying NMS
* @param topN Quantity of bounding boxes
* @return reference to layer builder
*/
ProposalLayer& setPreNMSTopN(size_t topN);
/**
* @brief Returns minimum value of the proposal to be taken into consideration
* @return Threshold
*/
float getNMSThresh() const;
/**
* @brief Sets minimum value of the proposal to be taken into consideration
* @param thresh Threshold
* @return reference to layer builder
*/
ProposalLayer& setNMSThresh(float thresh);
/**
* @brief Returns base size for anchor generation
* @return Base size
*/
size_t getBaseSize() const;
/**
* @brief Sets base size for anchor generation
* @param baseSize Base size for anchor generation
* @return reference to layer builder
*/
ProposalLayer& setBaseSize(size_t baseSize);
/**
* @brief Returns minimum size of box to be taken into consideration
* @return Minimum size
*/
size_t getMinSize() const;
/**
* @brief Sets minimum size of box to be taken into consideration
* @param minSize Minimum size of the box
* @return reference to layer builder
*/
ProposalLayer& setMinSize(size_t minSize);
/**
* @brief Returns step size to slide over boxes in pixels
* @return Step size
*/
size_t getFeatStride() const;
/**
* @brief Sets step size to slide over boxes in pixels
* @param featStride Step size
* @return reference to layer builder
*/
ProposalLayer& setFeatStride(size_t featStride);
/**
* @brief Returns scales for anchor generation
* @return Vector of scales
*/
const std::vector<float> getScale() const;
/**
* @brief Sets scales for anchor generation
* @param scales Vector of scales
* @return reference to layer builder
*/
ProposalLayer& setScale(const std::vector<float>& scales);
/**
* @brief Returns ratios for anchor generation
* @return Vector of ratios
*/
const std::vector<float> getRatio() const;
/**
* @brief Sets ratios for anchor generation
* @param ratios Vector of scales
* @return reference to layer builder
*/
ProposalLayer& setRatio(const std::vector<float>& ratios);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,98 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
#include <vector>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for PSROIPooling layer
*/
class INFERENCE_ENGINE_API_CLASS(PSROIPoolingLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit PSROIPoolingLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit PSROIPoolingLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
PSROIPoolingLayer& setName(const std::string& name);
/**
* @brief Returns input ports
* @return Vector of input ports
*/
const std::vector<Port>& getInputPorts() const;
/**
* @brief Sets input ports
* @param ports Vector of input ports
* @return reference to layer builder
*/
PSROIPoolingLayer& setInputPorts(const std::vector<Port>& ports);
/**
* @brief Returns output ports
* @return Vector of output ports
*/
const Port& getOutputPort() const;
/**
* @brief Sets output ports
* @param port Vector of output ports
* @return reference to layer builder
*/
PSROIPoolingLayer& setOutputPort(const Port& port);
/**
* @brief Returns multiplicative spatial scale factor to translate ROI coordinates
* @return Spatial scale factor
*/
float getSpatialScale() const;
/**
* @brief Sets multiplicative spatial scale factor to translate ROI coordinates
* @param spatialScale Spatial scale factor
* @return reference to layer builder
*/
PSROIPoolingLayer& setSpatialScale(float spatialScale);
/**
* @brief Returns pooled output channel number
* @return Output channel number
*/
size_t getOutputDim() const;
/**
* @brief Sets pooled output channel number
* @param outDim Output channel number
* @return reference to layer builder
*/
PSROIPoolingLayer& setOutputDim(size_t outDim);
/**
* @brief Returns number of groups to encode position-sensitive score maps
* @return Number of groups
*/
size_t getGroupSize() const;
/**
* @brief Sets number of groups to encode position-sensitive score maps
* @param size Number of groups
* @return reference to layer builder
*/
PSROIPoolingLayer& setGroupSize(size_t size);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,155 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
#include <vector>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for RegionYolo layer
*/
class INFERENCE_ENGINE_API_CLASS(RegionYoloLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit RegionYoloLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit RegionYoloLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
RegionYoloLayer& setName(const std::string& name);
/**
* @brief Returns input port
* @return Input port
*/
const Port& getInputPort() const;
/**
* @brief Sets input port
* @param port Input port
* @return reference to layer builder
*/
RegionYoloLayer& setInputPort(const Port& port);
/**
* @brief Returns output port
* @return Output port
*/
const Port& getOutputPort() const;
/**
* @brief Sets output port
* @param port Output port
* @return reference to layer builder
*/
RegionYoloLayer& setOutputPort(const Port& port);
/**
* @brief Returns number of coordinates for each region
* @return Number of coordinates
*/
int getCoords() const;
/**
* @brief Sets number of coordinates for each region
* @param coords Number of coordinates
* @return reference to layer builder
*/
RegionYoloLayer& setCoords(int coords);
/**
* @brief Returns number of classes for each region
* @return Number of classes
*/
int getClasses() const;
/**
* @brief Sets number of classes for each region
* @param classes number of classes
* @return reference to layer builder
*/
RegionYoloLayer& setClasses(int classes);
/**
* @brief Returns number of regions
* @return Number of regions
*/
int getNum() const;
/**
* @brief Sets number of regions
* @param num Number of regions
* @return reference to layer builder
*/
RegionYoloLayer& setNum(int num);
/**
* @brief Returns a flag which specifies the method of infer
* @return true if softmax is performed
*/
bool getDoSoftMax() const;
/**
* @brief Sets a flag which specifies the method of infer
* @param flag softmax is performed if true
* @return reference to layer builder
*/
RegionYoloLayer& setDoSoftMax(bool flag);
/**
* @brief Returns anchors coordinates of regions
* @return anchors coordinates
*/
float getAnchors() const;
/**
* @brief Sets anchors coordinates of regions
* @param anchors Anchors coordinates
* @return reference to layer builder
*/
RegionYoloLayer& setAnchors(float anchors);
/**
* @brief Returns mask
* @return Mask
*/
int getMask() const;
/**
* @brief Sets mask
* @param mask Specifies which anchors to use
* @return reference to layer builder
*/
RegionYoloLayer& setMask(int mask);
/**
* @brief Returns the number of the dimension from which flattening is performed
* @return Axis
*/
size_t getAxis() const;
/**
* @brief Sets the number of the dimension from which flattening is performed
* @param axis Axis
* @return reference to layer builder
*/
RegionYoloLayer& setAxis(size_t axis);
/**
* @brief Returns the number of the dimension on which flattening is ended
* @return End axis
*/
size_t getEndAxis() const;
/**
* @brief Sets the number of the dimension on which flattening is ended
* @param axis End axis
* @return reference to layer builder
*/
RegionYoloLayer& setEndAxis(size_t axis);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,62 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for ReLU6 layer
*/
class INFERENCE_ENGINE_API_CLASS(ReLU6Layer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit ReLU6Layer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit ReLU6Layer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
ReLU6Layer& setName(const std::string& name);
/**
* @brief Returns port with shapes for the layer
* @return Port with shapes
*/
const Port& getPort() const;
/**
* @brief Sets port shapes for the layer
* @param port Port with shapes
* @return reference to layer builder
*/
ReLU6Layer& setPort(const Port& port);
/**
* @brief Returns N value
* @return N
*/
float getN() const;
/**
* @brief Sets N value
* @param n N value (6 by default)
* @return reference to layer builder
*/
ReLU6Layer& setN(float n);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,62 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for ReLU layer
*/
class INFERENCE_ENGINE_API_CLASS(ReLULayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit ReLULayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit ReLULayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
ReLULayer& setName(const std::string& name);
/**
* @brief Returns port with shapes for the layer
* @return Port with shapes
*/
const Port& getPort() const;
/**
* @brief Sets port shapes for the layer
* @param port Port with shapes
* @return reference to layer builder
*/
ReLULayer& setPort(const Port& port);
/**
* @brief Returns negative slope
* @return Negative slope
*/
float getNegativeSlope() const;
/**
* @brief Sets negative slope
* @param negativeSlope Negative slope
* @return reference to layer builder
*/
ReLULayer& setNegativeSlope(float negativeSlope);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,77 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
#include <vector>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for ReorgYolo layer
*/
class INFERENCE_ENGINE_API_CLASS(ReorgYoloLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit ReorgYoloLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit ReorgYoloLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
ReorgYoloLayer& setName(const std::string& name);
/**
* @brief Returns input port
* @return Input port
*/
const Port& getInputPort() const;
/**
* @brief Sets input port
* @param ports Input port
* @return reference to layer builder
*/
ReorgYoloLayer& setInputPort(const Port& ports);
/**
* @brief Returns output port
* @return Output port
*/
const Port& getOutputPort() const;
/**
* @brief Sets output port
* @param port Output port
* @return reference to layer builder
*/
ReorgYoloLayer& setOutputPort(const Port& port);
/**
* @brief Returns distance of cut throws in output blobs
* @return Stride
*/
int getStride() const;
/**
* @brief Sets distance of cut throws in output blobs
* @param stride Stride
* @return reference to layer builder
*/
ReorgYoloLayer& setStride(int stride);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,73 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
#include <vector>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for Reshape layer
*/
class INFERENCE_ENGINE_API_CLASS(ReshapeLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit ReshapeLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit ReshapeLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
ReshapeLayer& setName(const std::string& name);
/**
* @brief Returns input port
* @return Input port
*/
const Port& getInputPort() const;
/**
* @brief Sets input port
* @param port Input port
* @return reference to layer builder
*/
ReshapeLayer& setInputPort(const Port& port);
/**
* @brief Returns output port
* @return Output port
*/
const Port& getOutputPort() const;
/**
* @brief Sets output port
* @param port Output port
* @return reference to layer builder
*/
ReshapeLayer& setOutputPort(const Port& port);
/**
* @brief Returns reshape dimensions
* @return Dimensions
*/
const std::vector<int> getDims() const;
/**
* @brief Sets reshape dimensions
* @param dims Dimensions
* @return reference to layer builder
*/
ReshapeLayer& setDims(const std::vector<int>& dims);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,84 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
#include <vector>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for ROIPooling layer
*/
class INFERENCE_ENGINE_API_CLASS(ROIPoolingLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit ROIPoolingLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit ROIPoolingLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
ROIPoolingLayer& setName(const std::string& name);
/**
* @brief Returns input ports
* @return Vector of input ports
*/
const std::vector<Port>& getInputPorts() const;
/**
* @brief Sets input ports
* @param ports Vector of input ports
* @return reference to layer builder
*/
ROIPoolingLayer& setInputPorts(const std::vector<Port>& ports);
/**
* @brief Returns output port
* @return Output port
*/
const Port& getOutputPort() const;
/**
* @brief Sets output port
* @param port Output port
* @return reference to layer builder
*/
ROIPoolingLayer& setOutputPort(const Port& port);
/**
* @brief Returns a ratio of the input feature map over the input image size
* @return Spatial scale
*/
float getSpatialScale() const;
/**
* @brief Sets a ratio of the input feature map over the input image size
* @param spatialScale Spatial scale
* @return reference to layer builder
*/
ROIPoolingLayer& setSpatialScale(float spatialScale);
/**
* @brief Returns height and width of the ROI output feature map
* @return Vector contains height and width
*/
const std::vector<int> getPooled() const;
/**
* @brief Sets height and width of the ROI output feature map
* @param pooled Vector with height and width
* @return reference to layer builder
*/
ROIPoolingLayer& setPooled(const std::vector<int>& pooled);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,63 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for ScaleShift layer
*/
class INFERENCE_ENGINE_API_CLASS(ScaleShiftLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit ScaleShiftLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit ScaleShiftLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
ScaleShiftLayer& setName(const std::string& name);
/**
* @brief Returns port with shapes for the layer
* @return Port with shapes
*/
const Port& getPort() const;
/**
* @brief Sets port shapes for the layer
* @param port Port with shapes
* @return reference to layer builder
*/
ScaleShiftLayer& setPort(const Port &port);
/**
* @brief Sets weights for layer
* @param weights Constant blob with weights
* @return reference to layer builder
*/
ScaleShiftLayer& setWeights(const Blob::CPtr& weights);
/**
* @brief Sets biases for layer
* @param biases Constant blob with biases
* @return reference to layer builder
*/
ScaleShiftLayer& setBiases(const Blob::CPtr& biases);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,50 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for Sigmoid layer
*/
class INFERENCE_ENGINE_API_CLASS(SigmoidLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit SigmoidLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit SigmoidLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
SigmoidLayer& setName(const std::string& name);
/**
* @brief Returns port with shapes for the layer
* @return Port with shapes
*/
const Port& getPort() const;
/**
* @brief Sets port shapes for the layer
* @param port Port with shapes
* @return reference to layer builder
*/
SigmoidLayer& setPort(const Port& port);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,140 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
#include <vector>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for SimplerNMS layer
*/
class INFERENCE_ENGINE_API_CLASS(SimplerNMSLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit SimplerNMSLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit SimplerNMSLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
SimplerNMSLayer& setName(const std::string& name);
/**
* @brief Returns input ports
* @return Vector of input ports
*/
const std::vector<Port>& getInputPorts() const;
/**
* @brief Sets input ports
* @param ports Vector of input ports
*/
SimplerNMSLayer& setInputPorts(const std::vector<Port>& ports);
/**
* @brief Returns output port
* @return Output port
*/
const Port& getOutputPort() const;
/**
* @brief Sets output port
* @param port Output port
* @return reference to layer builder
*/
SimplerNMSLayer& setOutputPort(const Port& port);
/**
* @brief Returns the quantity of bounding boxes before applying NMS
* @return Quantity of bounding boxes
*/
size_t getPreNMSTopN() const;
/**
* @brief Sets the quantity of bounding boxes before applying NMS
* @param topN Quantity of bounding boxes
* @return reference to layer builder
*/
SimplerNMSLayer& setPreNMSTopN(size_t topN);
/**
* @brief Returns the quantity of bounding boxes after applying NMS
* @return Quantity of bounding boxes
*/
size_t getPostNMSTopN() const;
/**
* @brief Sets the quantity of bounding boxes after applying NMS
* @param topN Quantity of bounding boxes
* @return reference to layer builder
*/
SimplerNMSLayer& setPostNMSTopN(size_t topN);
/**
* @brief Returns the step size to slide over boxes in pixels
* @return Step size
*/
size_t getFeatStride() const;
/**
* @brief Sets the step size to slide over boxes in pixels
* @param featStride Step size
* @return reference to layer builder
*/
SimplerNMSLayer& setFeatStride(size_t featStride);
/**
* @brief Returns the minimum size of box to be taken into consideration
* @return Minimum size
*/
size_t getMinBoxSize() const;
/**
* @brief Sets the minimum size of box to be taken into consideration
* @param minSize Minimum size
* @return reference to layer builder
*/
SimplerNMSLayer& setMinBoxSize(size_t minSize);
/**
* @brief Returns scale for anchor boxes generating
* @return Scale for anchor boxes
*/
size_t getScale() const;
/**
* @brief Sets scale for anchor boxes generating
* @param scale Scale for anchor boxes
* @return reference to layer builder
*/
SimplerNMSLayer& setScale(size_t scale);
/**
* @brief Returns the minimum value of the proposal to be taken into consideration
* @return Threshold
*/
float getCLSThreshold() const;
/**
* @brief Sets the minimum value of the proposal to be taken into consideration
* @param threshold Minimum value
* @return reference to layer builder
*/
SimplerNMSLayer& setCLSThreshold(float threshold);
/**
* @brief Returns the minimum ratio of boxes overlapping to be taken into consideration
* @return Threshold
*/
float getIOUThreshold() const;
/**
* @brief Sets the minimum ratio of boxes overlapping to be taken into consideration
* @param threshold Minimum value
* @return reference to layer builder
*/
SimplerNMSLayer& setIOUThreshold(float threshold);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,61 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for SoftMax layer
*/
class INFERENCE_ENGINE_API_CLASS(SoftMaxLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit SoftMaxLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit SoftMaxLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
SoftMaxLayer& setName(const std::string& name);
/**
* @brief Returns port with shapes for the layer
* @return Port with shapes
*/
const Port& getPort() const;
/**
* @brief Sets port shapes for the layer
* @param port Port with shapes
* @return reference to layer builder
*/
SoftMaxLayer& setPort(const Port& port);
/**
* @brief Returns axis
* @return Axis
*/
size_t getAxis() const;
/**
* @brief Sets axis
* @param axis Axis
* @return reference to layer builder
*/
SoftMaxLayer& setAxis(size_t axis);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,73 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
#include <vector>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for Split layer
*/
class INFERENCE_ENGINE_API_CLASS(SplitLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit SplitLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit SplitLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
SplitLayer& setName(const std::string& name);
/**
* @brief Returns output ports
* @return Vector of output ports
*/
const std::vector<Port>& getOutputPorts() const;
/**
* @brief Sets output ports
* @param ports Vector of output ports
* @return reference to layer builder
*/
SplitLayer& setOutputPorts(const std::vector<Port>& ports);
/**
* @brief Returns input port
* @return Input port
*/
const Port& getInputPort() const;
/**
* @brief Sets input port
* @param port Input port
* @return reference to layer builder
*/
SplitLayer& setInputPort(const Port& port);
/**
* @brief Returns axis
* @return Axis
*/
size_t getAxis() const;
/**
* @brief Sets axis
* @param axis Axis
* @return reference to layer builder
*/
SplitLayer& setAxis(size_t axis);
};
} // namespace Builder
} // namespace InferenceEngine

View File

@@ -0,0 +1,50 @@
// Copyright (C) 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <builders/ie_layer_fragment.hpp>
#include <ie_inetwork.hpp>
#include <string>
namespace InferenceEngine {
namespace Builder {
/**
* @brief The class represents a builder for TanH layer
*/
class INFERENCE_ENGINE_API_CLASS(TanHLayer): public LayerFragment {
public:
/**
* @brief The constructor creates a builder with the name
* @param name Layer name
*/
explicit TanHLayer(const std::string& name = "");
/**
* @brief The constructor creates a builder from generic builder
* @param genLayer generic builder
*/
explicit TanHLayer(Layer& genLayer);
/**
* @brief Sets the name for the layer
* @param name Layer name
* @return reference to layer builder
*/
TanHLayer& setName(const std::string& name);
/**
* @brief Returns port with shapes for the layer
* @return Port with shapes
*/
const Port& getPort() const;
/**
* @brief Sets port shapes for the layer
* @param port Port with shapes
* @return reference to layer builder
*/
TanHLayer& setPort(const Port& port);
};
} // namespace Builder
} // namespace InferenceEngine

Some files were not shown because too many files have changed in this diff Show More