Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
caffe@refkit-extra
hdf5@refkit-extra
leveldb@openembedded-layer
lmdb@refkit-extra
openblas@refkit-extra
python3-imageio@refkit-extra
python3-pillow@refkit-extra
python3-protobuf@refkit-extra
python3-pycparser@meta-python
python3-pyrealsense@refkit-extra
python3-six@core
snappy@refkit-extra
6 changes: 6 additions & 0 deletions meta-refkit-extra/conf/distro/include/refkit-extra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require refkit_extra_security_flags.inc

SUPPORTED_RECIPES_append = " \
${META_REFKIT_EXTRA_BASE}/conf/distro/include/refkit-extra-supported-recipes.txt \
"
SUPPORTED_RECIPES[refkit-extra-supported-recipes.txt] = "extra"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SECURITY_CFLAGS_pn-python3-pillow = "${SECURITY_NO_PIE_CFLAGS} ${SECURITY_PIC_CFLAGS}"
SECURITY_CFLAGS_pn-snappy = "${SECURITY_NO_PIE_CFLAGS} ${SECURITY_PIC_CFLAGS}"
SECURITY_CFLAGS_pn-leveldb = "${SECURITY_NO_PIE_CFLAGS} ${SECURITY_PIC_CFLAGS}"
SECURITY_CFLAGS_pn-python3-pyrealsense = "${SECURITY_NO_PIE_CFLAGS} ${SECURITY_PIC_CFLAGS}"
13 changes: 13 additions & 0 deletions meta-refkit-extra/conf/layer.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# We have a conf and classes directory, add to BBPATH
BBPATH .= ":${LAYERDIR}"

