1. Create a train.txt with an absolute path with a shell script
For example, I want to generate the following form of tagged files,:(if there are two tags: 0 and 1)
The shell script is as follows:
So the label 0 is written to Train.txt
1 #/usr/bin/env SH2data=/home/ttwang/desktop/texture/03datasave=/home/ttwang/Desktop4 5Echo"Create train.txt ..."6 7 #/usr/bin/env SH8Find $DATA-name grass*.jpg | Sed"s/$/1/">> $DATASAVE/Train.txt9 TenEcho"Done :"
Then write a script, so that the specified file under the want to make a label 1 of the image written to Train.txt, (this is more troublesome, there must be better than this)
# /usr/bin/env SH DATA=/HOME/TTWANG/DESKTOP/TEXTURE/1datasave=/home/ttwang/"Create train.txt ... "# /usr/bin/env sh"s/$/1/" >> $DATASAVE/ "done. . "
Then, run the script: SH 1.sh/sh 2.sh (assuming the script file is named this), it's all right!
(1) If you do not want to display so many paths, the corresponding data path of the representation, or use the cut specific reference (when used to review)
Train.txt generated with a Python script
2. Generate train.txt with a Python script
For example, I want to generate the following forms of tagged files:
The Python script is as follows:
1 ImportOS2 defGenerate (Dir,label):3Files =Os.listdir (dir)4 Files.sort ()5 Print '****************'6 Print 'Input:', dir7 Print 'start ...'8Listtext = open (dir+'/'+'List.txt','W')9 forFileinchFiles:TenFileType =os.path.split (file) One ifFILETYPE[1] = ='. txt': A Continue -Name = File +' '+ STR (int (label)) +'\ n' - listtext.write (name) the listtext.close () - Print 'down!' - Print '****************' - + if __name__=='__main__': -Generate'/HOME/TTWANG/DESKTOP/TEXTURE/TEST/1'.1k
Using Python and shell scripts to generate train.txt tag files