Skip to content

tf.layers.dense does not pass through name to the Keras Layer #484

Closed

Description

@moloneymb

This is needed so that dense layers can be specifically named so that the dense layer variable scope names line up with the pre-trained models.

https://github.com/tensorflow/tensorflow/blob/590d6eef7e91a6a7392c8ffffb7b58f2e0c8bc6b/tensorflow/python/layers/core.py#L185

I don't see the mechanism to do this in the TF.Net keras layer so for now I'll just make my own little dense layer. This is just a heads up that w/o fixing this it may be hard to load some pre-trained models.

Activity

  1. Oceania2018 commented on Jan 6, 2020

    @Oceania2018
    Member

    @moloneymb Do you have any Unit Test so that I can reproduce the problem?

  2. self-assigned this
    on Jan 6, 2020
  3. added
    missing feature/s
    on Jan 6, 2020
  4. moloneymb commented on Jan 6, 2020

    @moloneymb
    ContributorAuthor

    I can make a unit test tomorrow.

  5. moloneymb commented on Jan 7, 2020

    @moloneymb
    ContributorAuthor

    I'm tired atm and I keep screwing up the pull request. But the following unit test will surface the bug.

    namespace TensorFlowNET.UnitTest.layers_test
    {
        [TestClass]
        public class dense
        {
            [TestMethod]
            public void Case1()
            {
                var sess = tf.Session().as_default();
                var x = tf.ones(new TensorShape(10, 10));
                var y = tf.layers.dense(x, 20, name: "test");
                Assert.AreEqual("test/BiasAdd:0", y.name); // test name_scope
                Assert.AreEqual("test/bias", y.op.inputs[1].op.inputs[0]); // test variable_scope
            }
        }
    }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

missing feature/s

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions