tensortrade-org / tensortrade

An open source reinforcement learning framework for training, evaluating, and deploying robust trading agents.
https://discord.gg/ZZ7BGWh
Apache License 2.0
4.54k stars 1.03k forks source link

python/numpy default float type is float64. We prefer float32 instead. #231

Closed lefig closed 4 years ago

lefig commented 4 years ago

Hi all,

I have just started to learn about this fabulous project. But I have experienced a brick wall with respect to the examples. I try running train_and_evaluate notebook from the examples folder but have the error:

=== AGENT ID: 3f342cc3-2914-4288-a94e-4f5c1caae52d ====

ValueError Traceback (most recent call last)

in 3 agent = DQNAgent(env) 4 ----> 5 agent.train(n_steps=200, save_path="examples/agents/") C:\work\python\3.6.7\python-3.6.7.amd64\lib\site-packages\tensortrade\agents\dqn_agent.py in train(self, n_steps, n_episodes, save_every, save_path, callback, **kwargs) 165 continue 166 --> 167 self._apply_gradient_descent(memory, batch_size, learning_rate, discount_factor) 168 169 if n_steps and steps_done >= n_steps: C:\work\python\3.6.7\python-3.6.7.amd64\lib\site-packages\tensortrade\agents\dqn_agent.py in _apply_gradient_descent(self, memory, batch_size, learning_rate, discount_factor) 92 batch = DQNTransition(*zip(*transitions)) 93 ---> 94 state_batch = tf.convert_to_tensor(batch.state) 95 action_batch = tf.convert_to_tensor(batch.action) 96 reward_batch = tf.convert_to_tensor(batch.reward, dtype=tf.float32) C:\work\python\3.6.7\python-3.6.7.amd64\lib\site-packages\tensorflow\python\framework\ops.py in convert_to_tensor(value, dtype, name, preferred_dtype, dtype_hint) 1085 preferred_dtype = deprecation.deprecated_argument_lookup( 1086 "dtype_hint", dtype_hint, "preferred_dtype", preferred_dtype) -> 1087 return convert_to_tensor_v2(value, dtype, preferred_dtype, name) 1088 1089 C:\work\python\3.6.7\python-3.6.7.amd64\lib\site-packages\tensorflow\python\framework\ops.py in convert_to_tensor_v2(value, dtype, dtype_hint, name) 1143 name=name, 1144 preferred_dtype=dtype_hint, -> 1145 as_ref=False) 1146 1147 C:\work\python\3.6.7\python-3.6.7.amd64\lib\site-packages\tensorflow\python\framework\ops.py in internal_convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, ctx, accept_symbolic_tensors, accept_composite_tensors) 1222 1223 if ret is None: -> 1224 ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) 1225 1226 if ret is NotImplemented: C:\work\python\3.6.7\python-3.6.7.amd64\lib\site-packages\tensorflow\python\framework\constant_op.py in _constant_tensor_conversion_function(v, dtype, name, as_ref) 303 as_ref=False): 304 _ = as_ref --> 305 return constant(v, dtype=dtype, name=name) 306 307 C:\work\python\3.6.7\python-3.6.7.amd64\lib\site-packages\tensorflow\python\framework\constant_op.py in constant(value, dtype, shape, name) 244 """ 245 return _constant_impl(value, dtype, shape, name, verify_shape=False, --> 246 allow_broadcast=True) 247 248 C:\work\python\3.6.7\python-3.6.7.amd64\lib\site-packages\tensorflow\python\framework\constant_op.py in _constant_impl(value, dtype, shape, name, verify_shape, allow_broadcast) 282 tensor_util.make_tensor_proto( 283 value, dtype=dtype, shape=shape, verify_shape=verify_shape, --> 284 allow_broadcast=allow_broadcast)) 285 dtype_value = attr_value_pb2.AttrValue(type=tensor_value.tensor.dtype) 286 const_tensor = g.create_op( C:\work\python\3.6.7\python-3.6.7.amd64\lib\site-packages\tensorflow\python\framework\tensor_util.py in make_tensor_proto(values, dtype, shape, verify_shape, allow_broadcast) 473 """ - got shape %s, but wanted %s.""" % 474 (values, list(nparray.shape), --> 475 _GetDenseDimensions(values))) 476 477 # python/numpy default float type is float64. We prefer float32 instead. ValueError: Argument must be a dense tensor: (array([[ 2.59448999e+03, 2.63092993e+03, 2.59448999e+03, 2.36788917e+00, 2.63092993e+03, 5.99174614e+01, 9.02229125e+05, 2.82579987e+02, 2.82579987e+02, ............... ............ Thank you in advance!
lefig commented 4 years ago

Any suggestions would be really welcome.

Does the example need updating?

MarkintoshZ commented 4 years ago

What version of tensorflow and numpy are you using?

lefig commented 4 years ago

Thank you for taking a look. I do appreciate this. We are running on Win:

Tensorflow 1.14.0 numpy+mkl package 1.17.5

On python 3.6.7

lefig commented 4 years ago

What are your thoughts please? Could the problem be version related...

netsalesbg-ltd commented 4 years ago

You have to use TensorFlow >= 2.0.

IISuperluminaLII commented 4 years ago

import numpy from tf.experimental.numpy and the dtypes should be resolved to what Tensorflow "likes". Or you can set numpy dtype globally, a quick google search should tell you how to do that. TF 2.0 would't work since stable_baselines is supported for tf version <= 1.14 since gym/OpenAI needs tensorflow.contrib package

mwbrulhardt commented 4 years ago

Use TF 2.0 as this does not use stable-baselines so there is not conflict.