# We have recipes-* directories, add to BBFILES
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
${LAYERDIR}/recipes-*/*/*.bbappend"

BBFILE_COLLECTIONS += "refkit-extra"
BBFILE_PATTERN_refkit-extra = "^${LAYERDIR}/"
# higher priority than meta-refkit, so that we can override recipes here
BBFILE_PRIORITY_refkit-extra = "7"

META_REFKIT_EXTRA_BASE := "${LAYERDIR}"
10 changes: 10 additions & 0 deletions meta-refkit-extra/doc/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
This a layer for demos and other things which are built on top of
Refkit. Do not add dependencies from meta-refkit to this layer.

To enable this layer, enter:

$ bitbake-layers add-layer meta-refkit-extra

Then add to your local.conf of distribution config this line:

require conf/distro/include/refkit-extra.conf
70 changes: 70 additions & 0 deletions meta-refkit-extra/doc/computervision.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
Setting up computer vision demos
################################

Introduction
============

This layer contains components such as Caffe deep learning framework and
Python bindings to librealsense (pyrealsense). The components are
scriptable with Python 3, making it relatively easy to construct complex
computer vision demos using only Python.

Example 1: measuring distance to cats
=====================================

This is an example how the bindings can be used for measuring distance to cats
using a RealSense camera for taking pictures and distance calculations. OpenCV
does the cat recognition with a pre-configured classifier. You need to
have packages ``python3-pyrealsense`` and ``opencv`` installed and
Intel RealSense R200 camera connected to your device.

.. code:: python

#!/usr/bin/python3

import sys

import numpy as np
import cv2
import pyrealsense as pyrs

n_devices = pyrs.start()

if n_devices == 0:
print("No RealSense devices found!")
sys.exit(1)

cam = pyrs.Device()

cat_cascade = cv2.CascadeClassifier("/usr/share/OpenCV/haarcascades/haarcascade_frontalcatface.xml")

for x in range(30):
# stabilize exposure
cam.wait_for_frame()

while True:
# get image from web cam
cam.wait_for_frame()
img = cam.colour

cats = cat_cascade.detectMultiScale(img)

for (x,y,w,h) in cats:
# find center
cx = x+(w/2)
cy = y+(h/2)

depth = cam.depth[cy][cx]

print("Cat found, distance " + str(depth/10.0) + " cm")

Example 2: recognizing objects in images using Caffenet
=======================================================

Install ``caffe-imagenet-model`` package. Then run ``classify-demo.py
--mean_file=""`` in Caffe's Python directory (``/usr/python``) for an
interactive demo recognizing images in web camera stream. You need to
have a web camera connected. Point the web camera at things and in the
console you will see what the image classifier considers them to be. The
deep neural network which the example uses is Caffenet, which is trained
using the 1.3 million image ImageNet training set.
1 change: 1 addition & 0 deletions meta-refkit-extra/recipes-convnet/boost/boost_%.bbappend
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PACKAGECONFIG += "python"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ipuustin Is this needed? IIRC you mentioned it's not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's still needed -- it enables Python support in boost. We no longer need to select Python 3 by editing the user-config.jam file, because Python 3 support is now enabled as default if it's found. See difference to the previous iteration of the same file. https://github.com/ipuustin/intel-iot-refkit/blob/165b46149a2c5a58788b91d2cac97c394e567f14/meta-refkit/recipes-convnet/boost/boost_%25.bbappend

However, it's a good question if we should move the PACKAGECONFIG variable to the layer distro configuration file instead of the .bbappend file. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. python isn't enabled by default. I got confused by what you wrote earlier: "The bbappend should not be needed anymore."

94 changes: 94 additions & 0 deletions meta-refkit-extra/recipes-convnet/caffe/caffe_git.bb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
DESCRIPTION = "Build Caffe library for CNN using OpenBLAS lib"
AUTHOR = "Alexander Leiva <norxander@gmail.com>"
SUMMARY = "Caffe : A fast open framework for deep learning"
HOMEPAGE = "http://caffe.berkeleyvision.org/"
LICENSE = "BSD & BVLC-model-license"
PRIORITY= "optional"
SECTION = "libs"
PR = "r0"

DEPENDS = " \
boost \
openblas \
protobuf-native \
protobuf \
glog \
gflags \
hdf5 \
opencv \
lmdb \
snappy \
leveldb \
viennacl \
ocl-icd \
python3 \
python3-native \
python3-numpy-native \
"

inherit python3native

RDEPENDS_${PN} = "python3-numpy python3-imageio python3-six python3-protobuf"

LIC_FILES_CHKSUM = "file://LICENSE;md5=91d560803ea3d191c457b12834553991"

SRC_URI = " \
git://github.com/BVLC/caffe.git;branch=opencl \
http://dl.caffe.berkeleyvision.org/caffe_ilsvrc12.tar.gz;name=ilsvrc12 \
http://dl.caffe.berkeleyvision.org/bvlc_reference_caffenet.caffemodel;name=caffenet \
file://0001-Allow-setting-numpy-include-dir-from-outside.patch \
file://0002-cmake-do-not-use-SYSTEM-for-non-system-include-direc.patch \
file://0003-cmake-fix-RPATHS.patch \
file://0004-config-use-Python-3.patch \
file://0005-io-change-to-imageio.patch \
file://0006-classify-demo-added-a-demo-app-for-classifying-image.patch \
file://0001-cmake-find-Yocto-boost-python-libs.patch \
"
SRCREV = "f3ba72c520165d7c403a82770370f20472685d63"

SRC_URI[ilsvrc12.md5sum] = "f963098ea0e785a968ca1eb634003a90"
SRC_URI[ilsvrc12.sha256sum] = "e35c0c1994a21f7d8ed49d01881ce17ab766743d3b0372cdc0183ff4d0dfc491"

SRC_URI[caffenet.md5sum] = "af678f0bd3cdd2437e35679d88665170"
SRC_URI[caffenet.sha256sum] = "472d4a06035497b180636d8a82667129960371375bd10fcb6df5c6c7631f25e0"

S = "${WORKDIR}/git"

PACKAGES += "${PN}-imagenet-model"

RDEPENDS_${PN}-imagenet-model = "${PN}"

do_install_append() {
install -d ${D}${datadir}/Caffe/models/bvlc_reference_caffenet/
install -d ${D}${datadir}/Caffe/data/ilsvrc12

install ${S}/models/bvlc_reference_caffenet/* ${D}${datadir}/Caffe/models/bvlc_reference_caffenet/
install ${WORKDIR}/synset_words.txt ${D}${datadir}/Caffe/data/ilsvrc12
install ${WORKDIR}/bvlc_reference_caffenet.caffemodel ${D}${datadir}/Caffe/models/bvlc_reference_caffenet/

# ilsvrc_2012_mean.npy is already installed at /usr/python/caffe/imagenet/ilsvrc_2012_mean.npy
}

FILES_${PN}-imagenet-model += " \
${datadir}/Caffe/models/bvlc_reference_caffenet/* \
${datadir}/Caffe/data/ilsvrc12/* \
"
FILES_${PN} += " \
${prefix}/python/* \
"
FILES_${PN}-dev = " \
${includedir} \
${datadir}/Caffe/*cmake \
${libdir}/*.so \
"

inherit cmake python-dir

EXTRA_OECMAKE = " \
-DBLAS=open \
-DPYTHON_NUMPY_INCLUDE_DIR=${STAGING_DIR_TARGET}/usr/lib/python3.5/site-packages/numpy/core/include \
-DPYTHON_EXECUTABLE=${STAGING_BINDIR_NATIVE}/python3-native/python3 \
-DPYTHON_INCLUDE_DIRS=${STAGING_INCDIR_TARGET}/python3-native/python3.5m \
-DPYTHON_LIBRARIES=${STAGING_LIBDIR_TARGET}/python3.5 \
"

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
From 3a0407e127559d2349f0217c6c5cf7751dd1aeba Mon Sep 17 00:00:00 2001
From: Ismo Puustinen <ismo.puustinen@intel.com>
Date: Tue, 25 Oct 2016 12:09:19 +0300
Subject: [PATCH 1/6] Allow setting numpy include dir from outside.

---
cmake/Modules/FindNumPy.cmake | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/cmake/Modules/FindNumPy.cmake b/cmake/Modules/FindNumPy.cmake
index a671494..38ebb32 100644
--- a/cmake/Modules/FindNumPy.cmake
+++ b/cmake/Modules/FindNumPy.cmake
@@ -16,11 +16,16 @@ unset(NUMPY_VERSION)
unset(NUMPY_INCLUDE_DIR)

if(PYTHONINTERP_FOUND)
- execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
- "import numpy as n; print(n.__version__); print(n.get_include());"
- RESULT_VARIABLE __result
- OUTPUT_VARIABLE __output
- OUTPUT_STRIP_TRAILING_WHITESPACE)
+ if(NOT DEFINED PYTHON_NUMPY_INCLUDE_DIR)
+ execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
+ "import numpy as n; print(n.__version__); print(n.get_include());"
+ RESULT_VARIABLE __result
+ OUTPUT_VARIABLE __output
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ else()
+ SET(__result 0)
+ SET(__output "1.11.0\n${PYTHON_NUMPY_INCLUDE_DIR}")
+ endif()

if(__result MATCHES 0)
string(REGEX REPLACE ";" "\\\\;" __values ${__output})
@@ -55,4 +60,3 @@ if(NUMPY_FOUND)
endif()

caffe_clear_vars(__result __output __error_value __values __ver_check __error_value)
-
--
2.9.3

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
From 91f8bfd7da0d9d59701dffdb2f1ab6552721fe7b Mon Sep 17 00:00:00 2001
From: Ismo Puustinen <ismo.puustinen@intel.com>
Date: Wed, 26 Apr 2017 14:43:01 +0300
Subject: [PATCH] cmake: find Yocto boost python libs.

Upstream-status: Inappropriate

Signed-off-by: Ismo Puustinen <ismo.puustinen@intel.com>
---
cmake/Dependencies.cmake | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake
index 4a5bac4..dab3415 100644
--- a/cmake/Dependencies.cmake
+++ b/cmake/Dependencies.cmake
@@ -146,15 +146,15 @@ if(BUILD_python)
set(version ${PYTHONLIBS_VERSION_STRING})

STRING( REGEX REPLACE "[^0-9]" "" boost_py_version ${version} )
- find_package(Boost 1.46 COMPONENTS "python-py${boost_py_version}")
- set(Boost_PYTHON_FOUND ${Boost_PYTHON-PY${boost_py_version}_FOUND})
+ find_package(Boost 1.46 COMPONENTS "python${boost_py_version}")
+ set(Boost_PYTHON_FOUND ${Boost_PYTHON${boost_py_version}_FOUND})

while(NOT "${version}" STREQUAL "" AND NOT Boost_PYTHON_FOUND)
STRING( REGEX REPLACE "([0-9.]+).[0-9]+" "\\1" version ${version} )

STRING( REGEX REPLACE "[^0-9]" "" boost_py_version ${version} )
- find_package(Boost 1.46 COMPONENTS "python-py${boost_py_version}")
- set(Boost_PYTHON_FOUND ${Boost_PYTHON-PY${boost_py_version}_FOUND})
+ find_package(Boost 1.46 COMPONENTS "python${boost_py_version}")
+ set(Boost_PYTHON_FOUND ${Boost_PYTHON${boost_py_version}_FOUND})

STRING( REGEX MATCHALL "([0-9.]+).[0-9]+" has_more_version ${version} )
if("${has_more_version}" STREQUAL "")
--
2.9.3

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
From 9e698ecf0b354a87ea0bf79ee42a4e6ec09c7669 Mon Sep 17 00:00:00 2001
From: Ismo Puustinen <ismo.puustinen@intel.com>
Date: Fri, 17 Feb 2017 14:43:21 +0200
Subject: [PATCH 2/6] cmake: do not use SYSTEM for non-system include
directories.

Signed-off-by: Ismo Puustinen <ismo.puustinen@intel.com>
---
cmake/Dependencies.cmake | 8 ++++----
cmake/ProtoBuf.cmake | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake
index 00de565..0b861af 100644
--- a/cmake/Dependencies.cmake
+++ b/cmake/Dependencies.cmake
@@ -6,7 +6,7 @@ set(Caffe_COMPILE_OPTIONS "")

# ---[ Boost
find_package(Boost 1.46 REQUIRED COMPONENTS system thread filesystem)
-include_directories(SYSTEM PUBLIC ${Boost_INCLUDE_DIR})
+include_directories(PUBLIC ${Boost_INCLUDE_DIR})
add_definitions(-DBOOST_ALL_NO_LIB)
list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${Boost_INCLUDE_DIRS})
list(APPEND Caffe_LINKER_LIBS PUBLIC ${Boost_LIBRARIES})
@@ -66,14 +66,14 @@ else()
endif()
endif()

-include_directories(SYSTEM ${HDF5_INCLUDE_DIRS} ${HDF5_HL_INCLUDE_DIR})
+include_directories(${HDF5_INCLUDE_DIRS} ${HDF5_HL_INCLUDE_DIR})
list(APPEND Caffe_LINKER_LIBS PUBLIC ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES})
list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${HDF5_INCLUDE_DIRS})

# This code is taken from https://github.com/sh1r0/caffe-android-lib
if(USE_HDF5)
find_package(HDF5 COMPONENTS HL REQUIRED)
- include_directories(SYSTEM ${HDF5_INCLUDE_DIRS} ${HDF5_HL_INCLUDE_DIR})
+ include_directories(${HDF5_INCLUDE_DIRS} ${HDF5_HL_INCLUDE_DIR})
list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${HDF5_INCLUDE_DIRS})
list(APPEND Caffe_LINKER_LIBS PUBLIC ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES})
add_definitions(-DUSE_HDF5)
@@ -201,7 +201,7 @@ endif()

if(USE_NCCL)
include("cmake/External/nccl.cmake")
- include_directories(SYSTEM ${NCCL_INCLUDE_DIR})
+ include_directories(${NCCL_INCLUDE_DIR})
list(APPEND Caffe_LINKER_LIBS ${NCCL_LIBRARIES})
add_definitions(-DUSE_NCCL)
endif()
diff --git a/cmake/ProtoBuf.cmake b/cmake/ProtoBuf.cmake
index 2527195..dc6285b 100644
--- a/cmake/ProtoBuf.cmake
+++ b/cmake/ProtoBuf.cmake
@@ -8,7 +8,7 @@ if(MSVC)
else()
find_package( Protobuf REQUIRED )
endif()
-include_directories(SYSTEM ${PROTOBUF_INCLUDE_DIR})
+include_directories(${PROTOBUF_INCLUDE_DIR})
list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${PROTOBUF_INCLUDE_DIR})
list(APPEND Caffe_LINKER_LIBS PUBLIC ${PROTOBUF_LIBRARIES})

--
2.9.3

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
From 8d9b978681b7c7d5443f5503e2075b007fb460a5 Mon Sep 17 00:00:00 2001
From: Ismo Puustinen <ismo.puustinen@intel.com>
Date: Fri, 17 Feb 2017 15:35:43 +0200
Subject: [PATCH 3/6] cmake: fix RPATHS.

Signed-off-by: Ismo Puustinen <ismo.puustinen@intel.com>
---
cmake/Misc.cmake | 4 ----
1 file changed, 4 deletions(-)

diff --git a/cmake/Misc.cmake b/cmake/Misc.cmake
index 9dd2609..2150751 100644
--- a/cmake/Misc.cmake
+++ b/cmake/Misc.cmake
@@ -28,10 +28,6 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/install" CACHE PATH "Default install path" FORCE)
endif()

-# ---[ RPATH settings
-set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOLEAN "Use link paths for shared library rpath")
-set(CMAKE_MACOSX_RPATH TRUE)
-
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES ${CMAKE_INSTALL_PREFIX}/lib __is_systtem_dir)
if(${__is_systtem_dir} STREQUAL -1)
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
--
2.9.3

Loading