Skip to content

Instantly share code, notes, and snippets.

View cyrusbehr's full-sized avatar

cyrusbehr

View GitHub Profile
@cyrusbehr
cyrusbehr / mxnet2ncnn.cpp
Created September 12, 2019 18:47
NCNN mxnet2ncnn _copy operator fix
else if (n.op == "_copy")
{
fprintf(pp, "%-16s", "UnaryOp");
}
@cyrusbehr
cyrusbehr / ncnnInference.cpp
Last active September 16, 2019 17:02
Performing inference with NCNN
#include <iostream>
#include "ncnn/net.h"
#include "opencv2/opencv.hpp"
void normalize(std::vector<float>& arr) {
double mod = 0.0;
for (float i : arr) {
mod += i * i;
}
@cyrusbehr
cyrusbehr / CMakeLists.txt
Last active September 12, 2019 22:54
Performing inference with NCNN
cmake_minimum_required(VERSION 3.14)
project(ncnn-inference)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -fPIC -ffast-math -Ofast -fopenmp")
add_executable(ncnn_test main.cpp)
find_package( OpenCV REQUIRED )
target_include_directories(
ncnn_test
@cyrusbehr
cyrusbehr / tune_nnvm_x86.py
Last active September 12, 2019 21:57
Auto tune MXNet model and compile to TVM
import os
import numpy as np
import nnvm.testing
import nnvm.compiler
import tvm
import mxnet as mx
from tvm import autotvm
import tvm.relay as relay
from tvm.autotvm.tuner import XGBTuner, GATuner, RandomTuner, GridSearchTuner
@cyrusbehr
cyrusbehr / tvmInference.cpp
Last active September 16, 2019 17:02
Perform inference MXNet model converted to TVM
#include <fstream>
#include <iostream>
#include <memory>
#include "opencv2/opencv.hpp"
#include "tvm/runtime/module.h"
#include "tvm/runtime/registry.h"
#include "tvm/runtime/packed_func.h"
@cyrusbehr
cyrusbehr / CMakeLists.txt
Last active December 3, 2019 17:38
Performing inference with MXNet model converted to TVM
cmake_minimum_required(VERSION 3.14)
project(tvm-inference)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -fPIC -ffast-math -Ofast -ldl -lpthread")
add_executable(tvm_test tvm_runtime_pack.cc main.cpp)
set(HOME_TVM /path/to/tvm/dir)
find_package(OpenCV REQUIRED)
@cyrusbehr
cyrusbehr / build_opencv.sh
Last active November 28, 2019 00:14
OpenCV AArch32 and AArch64 CMake commands
####################
# build for aarch32
####################
mkdir build_aarch32
cd build_aarch32
cmake -DCMAKE_TOOLCHAIN_FILE="../platforms/linux/arm-gnueabi.toolchain.cmake" -D CMAKE_INSTALL_PREFIX="/usr/local" -D BUILD_SHARED_LIBS=OFF -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_DOCS=OFF -D BUILD_EXAMPLES=OFF -D BUILD_opencv_apps=OFF -D WITH_CAROTENE=OFF -D BUILD_opencv_python2=OFF -D BUILD_opencv_python3=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_TESTS=OFF -D FORCE_VTK=OFF -D WITH_FFMPEG=OFF -D WITH_GDAL=OFF -D WITH_IPP=OFF -D WITH_OPENEXR=OFF -D WITH_OPENGL=OFF -D WITH_QT=OFF -D WITH_TBB=OFF -D WITH_XINE=OFF -D BUILD_JPEG=ON -D BUILD_ZLIB=ON -D BUILD_PNG=ON -D BUILD_TIFF=OFF -D BUILD_BUILD_JASPER=OFF -D WITH_ITT=OFF -D WITH_LAPACK=OFF -D WITH_OPENCL=OFF -D WITH_TIFF=OFF -D WITH_PNG=ON -D WITH_OPENCLAMDFFT=OFF -D WITH_OPENCLAMDBLAS=OFF -D WITH_VA_INTEL=OFF -D WITH_WEBP=OFF -D WITH_JASPER=OFF ..
make -j$(nproc)
@cyrusbehr
cyrusbehr / build_ncnn.sh
Last active November 28, 2019 00:13
Cross compile NCNN for AArch32 and AArch64
####################
# build for aarch32
####################
mkdir build_aarch32
cd build_aarch32
cmake -D NCNN_BUILD_TOOLS=OFF -D NCNN_VULKAN=OFF -D CMAKE_BUILD_TYPE=Release -D NCNN_DISABLE_RTTI=OFF -D CMAKE_TOOLCHAIN_FILE=../toolchains/arm-linux-gnueabihf.toolchain.cmake ..
@cyrusbehr
cyrusbehr / main.cpp
Last active November 26, 2019 21:17
Landmark Detection
#include <opencv2/opencv.hpp>
#include <memory>
#include <string>
#include <vector>
#include "mtcnn.h"
#include "net.h"
// Loads image, computes landmark locations, draws landmarks on image and save to disk
void detectLandmarks(const std::string& imgPath, const std::unique_ptr<MTCNN>& mtcnnPtr);
@cyrusbehr
cyrusbehr / CMakeLists.txt
Last active November 26, 2019 22:18
CMakeLists for AArch32
cmake_minimum_required(VERSION 3.0)
SET ( CMAKE_SYSTEM_NAME Linux )
SET ( CMAKE_SYSTEM_PROCESSOR arm )
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 )