question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom FeedForwardPolicy does not care for net_arch parameters

See original GitHub issue

Describe the bug I am trying to create my own Custom Policy network, however when I check the tensorboard logs and look under graphs I can see that it does not create the network as specified after my cnn extraction: net_arch=[64, dict(pi=[64, 64], vf=[64, 64])],

Code example

class CustomPolicy(FeedForwardPolicy):

    def __init__(self, *args, **kwargs,):
        super(CnnExtractor, self).__init__(*args, **kwargs,
                                           cnn_extractor=custom_cnn,
                                           act_fun=tf.nn.relu,
                                           net_arch=[64, dict(pi=[64, 64],
                                                          vf=[64, 64])],
                                           feature_extraction='cnn', )


def custom_cnn(scaled_images, **kwargs):
    """

    :param scaled_images: (TensorFlow Tensor) Image input placeholder
    :param kwargs: (dict) Extra keywords parameters for the convolutional layers of the CNN
    :return: (TensorFlow Tensor) The CNN output layer
    """
    activ = tf.nn.relu
    layer_1 = activ(conv(scaled_images, 'c1', n_filters=18, filter_size=2, stride=1, **kwargs))
    layer_2 = activ(conv(layer_1, 'c2', n_filters=64, filter_size=2, stride=1, **kwargs))
    layer_3 = activ(conv(layer_2, 'c3', n_filters=64, filter_size=2, stride=1, **kwargs))
    layer_3 = conv_to_fc(layer_3)
    return activ(linear(layer_3, 'fc1', n_hidden=64))

I have attached the tensboard files here: logs.zip

System Info Describe the characteristic of your environment:

  • Describe how the library was installed (pip, docker, source, …)
    • PIP
  • GPU models and configuration
    • GTX 1070
  • Python version
    • 3.7
  • Tensorflow version
  • 1.15.0

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
araffincommented, Feb 23, 2021

Wait so I can’t have my network like this in stable_baselines:

You need to redefine the policy completely for that, see https://stable-baselines.readthedocs.io/en/master/guide/custom_policy.html whereas SB3 supports that easily.

It is just that the stable_baslines3 does not support adding the NN graph to tensorboard, which was the main reason I discovered the mistake here

See https://stable-baselines3.readthedocs.io/en/master/guide/tensorboard.html#directly-accessing-the-summary-writer and https://github.com/DLR-RM/stable-baselines3/issues/286

0reactions
HadiSDevcommented, Feb 23, 2021

Alright

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Policy Network - Stable Baselines - Read the Docs
The net_arch parameter of FeedForwardPolicy allows to specify the amount and size of the hidden layers and how many of them are shared...
Read more >
Understanding custom policies in stable-baselines3
What I can say after i went through all the library code. CnnPolicy is differ to MlpPolicy only in implemented default BaseFeatureExtraction ...
Read more >
Define Custom Deep Learning Layer with Learnable Parameters
This example shows how to define a PReLU layer and use it in a convolutional neural network.
Read more >
Adding Custom Actions - Juniper Networks
Values that are passed to the custom action script. These properties are not based on the events or flow themselves, but cover other...
Read more >
Using Custom Tuning Parameters When Tuning a Neural ...
Note: Input data must be accessible in your CAS session, either as a CAS table or as a transient-scope table. A CAS table...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found