内容へ移動
サルでもわかる機械学習
ユーザ用ツール
ログイン
サイト用ツール
検索
ツール
文書の表示
以前のリビジョン
バックリンク
最近の変更
メディアマネージャー
サイトマップ
ログイン
>
最近の変更
メディアマネージャー
サイトマップ
トレース:
6_学習結果の保存_keras
この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。
===== (6)学習結果の保存(Keras) ===== <wrap hi>Keras2でMNIST目次</wrap>\\ [[Kerasプログラミングの全体図]] -[[(1)Kerasを使用するためのimport文]] -[[(2)データ準備(Keras)]] -[[(3)モデル設定(Keras)]] -[[(4)モデル学習(Keras)]] -[[(5)結果の出力(Keras)]] -[[(6)学習結果の保存(Keras)]] <wrap hi><= いまココ</wrap> -[[(7)推測(Keras)]] 以下をコピペするだけです。 <code> #6 学習結果の保存(Keras) ### save model and weights json_string = model.to_json() open('apple_orange_model.json', 'w').write(json_string) model.save_weights('apple_orange_weights.h5') </code> そのままです。学習モデルをjson形式で保存し、そのモデルに対応した学習結果のパラメータをh5形式で保存します。\\ 次のpredict.pyで、新しい画像の予測(分類)を行う際に、このモデルとパラメータを読み込む予定です。 ===== 開発環境 ===== Windows 8.1\\ Anaconda \\ Python 3.5\\ Tensorflow 1.4\\ Keras 2.0.9\\ Keras2.0のインストール方法は[[windowsにkeras2.0をインストール]]をご覧下さい。 このページは、[[(5)結果の出力(Keras)]]の続きであり、今回は、結果の出力を行っていきます。 ===== 手順 ===== ==== 0. 前回終了時の画面 ==== [[(5)結果の出力(Keras)]]終了時の、以下のような状態から始めます。 {{:pasted:20171110-055117.png}} ==== 1. 学習結果の保存 ==== 以下のコードを入力して、Shift + Enterを押します。 <code> #6 学習結果の保存(Keras) ### save model and weights json_string = model.to_json() open('apple_orange_model.json', 'w').write(json_string) model.save_weights('apple_orange_weights.h5') </code> 以下のような画面になります。 {{:pasted:20171110-055228.png}} Jupyter Notebook上では何も起こりませんが、 <code> %ls </code> と入力して、Shift+Enterを押すと、以下のように表示されて、train_MNIST_MLP.ipynb(今、入力しているJupyter Notebookのファイル)と同じフォルダに、 <code> "apple_orange_model.json" : モデルが記載されたjsonファイル "apple_orange_weights.h5" : モデルのweight(学習結果)が記載されたバイナリデータ </code> の2つのファイルが作成されていることが分かります。 {{:pasted:20171110-055811.png}} {{:pasted:20171110-055914.png}} Kerasでの学習結果の出力の手順は上記でおしまいです。 初めての方は、次は、<wrap hi>[[(7)推測(Keras)]]</wrap>に進んでください。 ===== 参考文献 ===== 初めてKerasプログラミングをやるときの超おすすめ本。\\ <html> <iframe style="width:120px;height:240px;" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src="//rcm-fe.amazon-adsystem.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=twosquirrel-22&o=9&p=8&l=as4&m=amazon&f=ifr&ref=as_ss_li_til&asins=4873117585&linkId=13a7db2c19cc5f40d6ab48906de8abd1"></iframe> <iframe style="width:120px;height:240px;" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src="//rcm-fe.amazon-adsystem.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=twosquirrel-22&o=9&p=8&l=as4&m=amazon&f=ifr&ref=as_ss_li_til&asins=4839962510&linkId=d722909965b5eab4196d370757843f6f"></iframe> </html> ===== リンク ===== 次 [[(7)推測(Keras)]] 前 [[(5)結果の出力(Keras)]] <wrap hi>Keras2でMNIST目次</wrap>\\ [[Kerasプログラミングの全体図]] -[[(1)Kerasを使用するためのimport文]] -[[(2)データ準備(Keras)]] -[[(3)モデル設定(Keras)]] -[[(4)モデル学習(Keras)]] -[[(5)結果の出力(Keras)]] -[[(6)学習結果の保存(Keras)]] -[[(7)推測(Keras)]]
6_学習結果の保存_keras.txt
· 最終更新: 2018/10/07 (外部編集)
ページ用ツール
文書の表示
以前のリビジョン
バックリンク
文書の先頭へ