def main(): args = parser.parse_args() is_file = '.' in args.out.split('/')[-1] assert is_file, 'Output must be file' util.rm_if_needed(args.out) util.makedirs_if_needed(args.out) in_files = list(glob.glob(args.in_dir + '/*.mat')) assert len(in_files) > 0, 'No mat files found' process(in_files, args.out, args.in_key, args.out_group)
def main(): args = parser.parse_args() if args.out is None: args.out = args.in_file.replace('.hdf5', '.tfrecords') is_file = '.' in args.out.split('/')[-1] assert is_file, 'Output must be file' util.rm_if_needed(args.out) util.makedirs_if_needed(args.out) in_ext = args.in_file.split('.')[-1] assert in_ext in ['hdf5'], 'Unsupported format {}'.format(in_ext) process(args.in_file, args.out)
def main(): args = parser.parse_args() if not os.path.isfile(args.in_file): raise Exception('Input file `{}` does not exist'.format(args.in_file)) if args.out is None: basename = '.'.join(args.in_file.split('.')[:-1]) args.out = basename + '-combined.hdf5' is_file = '.' in args.out.split('/')[-1] assert is_file, 'Directory output not supported yet, try file ext' util.rm_if_needed(args.out) util.makedirs_if_needed(args.out) in_ext = args.in_file.split('.')[-1] assert in_ext in ['hdf5'], 'Unsupported format {}'.format(out_ext) process(args.in_file, args.out)
def main(): args = parser.parse_args() if args.out is None: basename = os.path.basename(args.in_file) dirname = os.path.dirname(args.in_file) args.out = dirname + '/' + '.'.join( basename.split('.')[:-1]) + '-split' + '.hdf5' util.rm_if_needed(args.out) util.makedirs_if_needed(args.out) def _split_key_value_pair(s): key, value = s.split('=') return key, int(value) splits = list(map(_split_key_value_pair, args.splits.split(' '))) print(splits) process(args.in_file, args.out, splits)
def main(): args = parser.parse_args() if not os.path.isdir(args.in_dir): raise Exception('Input directory `{}` does not exist'.format(args.in_dir)) is_file = '.' in args.out.split('/')[-1] assert is_file, 'Directory output not supported yet, try file ext' util.rm_if_needed(args.out) util.makedirs_if_needed(args.out) out_ext = args.out.split('.')[-1] assert out_ext in ['hdf5'], 'Unsupported format {}'.format(out_ext) vid_dirs = list(util.find_deepest_dirs(args.in_dir)) assert len(vid_dirs) != 0, 'Could not find any vids' print('Found {} directories'.format(len(vid_dirs))) process_vids(vid_dirs, args.out)
def main(): args = parser.parse_args() if not os.path.isdir(args.in_dir): raise Exception('Input directory `{}` does not exist'.format( args.in_dir)) is_file = '.' in args.out.split('/')[-1] assert is_file, 'Directory output not supported yet, try file ext' util.rm_if_needed(args.out) util.makedirs_if_needed(args.out) out_ext = args.out.split('.')[-1] assert out_ext in ['hdf5'], 'Unsupported format {}'.format(out_ext) # Mean pixel if args.subtract_mean_pixel: mean_pixel = np.load(args.mean_pixel) else: print('Not using the mean pixel value') mean_pixel = None vid_dirs = list(util.find_deepest_dirs(args.in_dir)) assert len(vid_dirs) != 0, 'Could not find any vids' print('Found {} directories'.format(len(vid_dirs))) # Create a generator that generates batches of features per video vids = process_vids(vid_dirs, model_key=args.feature, debug=args.debug, batch_size=args.batch_size, mean_pixel=mean_pixel) # Write out the batches of features writers[out_ext](vids, args.out)
def main(): args = parser.parse_args() if not os.path.isdir(args.in_dir): raise Exception('Input directory `{}` does not exist'.format( args.in_dir)) is_file = '.' in args.out.split('/')[-1] assert is_file util.rm_if_needed(args.out) util.makedirs_if_needed(args.out) out_ext = args.out.split('.')[-1] assert out_ext in ['npy'], 'Unsupported format {}'.format(out_ext) vid_dirs = list(util.find_deepest_dirs(args.in_dir)) assert len(vid_dirs) != 0, 'Could not find any vids' print('Found {} directories'.format(len(vid_dirs))) # Create a generator that generates batches of features per video pixel = process_vids(vid_dirs) # Write out the batches of features writers[out_ext](pixel, args.out)
def main(): args = parser.parse_args() if args.out != '.': shutil.rmtree(args.out, ignore_errors=True) util.makedirs_if_needed(args.out) print(args.out) in_ext = args.in_file.split('.')[-1] assert in_ext in ['hdf5'], 'Unsupported format {}'.format(in_ext) if args.keys_file: print('Splitting using a keys file') assert args.out.split('.')[-1] in ['hdf5' ], 'Only hdf5 output supported' with open(args.keys_file, 'r') as keys_file: keys = keys_file.readlines() keys = list( filter(lambda k: k and len(k), map(lambda k: k.strip(), keys))) assert len(keys) print('Read {} keys'.format(len(keys))) extract(args.in_file, args.out, keys) else: print('Splitting by fractions') split_names = ['train', 'val', 'test'] split_fracs = [args.train_frac, args.validation_frac, args.test_frac] assert sum(split_fracs) == 1., 'Fractions should sum to 1' splits = filter(lambda x: x[1] != 0, zip(split_names, split_fracs)) split_names, split_fracs = zip(*splits) process_by_fracs(args.in_file, args.out, split_names, split_fracs)