Ubuntu_1

##

1. Linux中的$PATH$HOME

$PATH: 指当前的环境变量
$HOME: 用户目录 /home/arcsinw,也就是~

以上都可以在bash中用echo打印出来

1
2
echo $PATH
echo $HOME

2. Ubuntu 安装golang时配置GOROOTGOPATH的问题

GOROOT:
GOPATH:

3. sudo: unable to resolve host ubuntu

原因是主机名与host中的不对应

修改主机名为ubuntu

1
vi /etc/hostname

或修改host,增加一条

1
127.0.0.1| ubuntu

再reboot

4. VMware 扩展Ubuntu虚拟机磁盘

1
sudo apt-get install gparted

扩展的unallocated空间在分区最右边的的位置,无法直接被合并到sda1
先把unallocated空间和左边相邻的分区(如sda2合并,合并后交换unallocatedsda2的位置(resize/move里鼠标拖动),再resize把unallocated这部分空间排挤出来,这样unallocated就和sda1相邻了,可以合并到sda1

5. ubuntu中减小root盘大小

使用gparted live cd启动虚拟机

6. 减小Vmware中Ubuntu虚拟机磁盘

分为三步:

1. Defragment (no need to un/remount anything)

1
sudo e4defrag /

Ignore any errors. Some files like symlinks and device files can’t be defragmented.

2. Zero-fill all unused space so VMware knows it’s indeed unused:

1
dd if=/dev/zero of=wipefile bs=1M; sync; rm wipefile

3. 在ubuntu虚拟机中, Run the shrink operation:

1
sudo vmware-toolbox-cmd disk shrinkonly

Reference

  1. https://superuser.com/questions/211798/how-to-reduce-the-size-of-vmware-disk

neural_network

Neural Network

1. Variables’ definitions

$a_i^{(j)}$ : “activation” of unit $i$ in layer $j$

$\theta^{(j)}$ : matrix mapping from layer $j$ to layer $j+1$, with size of $S_{j+1}$ x $(S_j + 1)$

$L$ : layers’ count

$S_l$ : count of units (exclude bias count) in layer $l$

$\delta_j^{l}$ : error of unit $j$ in layer $l$

sigmoid function : $g(z) = \frac{1}{1 + e^{-z}}$

$J(\theta)$: cost function

a neural network picture here

Forward propagation

$a_1^{(2)} = g(\theta_{10}^{(1)}x_0 + \theta_{11}^{(1)}x_1 + \theta_{12}^{(1)}x_2 + \theta_{13}^{(1)}x_3)$

$a_2^{(2)} = g(\theta_{20}^{(1)}x_0 + \theta_{21}^{(1)}x_1 + \theta_{22}^{(1)}x_2 + \theta_{23}^{(1)}x_3)$

$a_3^{(2)} = g(\theta_{30}^{(1)}x_0 + \theta_{31}^{(1)}x_1 + \theta_{32}^{(1)}x_2 + \theta_{33}^{(1)}x_3)$

$h_\theta(x) = a_1^{(3)} = g(\theta_{10}^{(2)}a_0^{(2)} + \theta_{11}^{(2)}a_1^{(2)} + \theta_{12}^{(2)}a_2^{(2)} + \theta_{13}^{(2)}a_3^{(2)})$

$z^{(2)} = \theta^{(1)}x$

$\theta^{(1)}$ is a matrix $S_{j+1}$x$(S_j+1)$ (bias unit for +1)

$$J(\theta) = \frac{1}{m} \sum_{i=1}^m \sum_{k=1}^K [-y^{(i)}k log((h\theta(x^{(i)}))_k) - (1 - y^{(i)}k) log(1 - (h\theta(x^{(i)}))k)] + \frac{\lambda}{2m} \sum{l=1}^{l-1} \sum_{i=1}^{S_l} \sum_{j=1}^{S_{l+1}} (\theta_{ji}^{(l)})^2$$

find $\theta$ to minimize $J(\theta)$

$$\frac{\partial J(\theta)}{\partial \theta} = a_j^{(l)} \zeta_i^{(l+1)}$$

Backpropagation

$$\delta_j = a_j - y_j$$

for example

$\delta_j^{(4)} = a_j^{(4)} - y_i$

$\delta_j^{(3)} = (\theta^{(3)})^T\delta^{(4)}.*g’(z^{(3)})$

$\delta_j^{(2)} = (\theta^{(2)})^T\delta^{(3)}.*g’(z^{(2)})$

cnn

Introduce

Convolutional neural networks (CNNs) are the current state-of-the-art model architecture for image classification tasks. CNNs apply a series of filters to the raw pixel data of an image to extract and learn higher-level features, which the model can then use for classification.

卷积神经网络是目前图片分类任务中最先进的模型架构,卷积神经网络对图片的原始像素数据应用一系列的过滤器来提取和学习更高级的特征,而这正是模型作分类时要用到的

Layers

1. input layer

原始的图片数据

2. Convolutional layers (卷积层)

将原始的图片数据提取成feature map

对图片作卷积操作,常常会加上一个ReLU激活函数对卷积层的输出进行一个非线性映射

$$f(x) = max(x, 0)$$

一个卷积核对应一个feature map

in tensorflow tf.layers.conv2d()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
tf.layers.conv2d(
inputs,
filters,
kernel_size,
strides=(1, 1),
padding='valid',
data_format='channels_last',
dilation_rate=(1, 1),
activation=None,
use_bias=True,
kernel_initializer=None,
bias_initializer=tf.zeros_initializer(),
kernel_regularizer=None,
bias_regularizer=None,
activity_regularizer=None,
kernel_constraint=None,
bias_constraint=None,
trainable=True,
name=None,
reuse=None
)
  • inputs:
  • filters: filter的数量
  • kernel_size: 卷积窗口大小(感受视野?)
  • strides: 步长,(高,宽) (纵向,横向)
  • padding: valid or same
  • data_format:

channels_last: shape(batch_size, height, width, channels)
channels_first: shape(batch_size, channels, height, width)

  • activation: 激活函数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
keras.layers.convolutional.Convolution2D(
nb_filter,
nb_row,
nb_col,
init='glorot_uniform',
activation=None,
weights=None,
border_mode='valid',
subsample=(1, 1),
dim_ordering='default',
W_regularizer=None,
b_regularizer=None,
activity_regularizer=None,
W_constraint=None,
b_constraint=None,
bias=True)
  • dim_ordering: ‘th’ or ‘tf’. In ‘th’ mode, the channels dimension (the depth) is at index 1, in ‘tf’ mode is it at index 3. It defaults to the image_dim_ordering value found in your Keras config file at ~/.keras/keras.json. If you never set it, then it will be “tf”.

3. Pooling layers (池化层)

in tensorflow tf.layers.max_pooling2d()

feature map降维以减少处理时间

池化层有与卷积层视野大小类似的东西,在tensorflow中叫pool_size

  • max pooling

  • average pooling

4. Dense (fully connected) layers(全连接层)

in tensorflow tf.layers.dense()

通常,CNN由一堆提取特征的卷积模块组成,每个卷积模块包括一个卷积层和紧接着的一个池化层,最后一个卷积模块后跟着一个或多个全连接层,CNN中的最后一个全连接层可以用来预测

Reference

  1. https://blog.csdn.net/cxmscb/article/details/71023576

2.https://www.tensorflow.org/tutorials/layers?hl=zh-cn

tensorflow_1

install

1
pip install tensorflow

显示tensorflow的版本

1
2
import tensorflow as tf
tf.__version__

##

tf.constant 定义常量
tf.Variable 定义变量
tf.placeholder 占位符,用于填充数据

  • 定义一个矩阵

  • sigmoid

Tensorboard

  1. 把计算过程用tf.name_scope包装起来
  2. 使用tf.summary.FileWriter输出到目标文件夹
  3. 启动Tensorboard

如果一个op中只有直接的赋值,那么这个op不会显示在Tensorboard中

1
tensorboard --logdir=/test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import tensorflow as tf
import os

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

if __name__ == '__main__':
const_A = tf.constant(10, name = 'const_A', dtype = tf.int64)

const_B = tf.constant(20, name = 'const_B', dtype = tf.int64)

placeholder_C = tf.placeholder(dtype = tf.int64)

with tf.name_scope('Add'):
_sum = const_A + const_B

with tf.Session() as session:
session.run(tf.global_variables_initializer())

const_sum = session.run(_sum)
print(const_sum)

train_writer = tf.summary.FileWriter('/test', session.graph)
train_writer.close()

Reference

1.https://dotblogs.com.tw/shaynling/2017/11/14/173025

2.https://www.tensorflow.org/api_docs/python/tf/matmul

opencv

1
cv2.CascadeClassifier.detectMultiScale(image[, scaleFactor[, minNeighbors[, flags[, minSize[, maxSize]]]]]) → objects
  • scaleFactor – Parameter specifying how much the image size is reduced at each image scale.

  • minNeighbors – Parameter specifying how many neighbors each candidate rectangle should have to retain it.

  • flags – Parameter with the same meaning for an old cascade as in the function cvHaarDetectObjects. It is not used for a new cascade.

  • minSize – Minimum possible object size. Objects smaller than that are ignored.

  • maxSize – Maximum possible object size. Objects larger than that are ignored.

1
cv.HaarDetectObjects(image, cascade, storage, scale_factor=1.1, min_neighbors=3, flags=0, min_size=(0, 0)) → detectedObjects