csv文件_训练图片标签_(个人学习记录)
csv文件_训练图片标签_记录
1、csv
opencv教程里面为我们提供了自动生成csv文件的脚本(create_csv.py).
打开后是我们修改一下代码,BASE_PATH手动的改成自己的数据集路径,改完后代码如下:
#!/usr/bin/env python
import sys
import os.path
# This is a tiny script to help you creating a CSV file from a face
# database with a similar hierarchie:
#
# philipp@mango:~/facerec/data/at$ tree
# .
# |-- README
# |-- s1
# | |-- 1.pgm
# | |-- ...
# | |-- 10.pgm
# |-- s2
# | |-- 1.pgm
# | |-- ...
# | |-- 10.pgm
# ...
# |-- s40
# | |-- 1.pgm
# | |-- ...
# | |-- 10.pgm
#
if __name__ == "__main__":
if len(sys.argv) != 2:
print "usage: create_csv <base_path>"
sys.exit(1)
BASE_PATH="C:/Users/ZOY/Desktop/temp/video/orl_faces"
SEPARATOR=";"
fh = open("C:/Users/ZOY/Desktop/temp/video/orl_faces/at.txt",'w') //生成csv格式数据的路径
label = 0
for dirname, dirnames, filenames in os.walk(BASE_PATH):
for subdirname in dirnames:
subject_path = os.path.join(dirname, subdirname)
for filename in os.listdir(subject_path):
abs_path = "%s/%s" % (subject_path, filename)
print("%s%s%d" % (abs_path, SEPARATOR, label))
fh.write(abs_path)
fh.write(SEPARATOR)
fh.write(str(label))
fh.write("\n")
label = label + 1
fh.close()
然后win+R cmd 回车,start python "create_csv.py"
2、训练图片路径txt
win+R cmd 回车,输入命令:“训练集图片所在路径”>dir /b/s *.png *.jpg > at.txt
,无标签,仅生成路径列表