samre12 / deep-trading-agent

Deep Reinforcement Learning based Trading Agent for Bitcoin
MIT License
751 stars 212 forks source link

InvalidArgumentError (see above for traceback): Input to reshape is a tensor wit h 80640 values, but the requested shape has 115200 #8

Closed txizzle closed 6 years ago

txizzle commented 6 years ago

Hi, cool project.

Getting a weird error during training when using the same config as example.cfg:

KeyError: KeyError(<weakref at 0x7f3801e2a628; to 'tqdm' at 0x7f38019d88d0>,) in
 <bound method tqdm.__del__ of   0%|                    | 24866/25000000 [00:05<
1:24:55, 4901.45it/s]> ignored
Traceback (most recent call last):
  File "main.py", line 38, in <module>
    main(vars(args)['file_path'])
  File "main.py", line 29, in main
    agent.train()
  File "/home/ted/projects/deep-trading-agent/code/model/agent.py", line 71, in 
train
    self.observe(screen, reward, action, terminal, trade_rem)
  File "/home/ted/projects/deep-trading-agent/code/model/agent.py", line 170, in
 observe
    self.q_learning_mini_batch()
  File "/home/ted/projects/deep-trading-agent/code/model/agent.py", line 186, in
 q_learning_mini_batch
    self.t_trade_rem_t: trade_rem_t_plus_1
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.
py", line 905, in run
    run_metadata_ptr)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.
py", line 1137, in _run
    feed_dict_tensor, options, run_metadata)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.
py", line 1355, in _do_run
    options, run_metadata)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.
py", line 1374, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to reshape i
s a tensor with 80640 values, but the requested shape has 115200
         [[Node: t_q_network/Reshape_1 = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _d
evice="/job:localhost/replica:0/task:0/device:GPU:0"](t_q_network/conv_layers/co
nv_layer_2/conv_2/Relu, t_q_network/Reshape_1/shape)]]
         [[Node: t_q_network/q_values/BiasAdd/_139 = _Recv[client_terminated=fal
se, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/jo
b:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_na
me="edge_274_t_q_network/q_values/BiasAdd", tensor_type=DT_FLOAT, _device="/job:
localhost/replica:0/task:0/device:CPU:0"]()]]

Caused by op u't_q_network/Reshape_1', defined at:
  File "main.py", line 38, in <module>
    main(vars(args)['file_path'])
  File "main.py", line 28, in main
    agent = Agent(sess, logger, config, env)
  File "/home/ted/projects/deep-trading-agent/code/model/agent.py", line 44, in 
__init__
    self.build_dqn(params)
  File "/home/ted/projects/deep-trading-agent/code/model/agent.py", line 254, in
 build_dqn
    self.t_q.build_model((self.t_s_t, self.t_trade_rem_t))
  File "/home/ted/projects/deep-trading-agent/code/model/deepsense.py", line 150
, in build_model
    self.params.window_size * self.params.filter_sizes[-1]
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_o
ps.py", line 3903, in reshape
    "Reshape", tensor=tensor, shape=shape, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_de
f_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.p
y", line 3271, in create_op
    op_def=op_def)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.p
y", line 1650, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-
access

InvalidArgumentError (see above for traceback): Input to reshape is a tensor wit
h 80640 values, but the requested shape has 115200
         [[Node: t_q_network/Reshape_1 = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _d
evice="/job:localhost/replica:0/task:0/device:GPU:0"](t_q_network/conv_layers/co
nv_layer_2/conv_2/Relu, t_q_network/Reshape_1/shape)]]
         [[Node: t_q_network/q_values/BiasAdd/_139 = _Recv[client_terminated=fal
se, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/jo
b:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_na
me="edge_274_t_q_network/q_values/BiasAdd", tensor_type=DT_FLOAT, _device="/job:
localhost/replica:0/task:0/device:CPU:0"]()]]

Any idea for what this is from?

samre12 commented 6 years ago

Hi @txizzle , thanks for pointing out this bug. With padding=SAME, the code works just fine, the issue is introduced in VALID padding for the convolutional network. I am working to remove the bug in the next commit to the master branch.