人眼睁闭状态正负样本标定过程(BAT批处理文件 + python)

来源:互联网 发布:网络平台使用协议 编辑:程序博客网 时间:2024/06/05 08:01

机器学习中进行人眼睁闭状态正负样本标定过程(BAT批处理文件 + python)

此博客内容简单,是为了记录与总结本次解决问题的全过程(全文仅以处理闭眼样本为例),如果能帮助到遇到同样问题的小伙伴,那就再好不过了。

参考资料:
http://stackoverflow.com/questions/11555468/how-should-i-read-a-file-line-by-line-in-python

http://stackoverflow.com/questions/4828885/how-to-direct-output-into-a-txt-file-in-python-in-windows

https://www.lifewire.com/dir-command-4050018

  • 将闭眼数据集存储在某一指定文件夹下,并用bulk rename utility 软件对数据集批量命名,如closed_eyes_1.jpg
  • 用BAT批处理文件,将闭眼数据集中的全部图片文件(仅含文件名或包含完整路径的文件名)导入到txt文件中。
    `
    //仅包含文件名
    @echo off
    dir “D:\FYP\dataset_B_Eye_Images\closedEyes_train” /a-d /b > C:\Users\Lucy\Desktop\listmyfolder.txt

    //含完整路径的文件名
    @echo off
    dir D:\FYP\dataset_B_Eye_Images\closedEyes_train*.jpg /s /b > C:\Users\Lucy\Desktop\closedeyes.txt
    `

  • 使用python进行txt文件读取,并将新生成的标记后的文件保存为新的txt文件
    `/*以下为python脚本test.py,写好后只需在命令行中运行
    python test.py > output.txt 即可生成最终带标记的数据集。例如D:\Python27\python.exe test.py > C:\Users\Lucy\Desktop\openedeyes.txt。
    注意此command prompt需要在py文件所在处打开。*/

    with open(‘C:\Users\Lucy\Desktop\closedeyes_train.txt’) as fp:
    for line in fp:
    lines = line.strip(‘\n’)
    print lines
    print(‘0’)`

0 0
原创粉丝点击