François Chollet:Python と Keras によるディープラーニング

作成日 : 2025-03-19
最終更新日 :

概要

原題は「 Deep Learning with Python」。 サポートページには、本書のコードが置かれている。
https://github.com/fchollet/deep-learning-with-python-notebooks
おそらく、R と Keras によるディープラーニングの姉妹書だろう。

Sequential クラス

p.64 などで、Sequential クラスを使ったモデル定義は次のようになっている。

from keras import models
from keras import layers

model = models.Sequential()
model.add(layers.Dense(32, activation='relu', input_shape=(784,)))
model.add(layers.Dense(10, activation='softmax'))

だが、実際には inpus_shape のある行で、次のエラーが発生する

UserWarning: Do not pass an `input_shape`/`input_dim` argument to a layer. When using Sequential models, prefer using an `Input(shape)` object as the first layer in the model instead.

このエラーを回避するには、input_shape のある行を次のように2つに分ければいい。

model.add(layers.Input(shape=(784,)))
model.add(layers.Dense(32, activation='relu'))

なお、上記と同様のエラーは、p.72 のリスト 3-3 などでも生じる。対処方法も同様だ。

コンパイルステップ

p.64 で、学習プロセスはコンパイルステップで設定されることがのべられていて、一般的なケースは損失関数が1つだけのモデルが説明されている。 本書の定義は次のとおりである。

from keras import optimizers

model.compile(optimizer=optimizers.RMSprop(lr=0.001),loss='mse', metrics=['accuracy'])

だが、このコードを実行すると次のエラーになる。

ValueError: Argument(s) not recognized: {'lr': 0.001}

そのため、コンパイルステップを次のように書く必要がある。

model.compile(optimizer=optimizers.RMSprop(learning_rate=0.001),loss='mse', metrics=['accuracy'])

なお、上記と同様のエラーは、p.73 のリスト 3-5 などでも生じる。対処方法も同様だ。

書誌情報

書名 Python と Keras によるディープラーニング
著者 François Chollet
発行日 2018 年 10 月 25 日(初版第 4 刷)
発行所 マイナビ出版
定価 3800 円(本体)
サイズ A5 変形 判
ISBN 978-4-8399-6426-9
その他 草加市立図書館で借りて読む

まりんきょ学問所コンピュータの部屋コンピュータの本ニューロコンピューティング・人工知能 > François Chollet:Python と Keras によるディープラーニング


MARUYAMA Satosi