You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
at each step the agent has access to previous 1000 prices + current price of stock = 1001 and it can take 3 possible action from 0,1,2
then i wrapped it in TFPyEnvironment to convert it to tf_environment
the prices that the agent can observe is a 1d numpy array prices = [584.95 582.3 581.7 ... 107.35 107.2 107.2 ]
then i build a dqn agent but i want to build it with a Conv1d layer
my network consist of
Conv1D,
MaxPool1D,
Conv1D,
MaxPool1D,
Dense_64,
Dense_32 ,
q_value_layer
i created a list layers using tf.keras.layers api and stored it in dense_layers list and created a Sequential Network
DQN_Agent
learning_rate = 1e-3
action_tensor_spec = tensor_spec.from_spec(tf_env.action_spec())
num_actions = action_tensor_spec.maximum - action_tensor_spec.minimum + 1
dense_layers = []
dense_layers.append(tf.keras.layers.Conv1D(
64,
kernel_size=(10),
activation=tf.keras.activations.relu,
input_shape=(1,1001),
))
dense_layers.append(
tf.keras.layers.MaxPool1D(
pool_size=2,
strides=None,
padding='valid',
))
dense_layers.append(tf.keras.layers.Conv1D(
64,
kernel_size=(10),
activation=tf.keras.activations.relu,
))
dense_layers.append(
tf.keras.layers.MaxPool1D(
pool_size=2,
strides=None,
padding='valid',
))
dense_layers.append(
tf.keras.layers.Dense(
64,
activation=tf.keras.activations.relu,
))
dense_layers.append(
tf.keras.layers.Dense(
32,
activation=tf.keras.activations.relu,
))
q_values_layer = tf.keras.layers.Dense(
num_actions,
activation=None,
kernel_initializer=tf.keras.initializers.RandomUniform(
minval=-0.03, maxval=0.03),
bias_initializer=tf.keras.initializers.Constant(-0.2))
q_net = sequential.Sequential(dense_layers + [q_values_layer])`
`optimizer = tf.keras.optimizers.Adam(learning_rate=learning_rate)
train_step_counter = tf.Variable(0)
agent = dqn_agent.DqnAgent(
tf_env.time_step_spec(),
tf_env.action_spec(),
q_network=q_net,
optimizer=optimizer,
td_errors_loss_fn=common.element_wise_squared_loss,
train_step_counter=train_step_counter)
agent.initialize()`
>but when i passed the q_net as a q_network to DqnAgent i came accross this error
`---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
[<ipython-input-98-41189fb31406>](https://localhost:8080/#) in <module>()
68 optimizer=optimizer,
69 td_errors_loss_fn=common.element_wise_squared_loss,
---> 70 train_step_counter=train_step_counter)
71
72 agent.initialize()
7 frames
[/usr/local/lib/python3.7/dist-packages/tf_agents/networks/sequential.py](https://localhost:8080/#) in call(self, inputs, network_state, **kwargs)
222 else:
223 # Does not maintain state.
--> 224 inputs = layer(inputs, **layer_kwargs)
225
226 return inputs, tuple(next_network_state)
ValueError: Exception encountered when calling layer "sequential_54" (type Sequential).
Input 0 of layer "conv1d_104" is incompatible with the layer: expected min_ndim=3, found ndim=2. Full shape received: (1, 1001)
Call arguments received by layer "sequential_54" (type Sequential):
• inputs=tf.Tensor(shape=(1, 1001), dtype=float32)
• network_state=()
• kwargs={'step_type': 'tf.Tensor(shape=(1,), dtype=int32)', 'training': 'None'}
In call to configurable 'DqnAgent' (<class 'tf_agents.agents.dqn.dqn_agent.DqnAgent'>)
i know it has something to do with the input shape of first layer of cov1d but cant figure out what am doing wrong
at each time_step the agent is reciveing a observation of prices of 1d array of length 1001 then the input shape of conv1d should be (1,1001) but its wrong and i don't know how to solve this error
need help
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
env = TradingEnv(df=df.head(100000), lkb=1000)
tf_env = tf_py_environment.TFPyEnvironment(env)
TimeStep Specs
TimeStep Specs: TimeStep( {'discount': BoundedTensorSpec(shape=(), dtype=tf.float32, name='discount', minimum=array(0., dtype=float32), maximum=array(1., dtype=float32)), 'observation': BoundedTensorSpec(shape=(1001,), dtype=tf.float32, name='_observation', minimum=array(0., dtype=float32), maximum=array(3.4028235e+38, dtype=float32)), 'reward': TensorSpec(shape=(), dtype=tf.float32, name='reward'), 'step_type': TensorSpec(shape=(), dtype=tf.int32, name='step_type')}) Action Specs: BoundedTensorSpec(shape=(), dtype=tf.int32, name='_action', minimum=array(0, dtype=int32), maximum=array(2, dtype=int32))
DQN_Agent
Beta Was this translation helpful? Give feedback.
All reactions