def main(normfile, output, wikiuni, jar, fasttext): fcfg = fileconfig.Configuration() fh.is_file(normfile) if output: fh.is_folder(output) else: output = dirname(normfile) if wikiuni: fh.is_file(wikiuni) else: wikiuni = fcfg.get('MODEL_WIKI_UNIGRAMS') if jar: fh.is_file(jar) else: jar = fcfg.get('SNLP_TAGGER_JAR') if fasttext: fh.is_file(fasttext) else: fasttext = fcfg.get('FASTTEXT_EXEC_PATH') embeddings.embeddings_from_norms(normfile, output, wikiuni, jar, fasttext)
def generate_pathfile(rootfolder): rootfolder = fh.is_folder(rootfolder) left = join(rootfolder, 'LEFT') right = join(rootfolder, 'RIGHT') depth = join(rootfolder, 'DEPTH') leftfile = open(join(rootfolder, 'original_left.txt'), 'w') rightfile = open(join(rootfolder, 'original_right.txt'), 'w') depthfile = open(join(rootfolder, 'original_depth.txt'), 'w') logger.info('Saving paths from %s' % left) for root, dirs, files in os.walk(left, topdown=False): files = fh.sort_by_name(files) for name in files: path = join(root, name) leftfile.write('%s\n' % path) leftfile.close() logger.info('Saving paths from %s' % right) for root, dirs, files in os.walk(right, topdown=False): files = fh.sort_by_name(files) for name in files: path = join(root, name) rightfile.write('%s\n' % path) rightfile.close() logger.info('Saving paths from %s' % depth) for root, dirs, files in os.walk(depth, topdown=False): files = fh.sort_by_name(files) for name in files: path = join(root, name) depthfile.write('%s\n' % path) depthfile.close()
def move_files_new_path(rootfolder): """ After selecting images in `left_image` folder, move the selected from `right_image` and `depth_image` following the same structure as `LEFT` folder """ rootfolder = fh.is_folder(rootfolder) old_right = join(rootfolder, 'right_image') old_depth = join(rootfolder, 'depth_image') # folder containing subfolders with selected images left = join(rootfolder, 'LEFT') right = join(rootfolder, 'RIGHT') depth = join(rootfolder, 'DEPTH') for root, dirs, files in os.walk(left, topdown=False): # right righttmp = root.replace(left, right) dirright = fh.mkdir_from_file(righttmp) # depth depthtmp = root.replace(left, depth) dirdepth = fh.mkdir_from_file(depthtmp) logger.info('Moving files following the folder: %s' % root) for name in files: leftfile = join(root, name) old_rightfile = join(old_right, name) new_rightfile = leftfile.replace(left, right) shutil.move(old_rightfile, new_rightfile) old_depthfile = join(old_depth, name) new_depthfile = leftfile.replace(left, depth) shutil.move(old_depthfile, new_depthfile)
def rename_files(rootfolder): rootfolder = fh.is_folder(rootfolder) folders = ['LEFT', 'RIGHT', 'DEPTH'] for fld in folders: pathfolder = join(rootfolder, fld) fout = open(join(rootfolder, 'paths_'+fld.lower()+'.txt'), 'w') logger.info('Renaming paths from %s' % pathfolder) for root, dirs, files in os.walk(pathfolder, topdown=False): files = fh.sort_by_name(files) index = 1 for name in files: old_path = join(root, name) new_path = join(root, str(index)+'.jpg') #os.rename(old_path, new_path) fout.write('%s\n' % new_path) index += 1 fout.close()
elif topic == '/diffboat1/move_base/RRAPlannerROS/distance': sim.add('distance', msg.data) elif topic == '/diffboat1/move_base/RRAPlannerROS/computation_time': sim.add('computation', msg.data) fout = join(dirout, fname + '.pkl') logger.info('Saving file: {}'.format(fout)) d = {'boat1': boat1, 'boat2': boat2, 'stats': sim} with open(fout, 'wb') as f: pickle.dump(d, f) def main(bagfolder): fhandler = fh.FolderHandler(bagfolder, ext='bag') for bagname in fhandler: main_extract(bagname) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('bagfile', metavar='bag_file', help='Bag or folder containing several bags') args = parser.parse_args() if fh.is_folder(args.bagfile): main(args.bagfile) elif fh.is_file(args.bagfile): main_extract(args.bagfile) else: logger.info('Path does not contain bag files')