def __init__(self, env, args): self.args = args self.agent = Neurosmash.Agent() self.env = env # extract background self.extr = BE.Background_Extractor(self.env, self.agent, args) self.background = self.extr.get_background(oned=True) self.background_im = self.extr.get_background(oned=False)
def __init__(self, vision, env, args, agent=None): self.args = args self.vision = vision self.env = env if not agent: self.agent = Neurosmash.Agent() else: self.agent = agent # extract background self.extr = BE.Background_Extractor(self.env, self.agent, args) self.background = self.extr.get_background(oned=True)
def set_up_env(args): # Initialize agent and environment controller = Neurosmash.Agent() # This is an example agent. if args.use_controller: controller = Controller(args) # This is the main environment. try: environment = Neurosmash.Environment(args) except: print( "Connecting to environment failed. Please make sure Neurosmash is running and check your settings." ) print( f"Settings from world model: ip={args.ip}, port={args.port}, size={args.size}, timescale={args.timescale}" ) else: print("Successfully connected to Neurosmash!") return controller, environment
# Imports from convvae import ConvVae import numpy as np import mxnet as mx from mxnet import nd, autograd, gluon from sklearn.model_selection import train_test_split from tqdm import tqdm import matplotlib.pyplot as plt import Neurosmash ip = "127.0.0.1" port = 13000 size = 128 # 96, 192 timescale = 1 agent = Neurosmash.Agent() environment = Neurosmash.Environment(ip, port, size, timescale) # end (true if the episode has ended, false otherwise) # reward (10 if won, 0 otherwise) # state (flattened size x size x 3 vector of pixel values) # The state can be converted into an image as follows: # image = np.array(state, "uint8").reshape(size, size, 3) # You can also use to Neurosmash.Environment.state2image(state) function which returns # the state as a PIL image shape = (3, size, size) def roam_and_collect(nr_images=10): # The following steps through an entire episode from start to finish with random actions (by default)
def __init__(self, env, args): self.args = args self.agent = Neurosmash.Agent() self.env = env extr = BE.Background_Extractor(self.env, self.agent, args) self.background = extr.get_background().reshape(-1)