NarcissusInMirror / DailyWorkLog

0 stars 0 forks source link

2019春季学期-3月&4月 #1

Open NarcissusInMirror opened 5 years ago

NarcissusInMirror commented 5 years ago

2019.3.21工作日志

NarcissusInMirror commented 5 years ago

2019.3.24工作日志

获取输出

x = base_model.output

添加适合自己研究的全连接层

flatten_1 = Flatten()(x) dense_1 = Dense(512)(flatten_1) activation_1 = Activation('relu')(dense_1) drop_2 = Dropout(0.5)(activation_1) dense_2 = Dense(4)(drop_2) activation_2 = Activation('sigmoid')(dense_2)

使用functional API

model = Model(inputs=base_model.input, outputs=activation_2)

sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True) model.compile(loss='binary_crossentropy', optimizer=sgd, metrics=['accuracy'])

fit时需注意,输入是两个,[x_train, x_aux], 输出是一个 y_train,因为是共享标签的

validation_data=([x_test, x_aux_test], y_test)也是一样的

model.fit([x_train, x_aux], y_train, batch_size=32, nb_epoch=50,callbacks=[TensorBoard(log_dir='./log_dir', write_graph=True)],validation_data=([x_test, x_aux_test], y_test))

NarcissusInMirror commented 5 years ago

2019.3.25工作日志

阅读论文:Simultaneous Optical Flow and Intensity Estimation from an Event Camera, Bardow et. al.
NarcissusInMirror commented 5 years ago

2019.3.26工作日志

了解了一下正则项相关的问题。在另一个issue里也有提到这个问题

试图在keras下编写一个generator,失败

NarcissusInMirror commented 5 years ago

2019.3.28 工作日志

python的集合数据结构

label_lists = os.listdir(IMAGE_DIR) label_set = set() for i in label_lists: label_set.add(i) print(image_lists^label_set) # ^运算符,得到不同时包含于两个集合中的元素

NarcissusInMirror commented 5 years ago

2019.3.29工作日志

python调用子import中的模块
NarcissusInMirror commented 5 years ago

2019.4.1工作日志

深度解读CMOS图像传感器,这些知识你都知道吗?

NarcissusInMirror commented 5 years ago

2019.4.2工作日志

毕设进度:

current_time = datetime.datetime.now() year = str(current_time.year) month = str(current_time.month) day = str(current_time.day) hour = str(current_time.hour) minute = str(currenttime.minute) timestamp = year + '' + month + '' + day + '' + hour + '_' + minute os.makedirs('record_files/weight_files/' + timestamp)

