AndreaF
AndreaF

Reputation: 12385

Tensorflow error when I try to use tf.contrib.layers.convolution2d

When I invoke tf.contrib.layers.convolution2d the tensorflow execution terminates with an error about one of the parameters used

got an unexpected keyword argument 'weight_init'

The parameter passed are the follows:

layer_one = tf.contrib.layers.convolution2d(
    float_image_batch,
    num_output_channels=32,     
    kernel_size=(5,5),          
    activation_fn=tf.nn.relu,
    weight_init=tf.random_normal,
    stride=(2, 2),
    trainable=True)

That is exactly as described in the book that I'm reading. I suspect a possible syntax problem with weight_init=tf.random_normal written directly inside the call, but I don't know how to fix. I'm using Tensorflow 0.12.0

Upvotes: 0

Views: 1138

Answers (1)

PraveenPalanisamy
PraveenPalanisamy

Reputation: 546

The book that you are reading (You didn't mention which one) might be using an older version of TensorFlow when the initial values for the weight tensor was passed through the weight_init argument. In the TensorFlow library version you are using (You didn't mention your TF version), probably that argument is replaced with weight_initializer. The latest (TensorFlow v0.12.0) documentation for tf.contrib.layers.convolution2d is here.

To fix your problem, you can change the following line in your code:

weight_init=tf.random_normal

to

weight_initializer=tf.random_normal_initializer()

According to the documentation, by default, tf.random_normal_initialier uses a 0.0 mean, a standard deviation of 1.0 and the datatype to be tf.float32. You may change the arguments as per your need using this line instead: weight_initializer=tf.random_normal_initializer(mean=0.0, stddev=1.0, seed=None, dtype=tf.float32)

Upvotes: 3

Related Questions