title: Triplet Selection
grammar_cjkRuby: true
---

样本选取的理想情况:



a minimal number of exemplars of any one identity is present in each mini-batch

单个个体的全部样本必须存在于每个mini-batch中

In our experiments we sample the training data such that around 40 faces are selected per identity per minibatch. Additionally, randomly sampled negative faces are added to each mini-batch.

每个mini-batch中每个个体有40张图片,先组成A-P对,然后再随机抽取负样本到mini-batch中组成(A,P,N)三元组。

Instead of picking the hardest positive, we use all anchor-positive pairs in a mini-batch while still selecting the hard negatives. We found in practice that the all anchor-positive method was more stable and converged slightly faster(收敛更快) at the beginning of training

所有的A-P对和满足条件的A-N对

具体过程:
先从训练数据集中抽样出一组图片到mini-batch中,计算这些图片在当时的网络模型中得到的embedding,保存在emb_array当中。
每个mini-batch有多类图,每类图有多张

st=>start: mini-batch中第i类图的第j张图片
e=>end: 得到三元组(A.P.N)
op=>operation: 此图片和其他所有图片(这个mini-batch中的)的欧氏距离
op1=>operation: 此图片与同类其他图片组成(anchor,postive)图片,记为(A,P)
op2=>operation: 此图片与其他类的图片组成(anchor,negtive)图片,记为(A,N)st->op->op1->op2->e

(A,N)需满足的条件:

 all_neg = np.where(neg_dists_sqr-pos_dist_sqr<alpha)[0] # VGG Face
#多少人,alpha参数
def select_triplets(embeddings, nrof_images_per_class, image_paths, people_per_batch, alpha):""" Select the triplets for training"""trip_idx = 0#某个人的图片的embedding在emb_arr中的开始的索引emb_start_idx = 0num_trips = 0triplets = []# VGG Face: Choosing good triplets is crucial and should strike a balance between#  selecting informative (i.e. challenging) examples and swamping training with examples that#  are too hard. This is achieve by extending each pair (a, p) to a triplet (a, p, n) by sampling#  the image n at random, but only between the ones that violate the triplet loss margin. The#  latter is a form of hard-negative mining, but it is not as aggressive (and much cheaper) than#  choosing the maximally violating example, as often done in structured output learning.#遍历每一个人for i in xrange(people_per_batch):#这个人有多少张图片nrof_images = int(nrof_images_per_class[i])#遍历第i个人的所有图片for j in xrange(1,nrof_images):#第j张图的embedding在emb_arr 中的位置a_idx = emb_start_idx + j - 1#第j张图跟其他所有图片的欧氏距离neg_dists_sqr = np.sum(np.square(embeddings[a_idx] - embeddings), 1)#遍历每一对可能的(anchor,postive)图片,记为(a,p)吧for pair in xrange(j, nrof_images): # For every possible positive pair.#第p张图片在emb_arr中的位置p_idx = emb_start_idx + pair#(a,p)之前的欧式距离pos_dist_sqr = np.sum(np.square(embeddings[a_idx]-embeddings[p_idx]))#同一个人的图片不作为negative,所以将距离设为无穷大neg_dists_sqr[emb_start_idx:emb_start_idx+nrof_images] = np.NaN#all_neg = np.where(np.logical_and(neg_dists_sqr-pos_dist_sqr<alpha, pos_dist_sqr<neg_dists_sqr))[0]  # FaceNet selection#其他人的图片中有哪些图片与a之间的距离-p与a之间的距离小于alpha的all_neg = np.where(neg_dists_sqr-pos_dist_sqr<alpha)[0] # VGG Face selecction#所有可能的negativenrof_random_negs = all_neg.shape[0]#如果有满足条件的negativeif nrof_random_negs>0:#从中随机选取一个作为nrnd_idx = np.random.randint(nrof_random_negs)n_idx = all_neg[rnd_idx]# 选到(a,p,n)作为三元组triplets.append((image_paths[a_idx], image_paths[p_idx], image_paths[n_idx]))#print('Triplet %d: (%d, %d, %d), pos_dist=%2.6f, neg_dist=%2.6f (%d, %d, %d, %d, %d)' % #    (trip_idx, a_idx, p_idx, n_idx, pos_dist_sqr, neg_dists_sqr[n_idx], nrof_random_negs, rnd_idx, i, j, emb_start_idx))trip_idx += 1num_trips += 1emb_start_idx += nrof_imagesnp.random.shuffle(triplets)return triplets, num_trips, len(triplets)

更多代码解释请看:http://www.cnblogs.com/irenelin/p/7831338.html

转载于:https://www.cnblogs.com/1273545169stt/p/8394984.html

Triplet Selection相关推荐

  1. CV之FRec之ME/LF:人脸识别中常用的模型评估指标/损失函数(Triplet Loss、Center Loss)简介、使用方法之详细攻略

    CV之FRec之ME/LF:人脸识别中常用的模型评估指标/损失函数(Triplet Loss.Center Loss)简介.使用方法之详细攻略 目录 T1.Triplet Loss 1.英文原文解释 ...

  2. ECCV 2018 完整论文集 -- List 下载链接

    下文列表为ECCV2018官网得到了今年接收论文列表,共779篇: 下文为ECCV2018的全部接收论文汇总 Oral: Convolutional Networks with Adaptive Co ...

  3. 武汉大学计算机学院创业老师,胡瑞敏 - 教师简历 CV- 武汉大学计算机学院

    Selected papers 2020 Li G ,Hu R , Zhang R , et al. A mapping model of spectral tilt in normal-to-Lom ...

  4. facenet 人脸识别原理理解(三)

    在前两篇文章已经介绍了facenet人脸识别代码的使用和具体操作,但相关的原理还是没有说,这篇文章进行简单的讲解一下. 1. 原理 在人脸识别中,当我们需要加在图片数据库入新的一张人脸图片时,是怎么做 ...

  5. 论文研读 —— 5. FaceNet A Unified Embedding for Face Recognition and Clustering (2/3)

    文章目录 3. Method 3.1. Triplet Loss 3.2. Triplet Selection 3.3. Deep Convolutional Networks 4. Datasets ...

  6. 论文笔记 | FaceNet: A Unified Embedding for Face Recognition and Clustering

    Authors Florian Schroff Dmitry Kalenichenko James Philbin Florian Schroff Abstract 本文提出了FaceNet syst ...

  7. Cross Domain Knowledge Transfer for Person Re-identification笔记

    Cross Domain Knowledge Transfer for Person Re-identification笔记 1 介绍 2 相关工作 3 方法 3.1 特征提取的ResNet 3.2 特 ...

  8. Google人脸识别系统Facenet paper解析

    Facenet paper地址 : facenet:   论文解析下载地址(PDF版):论文解析 FaceNet: A Unified Embedding for Face Recognition a ...

  9. Android制造 FaceID [FaceNet + MobileNet]

    1. Abstract 好久没有在简书上写文章,最近在弄关于人脸识别的内容和研读一些论文.碰巧Apple的新iPhone X搭配了Face ID进行刷脸,我有一个想法,给Android做一个类似的Fa ...

最新文章

  1. 聊聊Mysql的那些破事儿
  2. cadence原理图封装pin名称重复_硬件工程师必备技巧--如何快速制作PCB封装
  3. 101. Leetcode 139. 单词拆分 (动态规划-完全背包)
  4. ECMAScript数据属性和访问器属性
  5. spring cloud+dotnet core搭建微服务架构:服务发现(二)
  6. 算法题目——被围绕的区域(dfs,bfs)
  7. c++ socket学习(1.6)
  8. js导出的xlsx无法打开_js-xlsx 导出表格至excel
  9. jggrid标红列和动态标红行的几种方法
  10. Python编程基础15:异常
  11. js判断是否为微信浏览器
  12. badbody下_BadboyInstaller下载-录制脚本工具Badboy下载2.2.5 官方最新版-西西软件下载...
  13. sp_send_dbmail参数设置
  14. 微信小程序创建过程(具体步骤)
  15. 《JavaScript 20 年》中文版之语言诞生
  16. hdu 1862 hdoj 1862
  17. 如何直接通过电脑查看路由器密码
  18. KGB知识图谱完成金融行业的信息抽取工作
  19. PHP 下载文件的方法(指定路径)
  20. 酷睿i7 8565u属于什么级别 i78565u相当于什么水平

热门文章

  1. 如何看待莫言获诺贝尔文学奖
  2. 1 1java_你知道1+1=2,但是你知道怎么用Java写吗?
  3. windows上后台运行程序
  4. 书旗小说搜索详情python爬虫破解 淦
  5. linux波浪号是哪个目录,是波浪号,`~`被认为是相对路径?
  6. (Div.2)D. Edge Deletion
  7. Adobe Master Collection 2021 crack
  8. 网页设计师必用的14个Firefox扩展
  9. 微型计算机中常见到的Ega.VGA等是指,2011年计算机一级考试理论试题:第七部分单选题7...
  10. Gitee 倒下了!!!