* 修改了损失函数,在独立测试集上的准确率提升了3~6个百分点
[Keras中自定义复杂的loss函数](https://spaces.ac.cn/archives/4493)
def mycrossentropy(y_true, y_pred, e=0.1):
    loss1 = K.binary_crossentropy(y_true, y_pred)
    loss2 = K.binary_crossentropy(K.ones_like(y_pred)/nb_classes, y_pred)
    return (1-e)*loss1 + e*loss2

model.compile(loss=mycrossentropy, optimizer=sgd, metrics=['accuracy'])

![image](https://user-images.githubusercontent.com/28808216/55390310-8acb0a00-5569-11e9-8095-3c4647f22272.png)
NarcissusInMirror commented 5 years ago

2019.4.3工作日志

https://stackoverflow.com/questions/15584608/python-opencv2-cv2-cv-fourcc-not-working-with-videowriter https://blog.csdn.net/Lay_ZY/article/details/53884420 https://docs.opencv.org/2.4.9/modules/highgui/doc/reading_and_writing_images_and_video.html#cv2.imwrite https://blog.csdn.net/u010167269/article/details/53268686

https://www.jianshu.com/p/7eec907827ee http://ufldl.stanford.edu/wiki/index.php/Exercise:PCA_and_Whitening http://ufldl.stanford.edu/wiki/index.php/PCA

NarcissusInMirror commented 5 years ago

2019.4.4 工作日志

opencv处理图像和视频

opencv官方文档

numpy的mask操作2️⃣

现有需求如下:需要将数组分为三个部分并进行赋值,大于threhold值的变为255,小于-threhold值的变为128,中间的值变为0。numpy数组支持形如array[array > threhold] = 255array[array < threhold] = 128的操作,但不支持array[-threhold < array < threhold] = 0的操作,也不支持array[-threhold < array and array < threhold] = 0,故需要用到mask,代码如下

mask_array = np.ma.array(minus_frame, mask=(minus_frame < threshold.threshold))
mask_array_2 = np.ma.array(minus_frame, mask= (minus_frame > - threshold.threshold))
mask = mask_array.mask & mask_array_2.mask

分析:

>>> import numpy as np
>>> a = np.array([1, 2, 3, 4, 5, 6, 7])
>>> b = np.ma.array(a, mask=(a < 3))
>>> b
masked_array(data=[--, --, 3, 4, 5, 6, 7],
             mask=[ True,  True, False, False, False, False, False],
       fill_value=999999)

由以上代码可以看出,maskarray由三部分组成,data,mask和fill_value,可以通过.进行访问

NarcissusInMirror commented 5 years ago

2019.4.8工作日志

NarcissusInMirror commented 5 years ago

2019.4.9工作日志

NarcissusInMirror commented 5 years ago

2019.4.10工作日志

linux中为命令添加别名
NarcissusInMirror commented 5 years ago

2019.4.11工作日志

完成中期答辩
关于TeX: The TeX family tree: LaTeX, pdfTeX, XeTeX, LuaTeX and ConTeXt
关于MacTeX的安装

吐槽一下:MacTex真的超级良心啊啊啊啊!就凭一个What is installed就把我圈粉了好吗!把安装的位置讲得那么清楚!我太希望所有软件都能有这么一个文档了! 主要分为两个部分:TeXLive-2018(可以理解为主题的程序)和GUI-Applications(相当于IDE)

NarcissusInMirror commented 5 years ago

2019.4.12工作日志

完善码率控制代码逻辑,加入降低阈值操作
python 三元运算符
a = 为真时的结果 if 判定条件 else 为假时的结果 
>>> result = 1 if 5>3 else 0
>>> result
1
NarcissusInMirror commented 5 years ago

2019.4.16工作日志

使用numpy的函数对图像进行减去均值的操作 使用到了numpy的以下函数:

有如下数组:(为明显起见,将数组用空行分为三段,代表三张图片)

>>> a = np.array([[[[10, 11, 12], [13, 14, 15]],
        [[16, 17, 18], [19, 20, 21]]],

        [[[22, 23, 24], [25, 26, 27]],
        [[28, 29, 30], [31, 32, 33]]],

        [[[34, 35, 36], [37, 38, 39]],
        [[40, 41, 42], [43, 44, 45]]]])

形状为(3, 2, 2, 3),其中四个维度分别为(图片数目,行, 列, 通道数) 因此这里我们模拟的是3张223的图片,第一张图片的三各通道分别为

[[10, 13],
 [16, 19]]

[[11, 14],
 [17, 20]]

[[12, 15],
 [18, 21]]

其他两张图片类似。

均值函数的使用方法为np.mean(ndarray, axis),这里比较关键的是axis的值。数组的axis是如何规定的呢?从最外层到最内层依次是0~n。这里的最内层,指的是最小的括号,最小的括号所包含的素个数即为第n维的维度。以此类推,倒数第二小的括号所包含的元素个数即为第n-1维的维度。 以以上数组为例,最小的括号是[10, 11, 12],包含3个元素,所以最后四维的维度是3,对应的axis为3,倒数第二小的括号包含[10, 11, 12], [13, 14, 15]这两个元素,所以倒数第第三维的维度是2,对应的axis为2 同理,第二维的维度也是2,对应的axis为1,第一维的维度为3,对应的axis为0。 我们所要计算的的是一个三通道图像每一个通道图像像素的均值,因此这里的axis应该选择第二和第三维,对应axis=(1, 2)

>>>a_mean = np.mean(a, axis=(1,2))
[[14.5 15.5 16.5]
 [26.5 27.5 28.5]
 [38.5 39.5 40.5]]

经过均值计算后,我们得到了一个(3, 3)的数组,这里第一维的3代表图片的数目,第二维的3代表通道个数,下面我们需要把均值减掉,很明显,直接进行相减是行不通的。需要把均值数组reshape成图片的大小。在此之前,要用的np.tile(ndarray, tuple)函数

>>> a_mean_tile = np.tile(a_mean, (1, 4))
[[14.5 15.5 16.5 14.5 15.5 16.5 14.5 15.5 16.5 14.5 15.5 16.5]
 [26.5 27.5 28.5 26.5 27.5 28.5 26.5 27.5 28.5 26.5 27.5 28.5]
 [38.5 39.5 40.5 38.5 39.5 40.5 38.5 39.5 40.5 38.5 39.5 40.5]]

tile函数的逻辑如下,参数列表中的元组是对各个维度的重复次数,这里的4表示对最小括号里的内容重复4次,因为图片的大小为2*2=4对于尺寸为mn的图片,这里参数改为mn即可;1表示对次小括号里的内容重复1次,若输入整数则默认对最小括号内的内容进行重复,其余维度保持不变。在本例中,原数组是二维的,如果输入的元组的维度大于2,就会增加数组的维度,例如:

>>>  a_mean_tile = np.tile(a_mean, (1, 1, 4))
[[[14.5 15.5 16.5 14.5 15.5 16.5 14.5 15.5 16.5 14.5 15.5 16.5]
  [26.5 27.5 28.5 26.5 27.5 28.5 26.5 27.5 28.5 26.5 27.5 28.5]
  [38.5 39.5 40.5 38.5 39.5 40.5 38.5 39.5 40.5 38.5 39.5 40.5]]]

最后,进行reshape操作,图片数目的维度填入-1即可

>>> a_mean_tile_reshape = np.reshape(a_mean_tile, (-1, 2, 2, 3))
[[[[14.5 15.5 16.5]
   [14.5 15.5 16.5]]

  [[14.5 15.5 16.5]
   [14.5 15.5 16.5]]]

 [[[26.5 27.5 28.5]
   [26.5 27.5 28.5]]

  [[26.5 27.5 28.5]
   [26.5 27.5 28.5]]]

 [[[38.5 39.5 40.5]
   [38.5 39.5 40.5]]

  [[38.5 39.5 40.5]
   [38.5 39.5 40.5]]]]

完整代码如下:

a = np.array([[[[10, 11, 12], [13, 14, 15]],
        [[16, 17, 18], [19, 20, 21]],
        [[22, 23, 24], [25, 26, 27]]],
            [[[28, 29, 30], [31, 32, 33]],
        [[34, 35, 36], [37, 38, 39]],
        [[40, 41, 42], [43, 44, 45]]],
            [[[46, 47, 48], [49, 50, 51]],
        [[52, 53, 54], [55, 56, 57]],
        [[58, 59, 60], [61, 62, 63]]]])

a_mean = np.reshape(np.tile(np.mean(a, axis=(1,2)), (1, 6)), (-1, 3, 2, 3))
b = a - a_mean_tile_reshape
NarcissusInMirror commented 5 years ago

2019.4.17工作日志

numpy, scipy, scikit-learn, pandas...

Screenshot 2019-04-17 at 11 24 40

如何理解主成分分析中的协方差矩阵的特征值的几何含义? Deep Learning Tutorial - PCA and Whitening

使用iMovie
学习概率论,矩估计和似然估计
NarcissusInMirror commented 5 years ago

2019.4.18工作日志

NarcissusInMirror commented 5 years ago

2019.4.19 & 2019.4.21工作日志

NarcissusInMirror commented 5 years ago

2019.4.22工作日志

使用sklearn进行k-fold验证,增加每次shuffle后数据的利用率

$ conda install scikit-learn

K-Fold官方文档 使用较为简单:

>>> from sklearn.model_selection import KFold
>>> kf = KFold(n_splits=5) # n_splits是数据分割的数目如果用20%的数据作为验证集,就设为5即可
>>> kf.get_n_splits()
5
>>> x = np.array(...)
>>> X = np.array([[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]])
>>> y = np.array([1, 2, 3, 4, 5]) 
>>> print(kf)  
KFold(n_splits=5, random_state=None, shuffle=False) # 如果不shuffle数据的话后两个参数用不到
>>> for train_index, test_index in kf.split(X):
...    print("TRAIN:", train_index, "TEST:", test_index)
...    X_train, X_test = X[train_index], X[test_index]
...    y_train, y_test = y[train_index], y[test_index]
TRAIN: [1 2 3 4] TEST: [0]
TRAIN: [0 2 3 4] TEST: [1]
TRAIN: [0 1 3 4] TEST: [2]
TRAIN: [0 1 2 4] TEST: [3]
TRAIN: [0 1 2 3] TEST: [4]
# 这个函数实则生成的就是n_split组数组的index

shell显示行数的问题

linux下vim和bash配置文件 这篇文章里还有许多其他的配置值得研究。

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

初步完成了上周五讨论的总结

计算机视觉领域常见期刊和会议

NarcissusInMirror commented 5 years ago

2019.4.23工作日志

继续进行数据的shuffle和交叉验证

思考是否是进行多示例学习进行辅助分类

NarcissusInMirror commented 5 years ago

2019.4.24工作日志

随机种子

毕设

Mac创建新的文本文件

去北大拷回了测试脉冲序列

NarcissusInMirror commented 5 years ago

2019.4.25工作日志

分析脉冲序列特性

NarcissusInMirror commented 5 years ago

2019.4.27工作日志

Fine-Tuning

NarcissusInMirror commented 5 years ago

2019.4.29工作日志

编写了计算输出AUC的脚本

关于keras!!!!!

https://en.wikipedia.org/wiki/Logit https://github.com/keras-team/keras/blob/master/keras/metrics.py https://stackoverflow.com/questions/42081257/keras-binary-crossentropy-vs-categorical-crossentropy-performance https://stackoverflow.com/questions/45741878/using-binary-crossentropy-loss-in-keras-tensorflow-backend

tf.nn.sigmoid binary cross entropy logit probability