from models.cc_concatenate import CCPPOPolicy, CCPPOTrainer from ray.rllib.agents.ppo.ppo import PPOTrainer import numpy as np import time import yaml import tensorflow as tf from utils.loader import load_envs, load_models from ray.rllib.agents.registry import get_agent_class #from ray.rllib.agents.marwil.marwil import MARWILTrainer from imitation_agent.imitation_trainer import ImitationAgent tf.compat.v1.enable_eager_execution() #tf.compat.v1.enable_v2_behavior() #tf.compat.v1.disable_eager_execution() load_envs("envs/flatland") load_models() ray.init() with open("custom_imitation_learning_rllib_tree_obs/ppo_imitation_tree_obs.yaml") as f: config = yaml.safe_load(f) obs_config = config["flatland-sparse-small-tree-fc-apex-il-trainer"]["config"]["env_config"]["observation_config"] agent_config = config["flatland-sparse-small-tree-fc-apex-il-trainer"]["config"]["model"] ##################################################################### # Instantiate a Remote Client ##################################################################### remote_client = FlatlandRemoteClient() ##################################################################### # Instantiate your custom Observation Builder # # You can build your own Observation Builder by following # the example here :
####################################################################################################### EXAMPLE_USAGE = """ Training example: python ./train.py --run DQN --env CartPole-v0 Training with Config: python ./train.py -f experiments/simple-corridor-0.yaml Note that -f overrides all other trial-specific command-line options. """ # Register all necessary assets in tune registries load_envs(os.getcwd()) # Load envs load_models(os.getcwd()) # Load models # Load custom algorithms from algorithms import CUSTOM_ALGORITHMS load_algorithms(CUSTOM_ALGORITHMS) print(ray.rllib.contrib.registry.CONTRIBUTED_ALGORITHMS) ####################################################################################################### ##################################### Helper Funcs ################################################# ####################################################################################################### def create_parser(parser_creator=None): parser = make_parser(parser_creator=parser_creator, formatter_class=argparse.RawDescriptionHelpFormatter, description="Train a reinforcement learning agent.",
from utils.loader import load_envs, load_models, load_algorithms, load_preprocessors from ray_experiment_builder import RayExperimentBuilder # Try to import both backends for flag checking/warnings. tf = try_import_tf() torch, _ = try_import_torch() from custom.models.my_vision_network import MyVisionNetwork """ Note : This script has been adapted from : https://github.com/ray-project/ray/blob/master/rllib/train.py and https://github.com/AIcrowd/neurips2020-procgen-starter-kit/blob/master/train.py """ load_envs(os.path.join("custom", "envs")) load_models((os.path.join("custom", "models"))) # Load models # Load custom algorithms from custom.algorithms import CUSTOM_ALGORITHMS load_algorithms(CUSTOM_ALGORITHMS) # Load custom preprocessors from custom.preprocessors import CUSTOM_PREPROCESSORS load_preprocessors(CUSTOM_PREPROCESSORS) print(ray.rllib.contrib.registry.CONTRIBUTED_ALGORITHMS) def run(): ModelCatalog.register_custom_model("my_vision_network", MyVisionNetwork) config = { "model": { "custom_model": "my_vision_network",