Ошибка типа: пара ключ-значение в данных не имеет одинаковую форму: (?,), (?, 1)
Я хотел бы реализовать нейронную сеть BCNN свертки Bayesien, но я получаю ошибку, это мой код
def conv2d(self,x, W, stride, pad='VALID'):
return tf.nn.conv2d(x, W, strides=[1, stride, stride, 1], padding=pad)
def BuildModel(self):
self.x = tf.placeholder(tf.float32, shape=[None,36, 148, 3], name="x")
self.angle_ = tf.placeholder(tf.float32, shape=[None, 1], name="y_")
self.first_keep_prob = tf.placeholder(tf.float32, name="first_keep_prob")
self.second_keep_prob = tf.placeholder(tf.float32, name="second_keep_prob")
self.W_conv1 = Normal(loc=tf.zeros([5, 5, 3, 12]), scale=tf.ones([5, 5, 3, 12]), name="W_conv1")
self.b_conv1 = Normal(loc=tf.zeros([12]), scale=tf.ones([12]), name="b_conv1")
self.h_conv1 = tf.nn.elu(self.conv2d(self.x, self.W_conv1 , 2) + self.b_conv1 )
self.W_conv2 = Normal(loc=tf.zeros([5, 5, 12, 24]), scale=tf.ones([5, 5, 12, 24]), name="W_conv2")
self.b_conv2 = Normal(loc=tf.zeros([24]), scale=tf.ones([24]), name="b_conv2")
self.h_conv2 = tf.nn.elu(self.conv2d(self.h_conv1, self.W_conv2, 2 , 'SAME' ) + self.b_conv2 )
self.h_conv2_flat = tf.reshape(self.h_conv2, [-1,864])
self.W_fc1 = Normal(loc=tf.zeros([864, 100]), scale=tf.ones([864, 100]), name="W_fc1")
self.b_fc1 = Normal(loc=tf.zeros([100]), scale=tf.ones([100]), name="b_fc1")
self.h_fc1 = tf.nn.elu(tf.matmul(self.h_conv4_flat, self.W_fc1) + self.b_fc1)
self.h_fc1_drop = tf.nn.dropout(self.h_fc1, self.first_keep_prob)
self.W_fc2 = Normal(loc=tf.zeros([100, 50]), scale=tf.ones([100, 50]), name="W_fc2")
self.b_fc2 = Normal(loc=tf.zeros([50]), scale=tf.ones([50]), name="b_fc2")
self.h_fc2 = tf.nn.elu(tf.matmul(self.h_fc1_drop, self.W_fc2) + self.b_fc2)
self.h_fc2_drop = tf.nn.dropout(self.h_fc2, self.second_keep_prob)
self.W_fc3 = Normal(loc=tf.zeros([50, 10]), scale=tf.ones([50, 10]), name="W_fc3")
self.b_fc3 = Normal(loc=tf.zeros([10]), scale=tf.ones([10]), name="b_fc3")
self.h_fc3 = tf.nn.elu(tf.matmul(self.h_fc2_drop, self.W_fc3) + self.b_fc3)
self.h_fc3_drop = tf.nn.dropout(self.h_fc3, self.second_keep_prob)
self.W_fc4 = Normal(loc=tf.zeros([10, 1]), scale=tf.ones([10, 1]), name="W_fc4")
self.b_fc4 = Normal(loc=tf.zeros([1]), scale=tf.ones([1]), name="b_fc4")
self.y = Categorical(tf.matmul(self.h_fc3, self.W_fc4) + self.b_fc4)
T = 20
# number of samples
with tf.name_scope("posterior"):
self.qW_conv1 = Empirical(params = tf.Variable(1/1000 *tf.random_normal([T,5,5,3,12])))
self.qb_conv1 = Empirical(params = tf.Variable(1/1000 *tf.random_normal([T,12])))
self.qW_conv2 = Empirical(params = tf.Variable(1/1000 *tf.random_normal([T,5, 5, 12, 24])))
self.qb_conv2 = Empirical(params = tf.Variable(1/1000 *tf.random_normal([T,24])))
self.qW_fc1 = Empirical(params = tf.Variable(tf.random_normal([T,864, 100])))
self.qb_fc1 = Empirical(params = tf.Variable(1/1000 *tf.random_normal([T,100])))
self.qW_fc2 = Empirical(params = tf.Variable(1/1000 *tf.random_normal([T,100,50])))
self.qb_fc2 = Empirical(params = tf.Variable(1/1000 *tf.random_normal([T,50])))
self.qW_fc3 = Empirical(params = tf.Variable(1/1000 *tf.random_normal([T,50,10])))
self.qb_fc3 = Empirical(params = tf.Variable(1/1000 *tf.random_normal([T,10])))
self.qW_fc4 = Empirical(params = tf.Variable(1/1000 *tf.random_normal([T,10,1])))
self.qb_fc4 = Empirical(params = tf.Variable(1/1000 *tf.random_normal([T,1])))
inference = ed.SGHMC({W_conv1: qW_conv1, b_conv1: qb_conv1, W_conv2: qW_conv2, b_conv2: qb_conv2,W_fc1: qW_fc1, b_fc1: qb_fc1, W_fc2: qW_fc2, b_fc2: qb_fc2,W_fc3: qW_fc3, b_fc3: qb_fc3,W_fc4: qW_fc4, b_fc4: qb_fc4}, data={y: y_})
inference.initialize()
inference.run(n_iter=1000,n_samples=5)
и я получаю следующую ошибку
File "/Users/bcn/src/edward/edward/inferences/sghmc.py", line 41, in __init__
super(SGHMC, self).__init__(*args, **kwargs)
File "/Users/bcn/src/edward/edward/inferences/monte_carlo.py", line 93, in __init__
super(MonteCarlo, self).__init__(latent_vars, data)
File "/Users/bcn/src/edward/edward/inferences/inference.py", line 80, in __init__
check_data(data)
File "/Users/bcn/src/edward/edward/util/random_variables.py", line 43, in check_data
"shape: {}, {}".format(key.shape, value.shape))
TypeError: Key-value pair in data does not have same shape: (?,), (?, 1)