ユーザ用ツール

サイト用ツール


1_kerasを使用するためのimport文

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
1_kerasを使用するためのimport文 [2017/10/27] adash3331_kerasを使用するためのimport文 [2019/08/04] (現在) – [2. Import文の入力(Copy and Paste)] adash333
行 1: 行 1:
 ===== (1)Kerasを使用するためのimport文 ===== ===== (1)Kerasを使用するためのimport文 =====
-<KerasでMNIST目次>\\ +<wrap hi>Keras2でMNIST目次</wrap>\\ 
-[[Kerasプログラミングの全体図]]\\ +[[Kerasプログラミングの全体図]] 
-[[(1)Kerasを使用するためのimport文]]\\ +  -[[(1)Kerasを使用するためのimport文]] <wrap hi><= いまココ</wrap> 
-[[(2)データ準備(Keras)]]\\ +  -[[(2)データ準備(Keras)]] 
-[[(3)モデル設定(Keras)]]\\ +  -[[(3)モデル設定(Keras)]] 
-[[(4)モデル学習(Keras)]]\\ +  -[[(4)モデル学習(Keras)]] 
-[[(5)結果の出力(Keras)]]\\ +  -[[(5)結果の出力(Keras)]] 
-[[(6)学習結果の保存(Keras)]]\\ +  -[[(6)学習結果の保存(Keras)]] 
-[[(7)推測(Keras)]]\\+  -[[(7)推測(Keras)]]
  
 最初に以下をコピペするだけですが、プログラムごとに、さらにimport文の追加が必要になる場合があります。 最初に以下をコピペするだけですが、プログラムごとに、さらにimport文の追加が必要になる場合があります。
行 34: 行 34:
 http://twosquirrel.mints.ne.jp/?p=20344 http://twosquirrel.mints.ne.jp/?p=20344
  
 +
 +上記コードを見ても最初はさっぱりだと思いますが、[[(7)推測|(7)推測(Chainer)]]まで読み終えた後、もう一度このページに戻ってきて、「ああ、ここでこれを使用するためにこれをimportしたんだなあ」くらいに思い出していただければと思います。
 +===== 開発環境 =====
 +Windows 8.1\\
 +Anaconda \\
 +Python 3.5\\
 +Tensorflow 1.4\\
 +Keras 2.0.9\\
 +
 +Keras2.0のインストール方法は[[windowsにkeras2.0をインストール]]をご覧下さい。
 +
 +以下は、上記リンクに記載のように、Anaconda Promptで、keras2という仮想環境を作成し、Keras 2.0をインストールしてある前提で、話を進めさせて頂きます。
 +===== 手順 =====
 +今回から、
 +
 +
 +
 +に従って、jupyter notebook上で、Keras2でMNIST手書き文字認識の機械学習を行い、Keras2プログラミングを学んでいきます。
 +
 +==== 0. AnacondaのインストールとKeras2仮想環境 ====
 +
 +(前提1)WindowsパソコンにAnacondaをインストール済み。\\
 +インストールしていない場合は、以下をご覧になり、インストールしておいてください。\\ [[http://twosquirrel.mints.ne.jp/dokuwiki/doku.php/windows%E3%81%A7python%E3%82%92%E5%A7%8B%E3%82%81%E3%82%8B%E6%96%B9%E6%B3%952017%E5%B9%B4%E7%89%88#3_windowsパソコンにanacondaをインストール_所要時間_約40分間|Anacondaのインストール]]
 +
 +(前提2)さらに、Anaconda Prompt上でkeras2.0をインストールしておく。\\
 +具体的な方法については、[[windowsにkeras2.0をインストール]]をご覧ください。
 +
 +==== 1. Jupyter Notebookの開始 ====
 +
 +Windowsのスタートボタンから、Anaconda Promptを起動
 +
 +{{:pasted:20171103-125512.png}}
 +
 +今回は、C:/py/keras/MNIST_MLP/ フォルダをWindowsで作成しておき、そちらに、ipynbファイルを作成して、プログラミングを行っていくこととします。
 +
 +Anaconda Prompt上で、以下のコマンドを入力
 +<code>
 +cd c:/py/keras/MNIST_MLP
 +</code>
 +keras2仮想環境を起動
 +<code>
 +activate keras2
 +</code>
 +Jupyter Notebookの起動
 +<code>
 +jupyter notebook
 +</code>
 +
 +{{:pasted:20171106-041410.png}}
 +
 +すると、ブラウザ(Chromeがお勧めです)が自動的に開いて、以下のような画面になるので、画面右側の方の「New」>「python3」の順にクリックして、新規Jupyter Notebookを作成。
 +
 +{{:pasted:20171103-173912.png}}
 +
 +新しいJupyter Notebookが開かれるので、画面上の方の「Untitled」をクリックして、名前を、「train_MNIST_MLP」に変更。
 +
 +{{:pasted:20171103-175203.png}}
 +
 +{{:pasted:20171106-041940.png}}
 +
 +以下のような状態からスタートします。
 +
 +{{:pasted:20171106-042015.png}}
 +
 +==== 2. Import文の入力(Copy and Paste) ====
 +
 +次のような状態になっていると思われます。
 +
 +{{:pasted:20171106-042240.png}}
 +
 +上図の部分に、Kerasプログラミングを開始するために必要な、以下のImport文をコピペします。
 +
 +<code>
 +import keras
 +from keras.models import Sequential
 +from keras.layers import Dense, Dropout
 +from keras.optimizers import RMSprop
 +from keras.utils import np_utils
 +
 +from sklearn.model_selection import train_test_split
 +
 +import numpy as np
 +from PIL import Image
 +import os
 +</code>
 +
 +さらに、Shift + Enter を押してから、数秒待つと、以下のようになります。
 +
 +{{:pasted:20171106-042357.png}}
 +
 +これで、Import文の入力は終了です。
 +
 +次に、<wrap hi>[[(2)データ準備(Keras)]]</wrap>を行っていきます。
  
 ===== 参考文献 ===== ===== 参考文献 =====
行 46: 行 139:
 <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> <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> </html>
 +
 +
 +機械学習で用いるpythonの”import xxx”まとめ
 +2017/10/25
 +http://twosquirrel.mints.ne.jp/?p=20344
 +
  
 ===== リンク ===== ===== リンク =====
  
-目次\\ +次 [[(2)データ準備(Keras)]] 
-[[Kerasプログラミングの全体図]]\\ + 
-[[(1)Kerasを使用するためのimport文]]\\ +前 [[Kerasプログラミングの全体図]] 
-[[(2)データ準備(Keras)]]\\ + 
-[[(3)モデル設定(Keras)]]\\ + 
-[[(4)モデル学習(Keras)]]\\ +<wrap hi>Keras2でMNIST目次</wrap>\\ 
-[[(5)結果の出力(Keras)]]\\ +[[Kerasプログラミングの全体図]] 
-[[(6)学習結果の保存(Keras)]]\\ +  -[[(1)Kerasを使用するためのimport文]] 
-[[(7)推測(Keras)]]\\+  -[[(2)データ準備(Keras)]] 
 +  -[[(3)モデル設定(Keras)]] 
 +  -[[(4)モデル学習(Keras)]] 
 +  -[[(5)結果の出力(Keras)]] 
 +  -[[(6)学習結果の保存(Keras)]] 
 +  -[[(7)推測(Keras)]]
  
  

1_kerasを使用するためのimport文.1509122613.txt.gz · 最終更新: 2018/10/07 (外部編集)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki