From 4a54b04036298344399f20cb0c035f5f7ce55f87 Mon Sep 17 00:00:00 2001 From: HypoX64 Date: Tue, 1 Sep 2020 18:09:59 +0800 Subject: [PATCH] Update --- Notes/dl/DML.md | 46 ++++++++++++++++++++++++++++------ Notes/github.md | 14 ++++++----- Notes/linux.md | 66 ++++++++++++++++++++++++++++++++++++------------- Notes/python.md | 4 +++ 4 files changed, 100 insertions(+), 30 deletions(-) diff --git a/Notes/dl/DML.md b/Notes/dl/DML.md index ba74a98..579fc95 100644 --- a/Notes/dl/DML.md +++ b/Notes/dl/DML.md @@ -13,11 +13,12 @@ ![image](./md_imgs/DML/knn.png) * **困难**:计算量过大,每次推理都需要用到数据库所有的数据,而且准确率很低 ### 真正的解决办法——Deep Metric Learning -**深度度量学习(deep metric learning)**的目标是学习一个从原始特征到低维稠密的向量空间(称之为嵌入空间,embedding space)的映射,使得同类对象在嵌入空间上使用常用的距离函数(欧氏距离、cosine距离等)计算的距离比较近,而不同类的对象之间的距离则比较远。深度度量学习在计算机视觉领域取得了非常多的成功的应用,比如**人脸识别、人脸验证、图像检索、签名验证、行人重识别等**以及最新的**Zero/few-shot/meta learning**上的应用。
+**深度度量学习(deep metric learning)**的目标是学习一个从原始特征到低维稠密的向量空间(称之为嵌入空间,embedding space)的映射,使得同类对象在嵌入空间上使用常用的距离函数(欧氏距离、cosine距离等)计算的距离比较近,而不同类的对象之间的距离则比较远。深度度量学习在计算机视觉领域取得了非常多的成功的应用,比如**人脸识别、人脸验证、图像检索、签名验证、行人重识别等**以及最新的**one/few-shot/meta learning**上的应用。
#### 如何使用DML进行图像分类? imageimage ![image](./md_imgs/DML/dml_eg_1.jpg) + ### 支付宝是怎么做到快速从数亿张脸中找到我的脸的? ![image](./md_imgs/DML/fecere.jpg) **简单来说就是 预处理+编码为向量 + 先验条件缩小搜索范围 + 高效率的向量相似度搜索的算法(Facebook的Faiss)** @@ -31,30 +32,61 @@ * 并行化及专用芯片加速:将搜索过程交给高度并行化的算法及服务器或者专用的加速芯片 * 兜底策略:输入手机尾号 ## DML-Algorithm -**学习一个度量相似度的距离函数:相似的目标离得近,不相似的离得远.** +**学习一个度量相似度的距离函数:相似的目标离得近,不相似的离得远.**
+ ### General Pipeline ![image](./md_imgs/DML/General_Pipeline.jpg) -* 1.将Sample mini-batch(一般是C类每类挑K个,共N个数据)提取网络来map embedding +* 1.将Sample mini-batch(一般是C类每类挑K个,共N个数据)提取网络来map embedding然后通过L2-normalization来归一化网络的输出 * 2.将每个数据都依次作为anchor(锚点)并使用采样策略组成多个sub-set * 3.在每个sub-set上计算loss ### Embedding -**可以是现在常用的网络结构,如ResNet50等**但是要训练有素的 +* network +可以是现在常用的网络结构,如ResNet50或GoogLeNet等.但是一定要**pre-trained**否则收敛会很慢 +* L2-normalization + +
+image +
+image +**L2-normalization得到了单位向量,其L2距离就和cos相似度成正比。** + ### Loss #### 1.Contrastive loss ![image](./md_imgs/DML/Contrastive loss.jpg) **contrastive loss只考虑了输入样本对本身的相似性** + + #### 2.Triplet loss ![image](./md_imgs/DML/Triplet loss.jpg) **Triplet-Loss的效果比Contrastive Loss的效果要好,因为他考虑了正负样本与锚点的距离关系。** -#### 3.Triplet loss + +#### 3.N-pair-ms loss +![image](./md_imgs/DML/N-pair-ms loss.jpg) +#### other +Margin Based Loss, Lifted Struct loss, Proxy NCA loss, Ranked list loss, Multi-Similarity loss + ### Sampling matters **提高数据的利用率来加速网络收敛** -### Experiment Setting +#### 1.Naive sampling +按loss里面的项每一对样本都算距离,那么就是NXN对. 对triplet loss来说就是正样本两两之间然后再随机采样一个负样本,也是NXN个triplet +#### 2.Semi-hard sampling +在距离margin()里,对一个anchor,loop所有剩下正样本就构建了N个正样本对,然后每对正样本对采样一个负样本 +#### 3.N-pairs sampling +基于anchor,loop后在每个负类中挑(一般是1)个 +#### other +Softhard Sampling, Distance weighted sampling... +![image](./md_imgs/DML/Sampling.jpg) +### Experiment Setting +* Dataset: Stanford Online Products, CARS196, and the CUB200-2011 +* Eval:一般是Recall@K和NMI(一般用k-means聚类)(For Recall@K,Each test image (query) first retrieves K nearest neighbors from the test set and receives score 1 if an image of the same class is retrieved among the K nearest neighbors and 0 otherwise. Recall@K averages this score over all the images \cite{lifted}.NMI is normalized mutual information to evaluate the clustering result with given ground truth clustering . and denotes mutual information and entropy respectively.) ## Reference [1]打个酱油, Deep Metric Learning, https://zhuanlan.zhihu.com/p/68200241 [2]赵赫 Mccree, Face Recognition Loss on Mnist with Pytorch, https://zhuanlan.zhihu.com/p/64427565 [3]杨旭东, 深度度量学习中的损失函数, https://zhuanlan.zhihu.com/p/82199561 [4]find goo, 支付宝是怎么做到快速从数亿张脸中找到我的脸的?,https://www.zhihu.com/question/359431172/answer/935555297 -[5]face_recognition, ageitgey, https://github.com/ageitgey/face_recognition#face-recognition \ No newline at end of file +[5]ageitgey, face_recognition, https://github.com/ageitgey/face_recognition#face-recognition +[6]NIPS'2016, Improved Deep Metric Learning with Multi-class N-pair Loss Objective +[7]ICCV'2017, Sampling Matters in Deep Embedding Learning +[8]Confusezius, Deep-Metric-Learning-Baselines, https://github.com/Confusezius/Deep-Metric-Learning-Baselines \ No newline at end of file diff --git a/Notes/github.md b/Notes/github.md index e9e5c6d..d383049 100644 --- a/Notes/github.md +++ b/Notes/github.md @@ -75,17 +75,19 @@ git merge online_repo1 ## 插入链接图片 [百度](http://baidu.com) -插入网络图片:![](网络图片链接地址),即叹号!+方括号[]+括号(),如果不加叹号!就会变成普通文本,方括号里可以加入一些 标识性的信息 +* 插入网络图片:![](网络图片链接地址),即叹号!+方括号[]+括号(),如果不加叹号!就会变成普通文本,方括号里可以加入一些 标识性的信息 ![baidu](http://www.baidu.com/img/bdlogo.gif "百度logo") -插入GITHub仓库里的图片:![](图片链接地址),即叹号!+方括号[]+括号(),URL写法:http://github.com/自己的用户名/项目名/raw/分支名/存放图片的文件夹/文件夹里的图片名字 - -给图片加上超链接:即点击一个图片进入指定网页,方括号里写自己起的标识名称,上下两行标识要一致。 +* 插入GITHub仓库里的图片:![](图片链接地址),即叹号!+方括号[]+括号(),URL写法:http://github.com/自己的用户名/项目名/raw/分支名/存放图片的文件夹/文件夹里的图片名字 +* 给图片加上超链接:即点击一个图片进入指定网页,方括号里写自己起的标识名称,上下两行标识要一致。 [![baidu]](http://baidu.com) -[baidu]:http://www.baidu.com/img/bdlogo.gif "百度Logo" - +[baidu]:http://www.baidu.com/img/bdlogo.gif "百度Logo"
+* 图片居中 +
+image +
## 插入代码片段 插入代码片段:在代码上下行用```标记,注意`符号是tab键上面那个,要实现语法高亮,则在```后面加上编程语言的名称 diff --git a/Notes/linux.md b/Notes/linux.md index f017c63..7c2a919 100644 --- a/Notes/linux.md +++ b/Notes/linux.md @@ -1,23 +1,33 @@ [TOC] ### 用户 -* 添加用户 +#### 查看当前所有用户 +cat /etc/passwd +#### 添加用户 ```bash sudo adduser hypo ``` -* 更改密码 +#### 更改密码 ```bash sudo passwd hypo ``` -* 更改用户权限 +#### 更改用户权限 ```bash cd /etc sudo vim sudosers hypo ALL=(ALL:ALL) ALL ``` -* 删除用户 +#### 删除用户 ```bash sudo userdel -r hypo ``` +### 文件夹权限 +```bash +#开放文件夹及子文件夹所有权限 +chmod -R 777 hypo #4是读权限,2是写权限,1是可执行权限,777就是所有权限都开,766或776才是开放其他用户的读写权限,777是开放所有权限 +#错误使用例子 +chmod -R 777 / #开放整个系统所有权限,完蛋 +chown -R mysql / #锁死所有权限,完蛋 +``` ### 安装显卡驱动 ```bash sudo add-apt-repository ppa:graphics-drivers/ppa @@ -25,7 +35,23 @@ sudo apt update ubuntu-drivers devices#选择推荐的驱动版本 sudo apt install nvidia-430 ``` -### 挂载U盘 +### 分区/挂载U盘/硬盘 +#### 分区 +```bash +fdisk -l +#先查看下是否有磁盘没有分区如果没有 +#device Start End Sectors Size Type +#则该磁盘没有分区 +fdisk /dev/sdb +#输入m,可以查看有哪些操作 +#输入p 查看当前硬盘分区,目前没有分区 +#输入n新建一个分区,输入p 建立分区,输入分区编号 1 +#设置扇区起始和结束,默认就是最大化的分区 +#输入p然后打印分区数,红色框就是已经建立好的分区 +#最后保存分区 输入w +mkfs.ext4 /dev/sdb1 +``` +#### 挂载 ```bash root@lthpc:/home/hypo# fdisk -l ... @@ -33,15 +59,15 @@ Device Start End Sectors Size Type /dev/sdc1 2048 7813967871 7813965824 3.7T Microsoft basic data root@lthpc:/home/hypo# cd /media root@lthpc:/media# mkdir usb -root@lthpc:/media# mount -t ntfs-3g /dev/sdc1 /media/usb - +root@lthpc:/media# mount -t ntfs-3g /dev/sdc1 /media/usb +# ext4 ext2 xfs #卸载挂载点 $ umount /dev/hda2 $ umount /usr #参数可以是设备文件或安装点 ``` ### linux应用设置 -* goldendict +#### goldendict ```bash # 安装 sudo apt install goldendict @@ -75,13 +101,13 @@ ps aux|grep python|grep -v grep|cut -c 9-15|xargs kill -15 #“kill -15”会正常退出指定进程,-9强行杀掉 ``` ### 常用系统命令 -* 删除文件 +#### 删除文件 ```bash -rm -rf yourdir -#-r 就是向下递归,不管有多少级目录,一并删除 -#-f 就是直接强行删除,不作任何提示的意思 +rm -rf yourdir#-r 就是向下递归,不管有多少级目录,一并删除 -f 就是直接强行删除,不作任何提示的意思 + +find -name "*.pth" -delete #批量删除后缀为pth的所有文件 ``` -* cp mv +#### cp mv ```bash # cp复制  mv剪切 cp [options] @@ -100,7 +126,7 @@ cp -rf dir1 dir #复制文件夹dir1到dir2,不显示进度 #-s 复制成符号连结文件 (symbolic link),亦即『快捷方式』档案; #-u 若 destination 比 source 旧才更新 destination。 ``` -* deb +#### deb ```bash sudo apt-get install -f #解决依赖关系 dpkg -i #安装一个 Debian 软件包,如你手动下载的文件。 @@ -133,6 +159,10 @@ $ sudo systemctl enable teamviewerd.service ``` ### 压缩解压 ```bash +#7z +安装:apt-get install p7zip-full +解压7z:使用方法:7z x file.7z + #.tar .tar.xz tar xvf filename.tar #.tar 解包 tar cvf filename.tar dirname #.tar 打包 @@ -165,8 +195,9 @@ tar cvf - test.txt | pigz > test.tar.gz tar -I pigz -xvf /path/to/archive.tar.gz -C /where/to/unpack/it/ ``` ### rdesktop(Windows远程桌面) -``` +```bash rdesktop -u Administrator -p password ip -g 1280x720 +-r sound:local:alsa #远程声音 ``` ### vim * 模式 @@ -177,6 +208,7 @@ rdesktop -u Administrator -p password ip -g 1280x720 * 保存退出 保存退出都要在命令模式下完成。保存用 :w path/to.txt,退出用 :q。如果是编辑已经存在的文件可以直接用 :wq 退出。 ### ssh +#### install & run * install ```bash sudo apt-get install openssh-client @@ -203,7 +235,7 @@ ssh -p 1234 hypo@192.168.0.1 * exit ```bash 'Ctrl+D' -#or +#orchmod -R 777 /home/mypackage exit ``` * ssh-keygen @@ -219,7 +251,7 @@ nohup python3 a.py & ```bash firefox & ``` -* transmit files +#### transmit files ```bash #压缩+解压流传输 把本地的文件复制到远程主机上 tar -c './dir' |pigz |ssh hypo@172.31.73.116 "gzip -d|tar -xC /home/hypo/MyProject" diff --git a/Notes/python.md b/Notes/python.md index 7907855..f4215e8 100644 --- a/Notes/python.md +++ b/Notes/python.md @@ -257,6 +257,7 @@ args , _ = parse.parse_known_args(sys.argv[1:]) SAVEDIR = args.savedir ``` ## numpy +[参考手册](https://docs.scipy.org/doc/numpy-1.17.0/reference/) * zeros/ones ```python np.zeros(shape, dtype=float, order='C') @@ -285,6 +286,8 @@ a.reshape #修改形状 #按照数组的第一列进行排序 data = data[np.argsort(data[:,0])] ``` +## scipy +[参考手册](https://docs.scipy.org/doc/scipy-1.4.1/reference/) ## pyinstaller @@ -362,6 +365,7 @@ cv2.imshow("Green", cv2.merge([zeros, G, zeros])) cv2.imshow("Red", cv2.merge([zeros, zeros, R])) ``` ## matplotlib +[实例库](https://matplotlib.org/gallery/index.html) ### colors markers ```python colors= ['blue','orange','green','red','purple','brown','pink','gray','olive','cyan'] -- GitLab