Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid arguments while using QNetwork #384

Closed
bazylip opened this issue May 27, 2020 · 1 comment
Closed

Invalid arguments while using QNetwork #384

bazylip opened this issue May 27, 2020 · 1 comment

Comments

@bazylip
Copy link

bazylip commented May 27, 2020

I am implementing Wumpus World in Tensorflow using DQN with discrete action space and encounter following error while trying to collect data using greedy policy
tensorflow.python.framework.errors_impl.InvalidArgumentError: 'then' and 'else' must have the same size. but received: [1,1] vs. [1] [Op:Select]
raised by this line in EpsilonGreedyPolicy
action = tf.compat.v1.where(cond, greedy_action.action, random_action.action)
I reckon this is the same issue as in #255 and #253 but applying workarounds mentioned there to RandomTFPolicy does not work and the error still remains the same. However, when I change network which I am using from:

class QNetwork(q_network.QNetwork):

    def __init__(self, input_tensor_spec, action_spec, num_actions, name=None):
        super(QNetwork, self).__init__(
            input_tensor_spec=input_tensor_spec,
            action_spec=action_spec,
            name=name)
        self._sub_layers = [
            tf.keras.layers.Dense(num_actions),
        ]

    def call(self, inputs, step_type=None, network_state=(), **kwargs):
        del step_type
        inputs = tf.cast(inputs, tf.float32)
        for layer in self._sub_layers:
            inputs = layer(inputs)
        return inputs, network_state

to simply:

q_net = q_network.QNetwork(
            train_env.observation_spec(),
            train_env.action_spec(),
            fc_layer_params=(100,))

then the exception is not raised. Of course such network is not what I am looking for to base my agent's policy on, so I would be very thankful for any suggestions what might be wrong in my code.

@tfboyd
Copy link
Member

tfboyd commented Sep 11, 2021

Closing due to age and lack of recent activity. If the issue still exists, please open a new issue and reference this one.

@tfboyd tfboyd closed this as completed Sep 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants