Learning Notes¶
c++ notes¶
1. Why should use member initialization list?¶
For POD class members, it makes no difference.
For class members which are classes, then it avoids an unnecessary call to a default constructor.
Furthermore, if a class doesn’t have a default constructor, or you have a const member variable, you must use an initializer list:
floating point number¶
浮点数最新标准为IEEE 754-2019
浮点数格式如下:
S(sign) | E (biased exponent) | T (trailing significand field) |
1 bit | w bits | t bits, t = p -1 |
具有如下关系:
关于biased E的说明:
- normal number: [1 , \(2^w - 2\)], 值为 \((-1)^s \times 2^{E-bias} \times (1+ 2^{1-p} \times T)\)
- 0, 当T=0表示 \(\pm 0\); 当T!=0 表示 subnormal number, 值为 \((-1)^s \times 2^{e_{min}} \times (0+ 2^{1-p} \times T)\)
- \(2^w − 1\) (二进制全部为1), 当T=0, 表示 \(\pm \infty\); 当T != 0, 表示 NaN.
ieee 规定的16, 32, 64, 128比特的浮点数格式列表¶
参数 | binary16 | binary32 | binary64 | binary128 |
---|---|---|---|---|
指数位数 | 5 | 8 | 11 | 15 |
emax/bias | 15 | 127 | 1023 | 16383 |
小数位数 | 10 | 23 | 52 | 112 |
Backpropagation的推导¶
约定¶
其中,\(z^l_j\) 表示未激活前第 \(l\) 层、第 \(j\) 个神经元的值,\(w^l_{jk}\) 为连接第 \(l\) 层第 \(j\) 个神经元和第 \(l+1\) 层第k个神经元的权重, \(a^l_k\) 表示激活后的第 \(l\) 层第 \(k\) 个神经元的值, \(b^l_j\) 为偏移量bias,\(\sigma\) 为激活函数。
注意和书籍 http://neuralnetworksanddeeplearning.com/chap2.html 中公式(23)的约定由区别,我们把weight和bias和神经元的值放到同一层中。
公式 (1) 写成矩阵形式为:
公式推导¶
我们约定C为损失函数(loss function),并记:
约定 Hadamard product 或者elementwise相乘为(重复指标不求和):
根据公式 (1) 可以直接得出对偏移量 \(b\) 的偏导数(梯度):
上式写成矩阵形式为:
对权重 \(w\) 的求导为:
上式写成矩阵形式为:
\(l\) 层 \(\delta^l\) 和 \(l+1\) 层的 \(\delta^{l+1}\) 的关系为:
上式写成矩阵形式为:
可以看出:
BP算法总结¶
BP算法可以概括为以下四个关系式:
可以看出,可以从 \(\delta^{l+1}\) 的推导出对第 \(l\) 层的权重和偏移量的偏导,以及第 \(l\) 层的未激活前的神经元的偏导。
convolution arithmetic¶
reference: |
---|
1. convolution¶
Set input data size \(i\), convolution kernel size \(k\), stride size \(s\), and zero padding size \(p\). Then the output size \(o\) is:
The floor function \({\lfloor}\,{\rfloor}\) can found at https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
2. pooling¶
According to (1), pooling output size is:
3. tansposed convolution¶
explanation: | The convolution operation can be rewritten to matrix multiplication. |
---|
4. dilated convolution¶
The dilation “rate” is controlled by an additional hyperparameter \(d\). A kernel of size k dilated by a factor d has an effective size:
Combined with (1) the output size is:
tensorrt 学习笔记¶
- nvinfer1:Dims 表示的是CHW的各个纬度,而不是NCHW!
- ModelImporter 类实现了nvonnxparser::IParser
- onnx parser 中增加对插件的支持,需要修改 builtin_op_importers.cpp
- 增加插件后,需要在文件 InferPlugin.cpp 注册插件
git tricks¶
How to delete all commit history in github?¶
1. Checkout
git checkout --orphan latest_branch
2. Add all files
git add -A
3. Commit the changes
git commit -am "commit message"
4. Delete the branch
git branch -D master
5. Rename the current branch to master
git branch -m master
6. Finally, force update your repository
git push -f origin master
linux notes¶
linux installer shell maker¶
How to disable gui when ubuntu desktop version booting¶
1. modify grub:
sudo vim /etc/default/grub
change
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
to
GRUB_CMDLINE_LINUX_DEFAULT="text"
update grub
sudo update-grub
2. disable lightdm service
sudo systemctl disable lightdm.service
3. If you want to start desktop
sudo servie lightdm start
4. To enable lightdm service, systemd has bug! ref: https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1595454 solution(root user or use sudo):
systemctl enable lightdm
ln -s /lib/systemd/system/lightdm.service /etc/systemd/system/display-manager.service
How to disable guest session¶
sudo vim /usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf
add:
allow-guest=false
ubuntu 18.04 disable xorg using nvidia card!¶
- create file /etc/X11/xorg.conf with the following content:
Section "Device"
Identifier "intel"
Driver "intel"
BusId "PCI:0:2:0"
EndSection
Section "Screen"
Identifier "intel"
Device "intel"
EndSection
fix time difference in Ubuntu & Windows Dual Boot¶
Ubuntu use the hardware clock (RTC, real time clock) in universal time (UTC) by default while Windows use the clock in local time.
easy solution in ubuntu
$ sudo timedatectl set-local-rtc 1