用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