christianhidber / easyagents

Reinforcement Learning for Practitioners.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spec_shape error

ogirdorodrigo opened this issue · comments

Hi there,
we started working with a custom game and received the following error:

ValueError: Received a mix of batched and unbatched Tensors, or Tensors are not compatible with Specs. num_outer_dims: 1.
Saw tensor_shapes:
TimeStep(step_type=TensorShape([1]), reward=TensorShape([1]), discount=TensorShape([1]), observation=TensorShape([1]))
And spec_shapes:
TimeStep(step_type=TensorShape([]), reward=TensorShape([]), discount=TensorShape([]), observation=TensorShape([1]))

We belive the error is comming from an incomplete definition of our init method. See below the relevant methods.

def __init__(self):
    self.action_space = spaces.Box(low=0, high=1, shape=(4,), dtype=np.float32)
    self.observation_space = spaces.Box(low=0, high=500, shape=(1,), dtype=np.float32)
    # additional game parameters
    self.maxNumBullets = 5
    self.bulletRadius = 6
    self.bulletColor = (0, 0, 0)  
    self.reset()

def reset(self):
    self.score = 0
    self.done = False
    self.reward = 0
    self.stepCount = 0
    # additional game parameters
    self.shootLoop = 0
    self.bullets = []
    self.enemies = []
    self.level = 1
    # pygame parameters
    pygame.init()
    clock = pygame.time.Clock()
    self.run  = True
    self.simGame = game()
    clock.tick(27)
    self.man = player(x=100, y=405, screenWidth=self.simGame.screenWidth)
    return self.getObservation()  # currently the observation is just a float in the range [0,500]

We would appreciate very much your help.

Cheers!!

This is coming from TF-Agents, so it might be you have to wrap low and high values in an array, like it it done here

https://colab.research.google.com/github/christianhidber/easyagents/blob/master/jupyter_notebooks/intro_line.ipynb