def set_config_params(args): if args.cfg_file != '': cfg_from_file(args.cfg_file) if args.train is not None: cfg.TRAIN.FLAG = args.train if args.data_dir != '': cfg.DATA_DIR = args.data_dir cfg.DATA_DIR = os.path.join(cfg.DATA_DIR, cfg.DATA_SIZE) # Set device if torch.cuda.is_available(): cfg.DEVICE = torch.device('cuda') if args.threshold is not None: cfg.VOCAB.THRESHOLD = args.threshold print('Using config:') pprint.pprint(cfg)
cap_lens = cap_lens[sorted_indices] cap_array = np.zeros((len(captions), max_len), dtype='int64') for i in range(len(captions)): idx = sorted_indices[i] cap = captions[idx] c_len = len(cap) cap_array[i, :c_len] = cap key = name[(name.rfind('/') + 1):] data_dic[key] = [cap_array, cap_lens, sorted_indices] algo.gen_example(data_dic) if __name__ == "__main__": args = parse_args() if args.cfg_file is not None: cfg_from_file(args.cfg_file) if args.data_dir != '': cfg.DATA_DIR = args.data_dir print('Using config:') pprint.pprint(cfg) if not cfg.TRAIN.FLAG: args.manualSeed = 100 elif args.manualSeed is None: args.manualSeed = random.randint(1, 10000) random.seed(args.manualSeed) np.random.seed(args.manualSeed) torch.manual_seed(args.manualSeed) if cfg.CUDA: torch.cuda.manual_seed_all(args.manualSeed)
cap = captions[idx] c_len = len(cap) cap_array[i, :c_len] = cap key = name[(name.rfind('/') + 1):] data_dic[key] = [cap_array, cap_lens, sorted_indices] algo.gen_example(data_dic) if __name__ == "__main__": m = Main() # change. object of Main class to handle code execution # args = parse_args() # argument parser object # check if the passed config file is not None if m.cfg_file is not None: # change # cf_file = "/Users/nikunjlad/Github/MirrorGAN/cfg/train_bird.yml" cfg_from_file(m.cfg_file) # update default configs and user given configs if m.data_dir != '': cfg.DATA_DIR = m.data_dir print('Using config:') pprint.pprint(cfg) # setting random seed fir numpy and torch tensors if not cfg.TRAIN.FLAG: m.manualSeed = 100 elif m.manualSeed is None: m.manualSeed = random.randint(1, 10000) random.seed(m.manualSeed) np.random.seed(m.manualSeed) torch.manual_seed(m.manualSeed)