训练Tensorflow RNN估计器时发生InvalidArgumentError

时间:2019-07-03 00:07:44

标签: python-3.x tensorflow python-3.6 recurrent-neural-network tensorflow-estimator

我正在尝试使用Tensorflow来训练一个简单的RNN估计器,该构造器如下所示:

sequence_feature_colums = [tf.contrib.feature_column.sequence_numeric_column("price", shape=...)]    
estimator = tf.contrib.estimator.RNNEstimator(
    head=tf.contrib.estimator.regression_head(),
    sequence_feature_columns=sequence_feature_colums,
    rnn_cell_fn=...)

features = {"price": <multi-dimentional numpy array>}
labels = <uni-dimentional numpy array>

estimator.train(input_fn=lambda:train_input_fn(features, labels), steps=100)

,输入函数定义如下:

def train_input_fn(features, labels):
    dataset = tf.data.Dataset.from_tensor_slices((dict(features), labels))    
    dataset = dataset.batch(64)
    iterator = dataset.make_one_shot_iterator()    
    return iterator.get_next()

不幸的是,在估算器上调用train时出现以下错误:

InvalidArgumentError (see above for traceback): indices[35] = 64 is not in [0, 64)
     [[node rnn/select_last_activations/GatherV2 (defined at /Users/luke/virtualenvs/smp-rnn/lib/python3.6/site-packages/tensorflow_estimator/contrib/estimator/python/estimator/rnn.py:171) ]]

我完全了解可能是什么原因,只是索引所能包含的范围似乎与批次大小相对应。我的代码与example included with the RNN Estimator docs非常相似,因此我不太确定自己做错了什么。

  • tensorflow version:1.13.1
  • tensorflow-estimator version:1.13.0
  • python --version:3.6.5

0 个答案:

没有答案