Welcome to Boyi's log

Hi there, welcome to my blog! Here I’ll log the problems I’ve encountered in my expidition to building new things through coding. I’ll document how I encountered the pitfalls, and how I got to the bottom and came back up stronger. I pray this log shall prove a valuable reference for myself and my fellow sailors who come across the similar courses. The routes I’ve become familar with and where I’m continuously exploring are:

Node.js Notes

Introduction Node is a runtime environment for executing JS code. Essentially, Node is a C++ program that embeds Chrome’s v8 engine. Node applications are single-threaded. That means a single thread is used to serve all clients. Node applications are asynchronous or non-blocking by default. Scope We don’t have the window object in Node. The global object in Node is “global”. Unlike browser applications, variables we define are not added to the “global” object.

Resolve "DSO missing from command line" error

I encountered the following error while building a project on Linux. /usr/bin/ld: CMakeFiles/ingame.dir/media/sdcard/ingame_app/sdk/src/ingame/dnn_in fer.cpp.o: undefined reference to symbol 'cudaDeviceReset@@libcudart.so.10.2' //usr/local/cuda-10.2/targets/aarch64-linux/lib/libcudart.so.10.2: error adding symbols: DSO missing from command line The solution was found from this link. A not accepted answer with 24 ups says the following. applying the export LDFLAGS="-Wl,--copy-dt-needed-entries" helped me to suppress the error. Background The DSO missing from command line message will be displayed when the linker does not find the required symbol with it’s normal search but the symbol is available in one of the dependencies of a directly specified dynamic library.

Python Cheat Sheet

This cheat sheet is from this link, with highlighting added by myself. # import is used to make specialty functions available # These are called modules import random import sys import os # Hello world is just one line of code # print() outputs data to the screen print("Hello World") ''' This is a multi-line comment ''' # A variable is a place to store values # Its name is like a label for that value name = "

Install Tensorflow Keras Tvm On Xavier

This blog talks about how to run and install TVM, Tensorflow, and Keras on Jetson Xavier with Jetpack 4.3. The steps are Install TVM Install Tensorflow Install Keras Install TVM TVM is an engine that compiles and optimizes deep learning model for different hardware platforms. To install is on Xaveir, run the following commands adapted from this tutorial. $ git clone --recursive https://github.com/apache/incubator-tvm tvm $ sudo apt-get update $ sudo apt-get install -y python3 python3-dev python3-setuptools gcc libtinfo-dev zlib1g-dev build-essential cmake libedit-dev libxml2-dev $ mkdir build $ cp cmake/config.

Using Nsight Eclipse to Profile Jetson Xavier Remotely

This blog talks about how to run and profile a program on Jetson Xavier remotely. The steps are Install Nsight Eclipse Set SSH Root Login Run Profiler Install Nsight Eclipse Nsight Eclipse is installed using Nvidia SDK Manager. When installing Jetpack on Xavier, make sure to also select the host machine to install Jetpack on the host PC. After this, Nsight Eclipse Edition can be found and executed from the Application folder.

Training Imagenet on Ubuntu 18.04

This blog talks about how to set up ubuntu 18.04 to train CNN model on imagenet. The steps are Install CUDA Install CUDNN Install pytorch Prepare imagenet dataset Training To save time, start with step 4 to download imagenet dataset first. Install CUDA No need to update graphic card driver, the driver will be updated with CUDA installation. Partially following this blog post, my commands are $ wget http://developer.


This is the take away from this video accompanied by this slide. It talks about running OpenCV on CUDA GPU. This seminar is based on OpenCV 2.4. The API in Opencv 3.X is different. A few points worth noting before entering the code: GpuMat is a padded image container, the upload/download operations are described in pages 15 - 17. Page 20 gives an example of template matching. Concurrent operation with CUDA is described in pages 24 to 28.

Shell Script Example

This shell script is from Jetson’s JetPack. It downloads and installs pytorch. I added highlighting and comments to help myself understand bash language. #!/bin/bash # #! is shebang interpreter directive, it sets which interpreter to use # when called using ./ # # Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "

C++ File Operation

