agents icon indicating copy to clipboard operation
agents copied to clipboard

Conv1D Option for Networks

Open kochlisGit opened this issue 1 year ago • 5 comments

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

kochlisGit avatar Oct 04 '22 08:10 kochlisGit

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)

sibyjackgrove avatar Oct 06 '22 17:10 sibyjackgrove

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...

kochlisGit avatar Oct 06 '22 18:10 kochlisGit

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.

sguada avatar Oct 10 '22 11:10 sguada

@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.

kochlisGit avatar Oct 10 '22 11:10 kochlisGit

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

sguada avatar Oct 10 '22 15:10 sguada