2017-10-18 252 views
1

當運行該代碼段(第一卷積層在TensorFlow模型):TensorFlow,類型錯誤:random_normal()得到了意想不到的關鍵字參數 'partition_info'

conv2d_layer_one = tf.contrib.layers.convolution2d(
    float_image_batch, 
    num_outputs = 32, 
    kernel_size = (5, 5), 
    activation_fn=tf.nn.relu, 
    weights_initializer = tf.random_normal, 
    stride =(2, 2), 
    trainable= True 
) 

我得到這個錯誤:

TypeError: random_normal() got an unexpected keyword argument 'partition_info' 

tf.random_normal函數沒有引入任何參數,比如partition_info,所以我有點困惑,因爲這個錯誤會出現。

我刪除了weights_initializer參數,錯誤消失。如果我再次引入它,錯誤似乎又出現了。

回答

1

卷積函數之前添加此功能定義:

from tensorflow.python.ops import random_ops 

def _initializer(shape, dtype=tf.float32, partition_info=None): 
    return random_ops.random_normal(shape) 

並調用_initializer代替tf.random_normal的。

相關問題