File operation with C++ can be a headache. I first tried with Windows API’s CopyFile(), but it took a lot of trial and error for me to figure out that under Visual Studio the text encoding has to be changed from UNICODE to Not Set. Then I found the following solution from StackOverflow, which is much simpler. #include <exception> #include <experimental/filesystem> // C++-standard filesystem header file in VS15, VS17. #include <iostream> namespace fs = std::experimental::filesystem; // experimental for VS15, VS17.

Objective-C Cheat Sheet

This cheat sheet is from this link, with highlighting added by myself. // The Foundation framework contains many fundamental // classes used to develop Objective C programs #import // Used for classes in the project #import "Animal.h" #import "Koala.h" #import "Animal+Exam.h" #import "Dog.h" // @1 becomes [NSNumber numberWithInteger:1] during the compiling. It's really just a shorthand means of creating an object out of a literal. int main(int argc, const char * argv[]) { // Memory is set aside for the app and when objects // are no longer needed their allocated memory // is released for other apps // The ARC (Automatic Reference Counting) // signals for the destruction of objects // when they are not needed @autoreleasepool { // Works like printf NSLog(@"

Swift Cheat Sheet

This cheat sheet is from this link, with highlighting added by myself. /* Multiline Comment */ import UIKit import Darwin // Some C libraries to use // Variable names must start with a letter and can contain most any unicode // character except whitespace, mathematical symbols, arrows // Swift uses type inference to guess the data type if it isn't provided // It assumes this is a string and won't except any other value type var str = "

Eigen Cheat Sheet

Eigen is a header-only, lightweight linear algebra library. It is released under MPL2 license, which is a weak copyleft license. Here’s a cheat sheet on how to initialize matrices and vectors, and how to perform simple operations on them. // fixed size typedef Matrix<float, 4, 4> Matrix4f; typedef Matrix<int, 1, 2> RowVector2i; // dynamic size typedef Matrix<double, Dynamic, Dynamic> MatrixXd; typedef Matrix<int, Dynamic, 1> VectorXi; // column vector // The matrix is stored column-major // constructors Matrix3f a; MatrixXf b; MatrixXf a(10,15); VectorXf b(30); // constructors to initialize value of small fixed-size vectors Vector4d c(5.

Face Alignment

Face alignment answers the question of finding keypoints on a human face. The following videos introduce two methods of face alignment in English and Chinese. In English In Chinese

Using Scatter Plot To Visualize Solution Space In MATLAB

I have a cost function of 3 parameters, whose solution space is discontinuous and should have local minimums. In order to observe the space to get a grasp of how swampy the space is, I plot a scatter plot of many points in the solution space, and each point’s color indicates its value. Following this video, I also plot a slice to visualize the values in that slice. Here are the code and the plots.

Write Binary File In C++ And Read In MATLAB

Following this post, I’m able to write binary file in C++ to pass data to MATLAB. In C++, I have a cv::Mat matFloats of type float, I used the following code to store the data in a binary file. #include <fstream> ofstream outfile; outfile.open("data.dat", std::ios::out | std::ios::binary); outfile.write((char*)matFloat.data, 2 * contourCentered.size() * sizeof(float)); outfile.close(); And the following code in MATLAB reads the data and reshapes the array. fd = fopen('data.

Customizing Code Highlighting

I’ve been trying to customize the way code appears in my blog. My blog is based on hugo and hyde-hyde, which already has code highlighting based on highlight.js. I need to Add support for Swift Select my own display style Make inline code appear the same as block code Load custom highlight.js CSS Customize inline code border width and color Here is how I solved these problems.

Calling C++ in Swift

I’ve been developing an iOS app with image processing capability. The app is programmed in Swift 4, yet the image processing library is written in C++ for performance and compatibility concerns. Therefore there is a need to bridge C++ class to Swift. Since Swift cannot call C++ directly yet, we need an Objective-C wrapper (more specifically, an Objective-C++ wrapper) as the middleman. Therefore we will first talk about how to call Objective-C function from Swift, and then we’ll talk about how to call C++ from Objective-C++.

Starting an App in Swift

This post describes the simple procedures to start a minimalistic app in Swift. Launch XCode, and select Create a new Xcode project. Select Single View App in the view that follows, and click next. Key in the Product Name and other information and click next. If Team is left as None, then this project cannot run on phones, but can only run on simulators. On the upper left corner of the IDE, pick a simulator (e.