Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UserWarning: WARN: Box bound precision lowered by casting to float32

I continuously get this error

UserWarning: WARN: Box bound precision lowered by casting to float32
  warnings.warn(colorize('%s: %s'%('WARN', msg % args), 'yellow'))

when I start my training session. I guess it's coming from this line

self.action_space = spaces.Box(low, high)

The code is running but I want to stop this error from showing up

I am using a cuda pc to run the code.

like image 334
Murtaza Basu Avatar asked Feb 10 '20 11:02

Murtaza Basu


2 Answers

Just cast the dtype of the values you pass Box to float32:

self.action_space = spaces.Box(np.float32(low), np.float32(high))

For example, also all these examples are valid:

self.action_space = spaces.Box(np.float32(3), np.float32(4.0))

self.action_space = spaces.Box(np.float32(np.array([3.0,3.5])), np.float32(np.array([4.0,4.5])))

self.action_space = spaces.Box(np.array([3.0,3.5],dtype=np.float32), np.array([4.0,4.5],dtype=np.float32))

By the way: While you can also explicitly cast the Box-dtype itself to np.float32 as @Robert Wilkerson suggests, there is no need for it: it does not solve the problem, and it has no effect as the dtype of Box already defaults to np.float32.

like image 141
FlorianH Avatar answered Nov 06 '22 17:11

FlorianH


Explicitly specify the dtype as float32 in the call like so...

self.action_space = spaces.Box(low, high, dtype=np.float32)

If that doesn't work, set the logger level lower in gym like so...

import gym
gym.logger.set_level(40)
like image 43
Robert Wilkerson Avatar answered Nov 06 '22 18:11

Robert Wilkerson