0%

Check the IP of Raspberry Pi is very painful because the IP of the Raspberry Pi will change automatically after a period of time if you didn’t assign a static IP to it. Checking the IP of the Raspberry Pi requires the keyboard, monitor, and it requires time to check it.

One way to solve this problem is let the Raspberry Pi to automatically send its IP to somewhere, like Google Sheet. This can make life better. Following are the steps to achieve it.

Connect the Raspberry Pi with WiFi

You need to use keyboard and monitor to set up the Raspberry Pi’s WiFi firstly, also check the IP, because we need to use the scp command to send file to Raspberry Pi.

Use gspread to send IP to google sheet

Set up googld cloud project

  • Head to Google Developers Console and create a new project.
  • Press the Google API icon of this new project and press “Enable APIs and services”
  • Enable Google Drive and Google Sheets API
  • Press the credentials icon and press “create credentials” and select “service account key”. Press create to download a json file for credentials

Set up python file

  • Download the pi_logger.py from this link, edit it
  • Use scp command to send this file together the json file to the Raspberry Pi
  • Install the requested libraries which are included in the pi_logger.py file.
    • Note: You need to use sudo pip3 to install the libraries, otherwise it cannot be ran by bash later
  • Ran python3 pi_logger.py to test it. Go to your Google Sheet you should find a file created and shared by Raspberry Pi

Write a bash file to launch the python file

  • Create a bash file named launcher.sh
  • In the file, type sudo python3 /home/pi/%your path%/pi_logger.py, save it
  • Type sh /home/pi/%your path%/launcher.sh to test the code, it should have the same result.
    • Note: if the terminal said there is error when importing libraries, you just need to uninstall relevant libraries and use sudo pip3 to install it back

Automatcally run the bash file

  • In Pi’s terminal, type sudo crontab -e
  • Type */2 * * * * /home/pi/justdiedbot/launcher.sh >/home/pi/logs/cronlog.log 2>&1, which means the Raspberry Pi will send do the sending action every 2 minutes

Reference

[1] https://www.instructables.com/id/Raspberry-Pi-Launch-Python-script-on-startup/
[2] https://raspberrypi.stackexchange.com/questions/78141/python-script-fails-with-importerror-when-run-from-rc-local

Multilayer Neural Network

  • Inherit tf.keras.Model can built own neural network
    • Every neural have several weights and a bias, and can handle a full input
  • Use tf.keras.Sequential()

Convolutional Neural Networks (CNN)

  • Can consider the relationship among several pixels
  • Special Layers:
    • Convolutional Layer
      • Won’t change the scale of the input if the stride is 1 * 1
    • Pooling Layer
      • Will generates more features but won’t increase the calculation

Recurrent Neural Networks (RNN)

  • Works well in the time-based classification
  • Make sense of what they’ve seen before, both short and long-term memory
  • Scenarios:
    • Video Processing
    • Speech Processing
    • Sentiment Analysis
    • Time series Data
  • Key Implements
    • What long term memory should be kept or removed
    • What new memory should be remembered as the long term memory
    • What new memory should be remembered as the short term memory

Below are some basic machine learning skills

  • Clustering
    • K-means
  • Instance-based Algorithms
    • KNN
  • Bayesian Algorithms
    • Naive Bayes
      • 假设输入的feature之间互相独立,因此概率的联合分布函数可以写成连乘
  • Regression
    • OLSR,最小二乘
    • Linear Regression
    • Logistic Regression
  • Decision Tree
    • ID3
    • C4.5
    • CART
  • Ensemble Algorithms:多个弱分类器共同构成强分类器
    • Boosting
    • Bagging
    • Random Forest
    • Gradient Boosted Regression Trees
  • Artificial Neural Network
    • Perceptron
  • SVM
  • Dimensionality Reduction Algorithms
    • PCA
    • PCR

Reference

机器学习算法集锦:从贝叶斯到深度学习及各自优缺点

Object detection is kind of classificitaion which you need to figure out where the object is located in the image. The output is usually described as:
$$
y = [P_c, P_x, P_y, W, H, c_1, c_2, c_3, …]
$$
$P_c$ means whether this image contain the content you’re detecting, $c_i$ the probability of the label_i object exists.

Object detection includes both localization and detection.

Sliding Windows Detection

Convolution Implementation

YOLO(You Only Look Once) Algorithm

