【问题标题】:TensorFlow, TypeError: random_normal() got an unexpected keyword argument 'partition_info'TensorFlow,TypeError:random_normal() 得到了一个意外的关键字参数“partition_info”
【发布时间】:2017-10-18 09:14:00
【问题描述】:

运行这段代码时(TensorFlow模型中的第一个卷积层):

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 参数并且错误消失了。如果我重新引入它,错误似乎又出现了。

【问题讨论】:

    标签: python-2.7 machine-learning tensorflow convolution


    【解决方案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。

    【讨论】:

      【解决方案2】:

      你只需要在tf.random_normal之后添加()

      weights_initializer = tf.random_normal()
      

      【讨论】:

        猜你喜欢
        • 2018-07-31
        • 1970-01-01
        • 1970-01-01
        • 2016-09-17
        • 2015-06-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-01
        相关资源
        最近更新 更多