2
3

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 エラーメモ

Last updated at Posted at 2016-11-22

最近 TensorFlow を触りだしたので、遭遇したエラーとその対応をメモしていきます。
随時書き足していきます。

placeholder / Variable の次元を間違えた

ValueError: Dimensions must be equal, but are 780 and 784

原因

placeholder, Variable の次元数が間違っています。(整合性が保てていません)

ニューラルネットワークで言えば、 placeholder はニューロンで、 Variable は重みやバイアスなどの変数です。

image

上のようなネットワークがあったとき、 placeholder = ニューロンの数をまず決めると思います。
その後それに合わせて、前後のニューロン間の Variable = 重みを決めると思いますが、重みの次元が前後のニューロンの次元とマッチしていない場合などに起こります。

(この図では簡単のためバイアスの Variable は省略しています)

イメージとしては上記のような感じですが、厳密にはどのような行列演算がなされるかを考えてみればわかると思います。

属性が無い

AttributeError: module 'tensorflow.models.rnn.ptb.reader' has no attribute 'ptb_producer'

原因

pip install した TensorFlow のバージョンと、 git clone してきた TensorFlow のバージョンがちがうかもしれません。
例えば pip install で v0.11 をインストールし、 v0.12 以降のソースコードを git clone してきてその中のサンプルで実行をしている場合に起きたりします。

対応

参照しているソースコード側を適切なバージョンのブランチに切り替えましょう。

python を実行して pip install した tensorflow のバージョンを調べます。

>>> import tensorflow
>>> tensorflow.__version__
'0.11.0'

pip install したバージョンを check out します。

git checkout -b r0.11 origin/r0.11

参考

Can't import reader.py correctly for rnn/ptb/

tensorflow 直下で import tensorflow しない

ImportError: cannot import name 'pywrap_tensorflow'

原因

clone してきた tensorflow 直下で python から import tensorflow しようとするとこのエラーが出るようです。
PyCharm とかで実行するとこうなってしまう?

対応

別のディレクトリで実行しましょう。

参考

ImportError: cannot import name pywrap_tensorflow

2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?