Evaluationg Object Localization

$$
Intersection\ Over\ Union = \frac{size\ of\ overlaping\ area}{size\ of\ true\ and\ detection\ area}
$$

Non-max Suppression Algorithm

Overlapping Objects

Import a personal lib

Importing the .ipynb file we wrote as a module to a new .ipynb file is different from importing them in a .py file. The easiest way is to convert those .ipynb file to a .py file and you can import those in a new .ipynb file. However, this method doesn’t allow you to modify the code and reload it easily.

When the .ipynb lib file is in the same folder with you

For example, the lib’s name is test.ipynb. There is a function called hello() within it. In a new .ipynb file, you need to type the following.

1
2
3
4
5
6
7
# !pip install import-ipynb
import import_ipynb
import importlib
importlib.reload(test)
import test

test.hello()

The import_ipynb lib is allowing you to import a .ipynb file. The importlib file is allowing you to reload the module thus the new change to the lib file can be reloaded into your file.

When the .ipynb lib file is in the subfolder of current folder

For example, the lib file in the folder of lib. The lib’s name is test.ipynb. There is a function called hello() within it. In a new .ipynb file, you need to type the following.

Powershell is a more powerfull shell than CMD in Windows. However, the layout of powershell in Windows is very ugle, especially the default font. In order to change the font of powershell, we need to do several works.

Descipline

Actually the font can be change in the powershell if we click the top left corner of the powreshell interface. While if the CodePage is 936(Chinese), you can only change the font of powershell among several Chineses fonts, which are not well performed in the powershell.

So we need to find some way to change the CodePage of powershell to 437(English), then we can change the font to some English font like Consolas.

In order to change the default page to another, there are two steps need to finish that. One is for the powershell launched by Win+R, and another is the powershell launched by the start menu. It is because the software launched by shortcut follows other disciplines which I don’t know much.

Change for the Win+R powershell

  1. Open the Win+R, and input regedit
  2. Navigate to \HKEY_CURRENT_USER\Console\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe
  3. Create/Change the CodePage of type DWORD to decimal 437

Change for the shortcut powershell

  1. Right click the powershell in start menu and go to the file location
  2. Right clikc the ico and go the properties
  3. Add the following words to the end

-NoExit -Command "chcp 437; cls"

The command above means the powershell will run the two commands automatically. The chcp 437 means to swtich the Codepage to 437; and the cls means to clear the powershell.

There is a lot of development frameworks for Java. This post talks about Guice (for Dependency Injection design pattern implementation), Spring (Java integration environment), JUnit and Mockito (for unit test).

Read more »

Tree is a basic data structure. The most popular tree is the binary tree, which has a left child and a right child. The exercise usually gives you the root node of the tree. The basic method to solve a tree problem is recursive.

Traverse the tree

Iteration

1
2
3
4
5
6
openlist = [root]
while len(openlist) > 0:
node = openlist.pop() # openlist.pop(0) if you want BFS
check(node)
openlist.append(node.left)
openlist.append(node.right)

Recursive

1
2
3
4
def check_tree(node):
if node:
check_tree(node.left)
check_tree(node.right)

The above two ara both DFS(Deep First Search), in order to achieve the BFS(Breadth First Search), in other means, traverse the tree layer by layer, we need to use a dictionary to store the node

1
2
3
4
5
6
7
8
9
10
dic_tree = {}

def check_tree_breadth(node, depth=1):
if node:
if depth not in dic_tree:
dic_tree[depth] = [node.val]
else:
dic_tree[depth].append(node.val)
check_tree_breadth(node.left, depth+1)
check_tree_breadth(node.right, depth+1)

Check the leaf

1
2
3
4
5
6
7
8
9
leafs = []

def check_leaf(node):
if node:
if not node.left and not node.right:
leafs.append(node.val)
else:
check_leaf(node.left)
check_leaf(node.right)

Calculate the depth

Iteration

Establish a list to collect the tuple like (node: depth)

Recursive

1
2
3
4
5
def get_depth(node):
if node:
return 1 + max(get_depth(node.left), get_depth(node.right))
else:
return 0

Check the path

1
2
3
4
5
6
7
8
9
paths = []

def check_path(node, path=[]):
if node:
path.append(node.val)
check_path(node.left, path.copy())
check_path(node.right, path.copy())
else:
paths.append(path)