繁体   English   中英

TensorFlow错误:TensorShape()必须具有相同的等级

[英]TensorFlow error: TensorShape() must have the same rank

def compileActivation(self, net, layerNum):
    variable = net.x if layerNum == 0 else net.varArrayA[layerNum - 1]
    #print tf.expand_dims(net.dropOutVectors[layerNum], 1)

    #print net.varWeights[layerNum]['w'].get_shape().as_list()

    z = tf.matmul((net.varWeights[layerNum]['w']), (variable * (tf.expand_dims(net.dropOutVectors[layerNum], 1) if self.dropout else 1.0))) + tf.expand_dims(net.varWeights[layerNum]['b'], 1)

    a = self.activation(z, self.pool_size)
    net.varArrayA.append(a)

我正在运行一个激活函数,该函数计算z并将其传递到S型激活中。 当我尝试执行上述功能时,出现以下错误:

ValueError: Shapes TensorShape([Dimension(-2)]) and TensorShape([Dimension(None), Dimension(None)]) must have the same rank

用于计算z的theano等效项工作正常:

z = T.dot(net.varWeights[layerNum]['w'], variable * (net.dropOutVectors[layerNum].dimshuffle(0, 'x') if self.dropout else 1.0)) + net.varWeights[layerNum]['b'].dimshuffle(0, 'x')

米希尔,

当我遇到此问题时,这是因为占位符在Feed字典中的大小错误。 您还应该知道如何在会话中运行图形。 tf.Session.run(fetches,feed_dict = None)

这是我制作占位符的代码

# Note this place holder is for the input data feed-dict definition
input_placeholder = tf.placeholder(tf.float32, shape=(batch_size, FLAGS.InputLayer))
# Not sure yet what this will be used for. 
desired_output_placeholder = tf.placeholder(tf.float32, shape=(batch_size, FLAGS.OutputLayer))

这是我的填充提要字典功能:

def feel_feed_funct(data_sets_train, input_pl, output_pl):
  ti_feed, dto_feed = data_sets_train.next_batch(FLAGS.batch_size)

  feed_dict = {
    input_pl: ti_feed,
    output_pl: dto_feed
  }
  return feed_dict

后来我这样做:

# Fill a feed dictionary with the actual set of images and labels
# for this particular training step.
feed_dict = fill_feed_dict(data_sets.train, input_placeholder, desired_output_placeholder)

然后运行会话并获取输出,我有这一行

_, l = sess.run([train_op, loss], feed_dict=feed_dict)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM