i have bash script , want convert python.
this script :
mv $1/positive/*.$3 $2/jpegimages mv $1/negative/*.$3 $2/jpegimages mv $1/positive/annotations/*.xml $2/annotations mv $1/negative/annotations/*.xml $2/annotations cut -d' ' -f1 $1/positive_label.txt > $4_trainval.txt
my problem : didn't found how past positive_label.txt in $4_trainval.txt.
this try, it's first time work python. please me make work. thank you.
import sys # required reading command line arguments import os # required path manipulations os.path import expanduser # required expanding '~', stands home folder. used in case command line arguments contain "~". without this, python won't parse "~" import glob import shutil def copy_dataset(arg1,arg2,arg3,arg4): path1 = os.path.expanduser(arg1) path2 = os.path.expanduser(arg2) # frame_ext = arg3 # file extension of patches pos_files = glob.glob(os.path.join(path1,'positive/'+'*.'+frame_ext)) neg_files = glob.glob(os.path.join(path1,'negative/'+'*.'+frame_ext)) pos_annotation = glob.glob(os.path.join(path1,'positive/annotations/'+'*.'+xml)) neg_annotation = glob.glob(os.path.join(path1,'negative/annotations/'+'*.'+xml)) #mv $1/positive/*.$3 $2/jpegimages x in pos_files: shutil.copyfile(x, os.path.join(path2,'jpegimages')) #mv $1/negative/*.$3 $2/jpegimages y in neg_files: shutil.copyfile(y, os.path.join(path2,'jpegimages')) #mv $1/positive/annotations/*.xml $2/annotations w in pos_annotation: shutil.copyfile(w, os.path.join(path2,'annotations')) #mv $1/negative/annotations/*.xml $2/annotations z in neg_annotation: shutil.copyfile(z, os.path.join(path2,'annotations')) #cut -d' ' -f1 $1/positive_label.txt > $4_trainval.txt line in open(path1+'/positive_label.txt') line.split(' ')[0]
without testing, should works.
#cut -d' ' -f1 $1/positive_label.txt > $4_trainval.txt positive = path1+'/positive_label.txt' path4 = os.path.join(arg4, '_trainval.txt') open(positive, 'r') input_, open(path4, 'w') output_: line in input_.readlines(): output_.write(line.split()[0] + "\n")
this code defines 2 files work , opens both. first opened in read mode, second in write mode. each line in input file, write first find data separated space output file.
check reading , writing files in python more informations files python.
Comments
Post a Comment