def __init__(self, args=None): self.env = None self.sampler = None self.experiment = None self.c_level = None self.pol = None if args is None: args = ArgsFromFile(self.default_args) self.args = args assert args.mirror in [False, "old", "new", "tuple"] if args.mirror == "old": args.mirror = True args.mirror_tuples = args.mirror == "tuple" self.env_kwargs = copy.deepcopy(getattr(self.args, "env_kwargs", {})) device_name = "cpu" if args.cuda < 0 else "cuda:{}".format(args.cuda) set_device(th.device(device_name)) self.num_updates = (int(args.num_total_frames) // args.num_steps // args.num_processes) self.seed_torch(args.seed) self.setup_env() if args.render or args.evaluate: self.load_save(args.env, "last") else: if hasattr(args, "load_path"): self.load_save(args.env, "last") else: self.setup_nets() self.setup_optims() self.setup_experiment()
with open(os.path.join(args.log, 'args.json'), 'w') as f: json.dump(vars(args), f) pprint(vars(args)) # modelの保存場所確保 if not os.path.exists(os.path.join(args.log, 'models')): os.mkdir(os.path.join(args.log, 'models')) # 乱数の種固定 np.random.seed(args.seed) torch.manual_seed(args.seed) # GPU or CPU device_name = 'cpu' if args.cuda < 0 else "cuda:{}".format(args.cuda) device = torch.device(device_name) set_device(device) # logのcsvファイル確保 score_file = os.path.join(args.log, 'progress.csv') logger.add_tabular_output(score_file) # Gymのenviromentを生成 from pybullet_envs.bullet.kukaCamGymEnv import KukaCamGymEnv env = KukaCamGymEnv(renders=False, isDiscrete=False) # renders=Trueだとmachinaのtrain進まない。相性が悪い? env = FlattenedObservationWrapper(env) flattend_observation_space = env.flattend_observation_space env = GymEnv(env, log_dir=os.path.join(args.log, 'movie'), record_video=args.record)