uehncfch 2020-02-01 22:38 采纳率: 40%
浏览 1654
已结题

TensorFlow报错:Shape (44, ?) must have rank at least 3 ?

用TensorFlow执行RNN,报错ValueError: Shape (44, ?) must have rank at least 3,下面是程序的部分代码,请问应该在哪里修改下?谢谢

解析函数:

feature = ['feature1',......,'feature44']
label = 'label2'
featureNames = list(feature)
featureNames.append(label)
columns = [tf.FixedLenFeature(shape=[1], dtype=tf.float32) for k in featureNames]
featuresDict = dict(zip(featureNames, columns))
def parse_tfrecord(example_proto):
  parsed_features = tf.parse_single_example(example_proto, featuresDict)
  labels = parsed_features.pop(label)
  return parsed_features, tf.cast(labels, tf.int32)

输入函数(原始数据是有44个特征值的数值序列,每个序列为一样本):

def tfrecord_input_fn(fileName,numEpochs=None,shuffle=True,batchSize=None):
  #读取tfrecord数据
  dataset = tf.data.TFRecordDataset(fileName, compression_type='GZIP')
  #执行解析函数
  dataset = dataset.map(parse_tfrecord)
  #打乱数据
  if shuffle:
    dataset = dataset.shuffle(buffer_size=batchSize * 100*numEpochs)
  #每32个样本作为一个batch
  dataset = dataset.batch(32)
  #重复数据
  dataset = dataset.repeat(numEpochs)

  print('features:',features)
  print('labels:',labels)
  iterator = dataset.make_one_shot_iterator()
  features, labels = iterator.get_next()
  return features, labels

打印返回值结果:

features: {'feature1': <tf.Tensor 'IteratorGetNext_21:0' shape=(?, 1) dtype=float32>, 'feature2': <tf.Tensor 'IteratorGetNext_21:1' shape=(?, 1) dtype=float32>,......, 'feature44': <tf.Tensor 'IteratorGetNext_21:43' shape=(?, 1) dtype=float32>}
labels: Tensor("IteratorGetNext_21:44", shape=(?, 1), dtype=int32)

执行网络后报错:

ValueError: Shape (44, ?) must have rank at least 3
  • 写回答

1条回答 默认 最新

  • threenewbee 2020-02-02 15:38
    关注

    该错误的意思是传入的数据集X的维度只有二维,而tf.nn.dynamic_rnn()要求传入的数据集的维度是三维(batch_size, squence_length, num_features)。在这里因为特征是一维,因此没有显示。

    https://www.cnblogs.com/jiangxinyang/p/9390355.html

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog