11
4

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.

"negative dimension size caused by subtracting 5 from 1" の対応策(keras)

Last updated at Posted at 2017-04-27

概要

tensorflow バックエンドでt ensorflow で書かれたコードを keras で走らせたところ
negative dimension size caused by subtracting 5 from 1
というエラーが出た。解決策を探していたところ色々なサイトが出てきて混乱したので個人的まとめ
(subtractiong 5 from 1 の部分は n from 1 で置き換えても大丈夫です)

環境

  • keras 2.0.3
  • tensorflow 1.0.1
  • Anaconda 4.3.1
  • python 3.5.2
  • Windows 10

解決策

keras.json を開く。ファイルの場所は、 Anaconda の仮想環境を立ち上げて、 python で keras.json の場所を調べることができる。

python
import os
print (os.path.expanduser('~'))

調べた場所にある keras.json を、以下のように編集する。
"image_data_format" を "channels_last" から "channels_first" に書き直す。

keras.json
{
    "epsilon": 1e-07,
-   "image_data_format": "channels_last",
+   "image_data_format": "channels_first"
    "floatx": "float32",
    "backend": "tensorflow"
}

保存して、元のコードを実行したところエラーが出なくなった。

参考

11
4
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
11
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?