【发布时间】:2017-07-04 13:48:27
【问题描述】:
我正在传递一个 [64,240] tf.array。 我想将其重塑为 [64,10,24] tf.array。 我尝试了各种不同的方法,但总是遇到同样的错误。
... raise ValueError("Shape %s must have rank %d" % (self, rank)) ValueError: Shape (64, 240) 必须有排名 1
代码在以下位置失败: self.x_expand[i] = tf.reshape(self.input_x[i],[num_classes,data_size])
我想我犯了一个基本错误,希望有人能指出它是什么......
更大的代码片段是:
类 CNN(对象):
def __init__(
self, sequence_length, num_classes, data_size,
filter_sizes, num_filters, l2_reg_lambda=0.0, batch_size=64):
# Placeholders for input, output and dropout
self.input_x = tf.placeholder(tf.int32, [batch_size, sequence_length], name="input_x")
self.input_y = tf.placeholder(tf.float32, [batch_size, num_classes], name="input_y")
self.dropout_keep_prob = tf.placeholder(tf.float32, name="dropout_keep_prob")
with tf.device('/cpu:0'), tf.name_scope("reshaping"):
self.x_expand = tf.placeholder(tf.int32, [batch_size, num_classes,data_size], name="expand_x")
for i in range(batch_size):
self.x_expand[i] = tf.reshape(self.input_x[i],[num_classes,data_size])
self.x_expanded = tf.expand_dims(self.x_expanded, -1)
【问题讨论】:
标签: python-3.x tensorflow