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

Conv1D Option for Networks #779

Open
kochlisGit opened this issue Oct 4, 2022 · 5 comments
Open

Conv1D Option for Networks #779

kochlisGit opened this issue Oct 4, 2022 · 5 comments

Comments

@kochlisGit
Copy link

Hello,
I have noticed that EncodingNetwork has set its conv_type to 2d by default, but there is no way to actually change this parameter. Am i missing anything?

@gin.configurable
class EncodingNetwork(network.Network):
  """Feed Forward network with CNN and FNN layers."""

  def __init__(self,
               input_tensor_spec,
               preprocessing_layers=None,
               preprocessing_combiner=None,
               conv_layer_params=None,
               fc_layer_params=None,
               dropout_layer_params=None,
               activation_fn=tf.keras.activations.relu,
               weight_decay_params=None,
               kernel_initializer=None,
               batch_squash=True,
               dtype=tf.float32,
               name='EncodingNetwork',
               conv_type=CONV_TYPE_2D):

This is the constructor of the Encoding Network. However, no Network allows to change the conv_type.... It is always set on 2D.
Thanks

@sibyjackgrove
Copy link

I don't think there is an option for 2D. I had the same requirement and ended up defining my own 1D CNN network and passing it as a preprocessing layer when creating the Actor networ.

preprocessing_layers = tf.keras.models.Sequential([tf.keras.layers.Conv1D(filters=16,kernel_size=1, activation='relu'),
                                                                  tf.keras.layers.Conv1D(filters=32,kernel_size=1, activation='relu'),
                                                                  tf.keras.layers.Flatten(),
                                                                  tf.keras.layers.Dense(units=64, activation='relu'),])

actor_net = actor_distribution_rnn_network.ActorDistributionRnnNetwork(
          tf_env.observation_spec(),
          tf_env.action_spec(),
          preprocessing_layers = preprocessing_layers,
          preprocessing_combiner=None,
          input_fc_layer_params=actor_fc_layers,
          output_fc_layer_params=None,
          lstm_size=lstm_size)

@kochlisGit
Copy link
Author

Well, I found a way around this.... I copied the ActorDistributionNetwork class and just passed the argument to the encoding network and it worked! However, it's such a shame that tf-agents, which also supported by tensorflow, doesn't support such simple thing...

@sguada
Copy link
Member

sguada commented Oct 10, 2022

For customized networks you need to create your own network, similar to what sibyjackgrove mentioned.

I'm confused, it seems that EncodingNetwork allows 1D Convolutions.

@kochlisGit
Copy link
Author

kochlisGit commented Oct 10, 2022

@sguada
Hello,
It does allow 1D convolutions. However, the ActionDistributionNetwork class does not allow you to pass CONV_TYPE_1D to the parameter "conv_type" of the encoding network.

@sguada
Copy link
Member

sguada commented Oct 10, 2022

Can you make a PR to allow passing conv_type from ActionDistributionNetwork to EncodingNetwork?

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

3 participants