用shell 脚本创建lfw的正负样本对
2016-12-28 18:31
267 查看
我们在lfw上做测试的时候,第一步就是创建lfw正负样本对。
现在总结如下#!/bin/bash # create the lfw postive pairs # usage: In this file ,you should create a lfw_name_list.txt (13233 lines) # for each line in lfw_name_list.txt ,format should be as : # number name_0001.jpg : # eg: 13202 Zhang_Ziyi_0003.jpg # the only change you may do in this file is : # yourNameList="lfw_name_list.txt" # # output: POSTIVE_PAIR.txt & NEGATIVE_PAIR.txt # tricy: how to add number at begin of you own *.txt # :let i=1 # :g/^/ s//\=i . ' '/ |let i=i+1 # # Author: bin.wang # Date : 2016/12/19 echo "preparing pos_result.txt..." cat ./pos_pairs.txt | awk '{print $1}' > ./leftImge_pos_p1.txt cat ./pos_pairs.txt | awk '{printf("_%04d.jpg\n",$2)}' > ./leftImge_pos_p2.txt cat ./pos_pairs.txt | awk '{print $1}' > ./rightImge_pos_p1.txt cat ./pos_pairs.txt | awk '{printf("_%04d.jpg\n",$3)}' > ./rightImge_pos_p2.txt paste leftImge_pos_p1.txt leftImge_pos_p2.txt --delimiters="" > leftImage_pos.txt paste rightImge_pos_p1.txt rightImge_pos_p2.txt --delimiters="" > rightImage_pos.txt paste leftImage_pos.txt rightImage_pos.txt --delimiters=" " > pos_result.txt echo "pos_result.txt done !!!" # create the lfw negative pairs # echo "preparing neg_resut.txt..." cat ./neg_pairs.txt | awk '{print $1}' > ./leftImage_neg_p1.txt cat ./neg_pairs.txt | awk '{printf("_%04d.jpg\n",$2)}' > ./leftImage_neg_p2.txt cat ./neg_pairs.txt | awk '{print $3}' > ./rightImge_neg_p1.txt cat ./neg_pairs.txt | awk '{printf("_%04d.jpg\n",$4)}' > ./rightImge_neg_p2.txt paste rightImge_neg_p1.txt rightImge_neg_p2.txt --delimiters="" > rightIamge_neg.txt paste leftImage_neg_p1.txt leftImage_neg_p2.txt --delimiters="" > leftImage_neg.txt paste leftImage_neg.txt rightIamge_neg.txt --delimiters=" " > neg_result.txt #delimiters=4 backSpace echo "neg_result.txt done !!!" rm -rf *_neg.txt *_pos.txt rm -rf *p1.txt *p2.txt rm -rf num1.txt num2.txt ############################# i=0 #for debug yourNameList="./lfwlists.txt" cat pos_result.txt | while read line do i=`expr $i + 1` right_pos_pair="" left_pos_pair="" eval $(echo $line |awk '{printf("left_pos_pair=%s;right_pos_pair=%s;",$1,$2)}') cat $yourNameList | grep " $left_pos_pair" | awk '{print $1}' >> num1.txt cat $yourNameList | grep " $right_pos_pair" | awk '{print $1}' >> num2.txt done paste num1.txt num2.txt --delimiters=" " >POSTIVE_PAIR.txt ######################################################################################### echo " You may wait a few minutes ..." j=0 cat neg_result.txt | while read line do j=`expr $j + 1` left_neg_pair="" right_neg_pair="" eval $(echo $line |awk '{printf("left_neg_pair=%s;right_neg_pair=%s;",$1,$2)}') cat $yourNameList | grep " $left_neg_pair" | awk '{print $1}' >> num3.txt cat $yourNameList | grep " $right_neg_pair" | awk '{print $1}' >> num4.txt done paste num3.txt num4.txt --delimiters=" " >NEGATIVE_PAIR.txt rm -rf num1.txt num2.txt num3.txt num4.txt ############################################################################ cp POSTIVE_PAIR.txt NEGATIVE_PAIR.txt ../test_lfw/featureMat/ echo "DONE!"
Notice: 这个shell脚本需要的输入: neg_pairs.txt pos_pairs.txt
格式为
【pos_pairs.txt】 1 Abel_Pacheco 1 4 2 Akhmed_Zakayev 1 3 3 Akhmed_Zakayev 2 3 4 Amber_Tamblyn 1 2 5 Anders_Fogh_Rasmussen 1 3 6 Anders_Fogh_Rasmussen 1 4 7 Angela_Bassett 1 5 8 Angela_Bassett 2 5 9 Angela_Bassett 3 4 10 Ann_Veneman 3 5 11 Ann_Veneman 6 10 12 Ann_Veneman 10 11 ... ... 【neg_pairs.txt】 1 Abdel_Madi_Shabneh 1 Dean_Barker 1 2 Abdel_Madi_Shabneh 1 Giancarlo_Fisichella 1 3 Abdel_Madi_Shabneh 1 Mikhail_Gorbachev 1 4 Abdul_Rahman 1 Portia_de_Rossi 1 5 Abel_Pacheco 1 Jong_Thae_Hwa 2 6 Abel_Pacheco 2 Jean-Francois_Lemounier 1 7 Afton_Smith 1 Dwayne_Wade 1 8 Ahmad_Jbarah 1 James_Comey 1 9 Akhmed_Zakayev 2 Donna_Morrissey 1 10 Alan_Dershowitz 1 Bertrand_Bonello 1
相关文章推荐
- shell 二维数组
- 通过shell的二维数组 跳入指定服务器
- Shell重定向
- shell自动下载nginx日志文件到本地
- Bash快捷键
- 变量在shell脚本间的传递
- 使用PowerShell修改操作系统“环境变量”
- 使用PowerShell修改操作系统“环境变量”
- 简单shell脚本(mongo)
- linux shell “永久环境变量”、“临时环境变量”和普通变量之完全解读
- shell命令快捷键
- linux中shell脚本设置环境变量
- linux下使用shell 自动执行脚本文件
- linux中在shell脚本内alias和unalias不可用解决办法
- Linux之bash shell特性
- shell -vim
- shell-引号
- Shell脚本在Linux下运行错误的解决方法
- shell 语法与C语言对比
- linux Ubuntu中如何连接xshell