In deep learning or machine learning, it is often necessary to organize and classify data, most commonly by writing data paths and labels
to a consolidated txt or CSV file, the training is read.
1 #Coding=utf-82 #!/usr/bin/env python4 ImportSYS5 ImportOs.path6 7 #This was a tiny script to help you creating a CSV file from a face8 #database with a similar hierarchie:9 # One # . A #|--README - #|--S1 - # | |--1.PGM the # | |-- ... - # | |--10.PGM - #|--S2 - # | |--1.PGM + # | |-- ... - # | |--10.PGM + # ... A #|--S40 at # | |--1.PGM - # | |-- ... - # | |--10.PGM - # - - if __name__=="__main__": in - ifLen (SYS.ARGV)! = 3: to Print "usage:create_csv <base_path>" +Sys.exit (1) - theBase_path=sys.argv[1] *Separator=";" $FH = open (sys.argv[2],'W')Panax Notoginseng -Label =0 the forDirName, Dirnames, filenamesinchOs.walk (base_path): + forSubdirnameinchDirnames: ASubject_path =Os.path.join (dirname, Subdirname) the forFileNameinchOs.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") theLabel = label + 1 -Fh.close ()
The call method is as follows
Python create.py D:/test/jaf d:/a.csv
The resulting file results are as shown
You can adjust the slash to match by replacing
Python creates a CVS file with tag and picture data