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

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 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题