3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

TensorflowでRNNを構築する際にValueErrorが出たときの対処法

Posted at

環境

Windows 10
Python 3.6.2
Tensorflow 1.5.0

エラー内容

TensorflowにてRNNを構築して、実行時に下記のエラーが出ました。

  • コード
error.py
n_hidden = 20
n_batch = tf.placeholder(tf.int32)
cell = tf.nn.rnn_cell.BasicRNNCell(n_hidden)
initial_state = cell.zero_state(n_batch, tf.float32)
  • エラー
ValueError: prefix tensor must be either a scalar or vector, but saw tensor: Tensor("Placeholder_2:0", dtype=int32)

対処

zero_stateに渡しているn_batchのshapeが未指定ということらしいです。
以下のように対処します。

n_batch = tf.placeholder(tf.int32, shape=[])

参考

BasicLSTMCell zero_state() raise error in TF1.2 but works in TF1.1

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?