Skip to content

initialize variable under variable scope? #24

@feng-1985

Description

@feng-1985

The correct one:

    with tf.variable_scope(scope) as scope:
        w = tf.get_variable("weights", [x.shape[1], out_dim], initializer=tf.random_normal_initializer())
        b = tf.get_variable("biases", [out_dim], initializer=tf.constant_initializer(0.0))

The following code will raise the error: TypeError: Failed to convert object of type <class 'list'> to Tensor. Contents: [Dimension(100), 50]. Consider casting elements to a supported type.

    with tf.variable_scope(scope) as scope:
        w = tf.get_variable(initializer=tf.random_normal([x.shape[1], out_dim]), name='weights')
        b = tf.get_variable(initializer=tf.zeros([out_dim]), name='biases')

What's happened?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions