Ejemplo n.º 1
0
import gym
import numpy as np
from datetime import datetime
from com.modulabs.ctrl.utils.FileUtils import FileUtils
from com.modulabs.ctrl.utils.SeedNumbers import RandomSeeder
from com.modulabs.ctrl.agents.CNNAgent import CNNAgent

RandomSeeder.set_seed()
RandomSeeder.reset()
GYM_ENV_NAME = 'Pong-v0'
EPISODES = 1000

model_name = 'pong'
cache_dir = 'caches/' + model_name
timestamp = datetime.now().strftime("%Y%m%d_%H%M")


def get_model_dir(_model_name, _timestamp):
    _model_dir = 'models/{}/dqn-{}.h5'.format(_model_name, _timestamp)
    print("get_model_dir({})".format(_model_dir))
    return _model_dir


def train(_model_name, _timestamp, _model_dir, _render):

    env = gym.make(GYM_ENV_NAME)
    agent = CNNAgent(env,
                     name=_model_name,
                     timestamp=_timestamp,
                     train_start=50000)
    global_step = 0
Ejemplo n.º 2
0
import gym
import numpy as np
from datetime import datetime
from com.modulabs.ctrl.utils.FileUtils import FileUtils
from com.modulabs.ctrl.utils.SeedNumbers import RandomSeeder
from com.modulabs.ctrl.agents.DQNAgent import DQNAgent

RandomSeeder.set_seed()
# RandomSeeder.reset()
GYM_ENV_NAME = 'CartPole-v1'
EPISODES = 1000

timestamp = datetime.now().strftime("%Y%m%d_%H%M")
model_name = 'cartpole'
model_path = 'models/{}/dqn-{}.h5'.format(model_name, timestamp)
cache_dir = 'caches/' + model_name


def train():
    global model_name, timestamp

    env = gym.make(GYM_ENV_NAME)
    agent = DQNAgent(env, name=model_name, timestamp=timestamp, use_swa=True)
    global_step = 0
    size_of_window = 15
    scores = []

    if FileUtils.exists_file(model_path):
        agent.load_weights(model_path)

    for e in range(EPISODES):
Ejemplo n.º 3
0
 def flip_random_seed(on=True):
     from com.modulabs.ctrl.utils.SeedNumbers import RandomSeeder
     if on:
         RandomSeeder.set_seed()
     else:
         RandomSeeder.reset()