深度哈希-DSH
来源:互联网 发布:网络作家工作室 编辑:程序博客网 时间:2024/04/29 00:18
论文:Deep Supervised Hashing for Fast Image Retrieval CVPR2016
源代码: https://github.com/lhmRyan/deep-supervised-hashing-DSH
论文网络结构似乎是CIFAR-10和Siamese两种网络的结合:
个人认为有两个创新点:
1、通过设计损失函数,使得最后一层的输出Binary-like。
论文修改了ContrastIve Loss,加上正则项:
这个正则项会使得最终输出的特征b1,b2的取值趋向于-1和+1。
2、generate image pairs online
这里一开始以为使用的是类似Siamese的双分支的网络结构。实则不然,只是如图所示的单支网络,重点是在作者设计的损失函数中。网络的训练是Batch为单位的,比如说每次输入n张图片,对应n个标签,在Loss函数中,使用两层循环来不重复的生成所有可能的图片对(i,j),共
void HashingLossLayer<Dtype>::Forward_cpu( const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) { // initialize parameters Dtype* bout = bottom[0]->mutable_cpu_diff();//前向传播计算Loss的同时计算梯度 const int num = bottom[0]->num(); const Dtype alpha = top[0]->cpu_diff()[0] / static_cast<Dtype>(num * (num - 1));//top[0]->cpu_diff()[0]保存的是该损失层的权重,默认为1.0 const Dtype beta = top[0]->cpu_diff()[0] / static_cast<Dtype>(num); const int channels = bottom[0]->channels(); Dtype margin = this->layer_param_.hashing_loss_param().bi_margin(); Dtype tradeoff = this->layer_param_.hashing_loss_param().tradeoff();//两种损失(ContrastiveLoss与RegularizationLoss)权衡系数 const int label_num = bottom[1]->count() / num; bool sim; Dtype loss(0.0);//总损失 Dtype reg(0.0);//正则化损失 Dtype data(0.0);//输入向量每维的值 Dtype dist_sq(0.0);//两向量距离的平方 caffe_set(channels*num, Dtype(0), bout); // calculate loss and gradient for (int i = 0; i < num; ++i) { for (int j=i+1; j < num; ++j){ caffe_sub( channels, bottom[0]->cpu_data()+(i*channels), // a bottom[0]->cpu_data()+(j*channels), // b diff_.mutable_cpu_data()); // a_i-b_j dist_sq = caffe_cpu_dot(channels, diff_.cpu_data(), diff_.cpu_data()); //D_w^2 if (label_num > 1) { //多标签 sim = caffe_cpu_dot(label_num, bottom[1]->cpu_data() + (i * label_num), bottom[1]->cpu_data() + (j * label_num)) > 0; } else { sim = ((static_cast<int>(bottom[1]->cpu_data()[i])) == (static_cast<int>(bottom[1]->cpu_data()[j]))); } if (sim) { // similar pairs loss += dist_sq; // gradient with respect to the first sample caffe_cpu_axpby( channels, alpha, diff_.cpu_data(), Dtype(1.0), bout + (i*channels));//计算损失函数对输入向量i的梯度 // gradient with respect to the second sample caffe_cpu_axpby( channels, -alpha, diff_.cpu_data(), Dtype(1.0), bout + (j*channels));//计算损失函数对输入向量j的梯度 } else { // dissimilar pairs loss += std::max(margin - dist_sq, Dtype(0.0)); if ((margin-dist_sq) > Dtype(0.0)) { // gradient with respect to the first sample caffe_cpu_axpby( channels, -alpha, diff_.cpu_data(), Dtype(1.0), bout + (i*channels));//计算损失函数对输入向量i的梯度 // gradient with respect to the second sample caffe_cpu_axpby( channels, alpha, diff_.cpu_data(), Dtype(1.0), bout + (j*channels));//计算损失函数对输入向量j的梯度 } } }//内层循环结束 //只针对一个输入向量而言 for (int k = 0; k < channels;k++){ data = *(bottom[0]->cpu_data()+(i*channels)+k); // gradient corresponding to the regularizer //正则化部分的梯度 *(bout + (i*channels) + k) += beta * tradeoff * (((data>=Dtype(1.0))||(data<=Dtype(0.0)&&data>=Dtype(-1.0)))?Dtype(1.0):Dtype(-1.0)); data = std::abs(data)-1; reg += std::abs(data);//正则化部分的损失 } }//外层循环结束 //将两段损失各自取平均,然后相加 loss = loss / static_cast<Dtype>(bottom[0]->num()*(bottom[0]->num()-1)); loss += tradeoff * reg /static_cast<Dtype>(bottom[0]->num()); top[0]->mutable_cpu_data()[0] = loss;}
可以看到Online方式相比传统的方式收敛速度更快。这是由于每次输入到网络的图片总数目一致的情况下,比如2n张图片,Online方式可以给出
论文还提到,最后输出bit位数的设置过大的话容易过拟合,需要先训练bit位数较少的,然后在此基础上微调。
- 深度哈希-DSH
- Linux dsh工具安装
- dsh批量管理linux服务器
- 通过dsh批量管理Linux服务器
- 通过dsh批量管理Linux服务器
- 深度哈希-DHN
- 灵活使用ssh、dsh和pssh高效管理大量计算机
- 好用的集群管理工具dsh(分布式shell)
- 关于ACM转载很多的一篇文章和对dsh神牛的感想
- 十个啊打发撒地方噶爱的色放和dsh
- 【集群管理】数据挂载mount命令及批处理dsh命令
- 深度
- 局部敏感哈希深度解析(locality-sensetive hashing, LSH)(一)
- 中科院NIPS 2017论文提出深度离散哈希算法,可用于图像检索
- 关于深度、深度缓存和深度测试
- OpenGL中的深度、深度缓存、深度测试
- 今天第而波,来点有深度的,赶紧做哈.
- 深度优先搜索/广度优先搜索(解决小哈)
- android robotium获取相同id的的控件
- HBase学习总结(1):HBase的下载与安装
- android4.4 bluetooth 配置文件分析
- 17-23 Monkey源码分析
- LintCode | 632. Binary Tree Maximum Node
- 深度哈希-DSH
- 二叉树的遍历
- Flask源码分析(一)
- 通过信号量和共享内存实现h264码流在不同进程间传输
- DB2 应用最常见的几种状态
- POJ2349 Arctic Network(最小生成树,Kruskal)
- BZOJ P1025: [SCOI2009]游戏
- POJ1511 Subway
- VS2013+MITK+Qt5环境搭建