TensorFlow,类型错误:random_normal()得到了意想不到的关键字参数 'partition_info'
问题描述:
当运行该代码段(第一卷积层在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参数,错误消失。如果我再次引入它,错误似乎又出现了。
答
卷积函数之前添加此功能定义:
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的。