ユーザ用ツール

サイト用ツール


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文の追加が必要になる場合があります。
行 35: 行 35:
  
  
-===== 参考文献 ===== +上記コードを見ても最初はさっぱりだと思いますが、[[(7)推測|(7)推測(Chainer)]]まで読み終えた後、もう一度このページに戻ってきて、「ああ、ここでこれを使用するためにこれをimportしたんだなあ」くらいに思い出していただければと思います。 
-初めてKerasプログラミングをやるときの超おすすめ本。 +===== 開発環境 ===== 
-\\+Windows 8.1\\ 
 +Anaconda \\ 
 +Python 3.5\\ 
 +Tensorflow 1.4\\ 
 +Keras 2.0.9\\
  
-<html>+Keras2.0のインストール方法は[[windowsにkeras2.0をインストール]]をご覧下さい。
  
-<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>+以下は、上記リンクに記載のように、Anaconda Promptで、keras2という仮想環境を作成し、Keras 2.0をインストールしてある前提で、話を進めさせて頂きます。 
 +===== 手順 ===== 
 +今回から、
  
-&nbsp; 
  
-<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> 
  
-===== リク =====+に従って、jupyter notebook上で、Keras2でMNIST手書き文字認識の機械学習を行い、Keras2プログラミグを学んでいきます。
  
-目次\\ +==== 0. AnacondaのインストールとKeras2仮想環境 ====
-[[Kerasプログラミングの全体図]]\\ +
-[[(1)Kerasを使用するためのimport文]]\\ +
-[[(2)データ準備(Keras)]]\\ +
-[[(3)モデル設定(Keras)]]\\ +
-[[(4)モデル学習(Keras)]]\\ +
-[[(5)結果の出力(Keras)]]\\ +
-[[(6)学習結果の保存(Keras)]]\\ +
-[[(7)推測(Keras)]]\\ +
-===== 開発環境 ====+
-Panasonic CF-RZ4\\ +
-Windows 8.1 Pro\\ +
-Anaconda 4.4.0\\ +
-Python 3.5\\ +
-Chainer 2.0\\ +
-OpenCV3+
  
-Kerasのインストール方法は[[WindowsにKeras2.0をインストール]]をご覧下さい。+(前提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のインストール]]
  
-以下は、上記リンクに記載のように、Anaconda Promptで、デフォルトの仮想環境に、Keras 2.0をインストールしてある前提で進めせて頂きます+(前提2)さらに、Anaconda Promptkeras2.0をインストールしておく。\\ 
 +具体的な方法については[[windowsにkeras2.0インストール]]をご覧くだ
  
-===== 手順 ===== +==== 1. Jupyter Notebookの開始 ====
-今回から、+
  
-Chainer: ビギナー向けチュートリアル Vol.1\\ +Windowsのスタートボタンから、Anaconda Promptを起動
-https://qiita.com/mitmul/items/eccf4e0a84cb784ba84a+
  
-に従って、jupyter notebook上で、Chainer2でMNIST手書き文字認識の機械学習を行い、Chainer2プログラミングを学んでいきます。+{{:pasted:20171103-125512.png}}
  
-==== 1. Jupyter Notebookの起動 ==== +今回は、C:/py/keras/MNIST_MLP/ フォルダをWindowsで作成しておき、そちipynbファイル作成して、プログラミング行っていくこととします。
-C:/ ドライブ下に、chainer2/ フォルダを作成します。 +
- +
-{{:pasted:20171019-224111.png}} +
- +
-Windowsのスタートボタンから、Anaconda Prompt開いて、以下入力します。+
  
 +Anaconda Prompt上で、以下のコマンドを入力
 +<code>
 +cd c:/py/keras/MNIST_MLP
 +</code>
 +keras2仮想環境を起動
 +<code>
 +activate keras2
 +</code>
 +Jupyter Notebookの起動
 <code> <code>
-cd C:/chainer2 
-activate chainer2 
- 
 jupyter notebook jupyter notebook
 </code> </code>
  
-{{:pasted:20171019-224232.png}}+{{:pasted:20171106-041410.png}}
  
-この後Webブラウザ(Chromeがオススメです)が自動的に開、以下のような画面になります+すると、ブラウザ(Chromeがお勧めです)が自動的に開いて、以下のような画面になるので、画面右側の方の「New」>「python3」の順にクリックして、新規Jupyter Notebookを作成
  
-{{:pasted:20171019-224809.png}}+{{:pasted:20171103-173912.png}}
  
-==== 2. ipynbファイル作成とImport文の入力(Copy and Paste) ==== +新しいJupyter Notebookが開かれる、画面上の方のUntitled」をクリックして、名前を、「train_MNIST_MLP」に変更
-画面上のNew」をクリックして、Python 3 (または、chainer2)クリックして新しいipynbファイルを作成する+
  
-{{:pasted:20171019-224643.png}}+{{:pasted:20171103-175203.png}}
  
-以下のような画面になるので、一番上の、Untitled をクリックして、MNIST_MLP と入力してEnter。+{{:pasted:20171106-041940.png}}
  
-{{:pasted:20171019-225023.png}}+以下のような状態からスタートします。
  
-{{:pasted:20171019-225238.png}}+{{:pasted:20171106-042015.png}}
  
-以下ような画面になる。+==== 2. Import文入力(Copy and Paste) ====
  
-{{:pasted:20171019-225356.png}}+次のような状態になっていると思われます。
  
-上図の部分に、Chainerプログラミングを開始するために必要な、以下のImport文をコピペす+{{:pasted:20171106-042240.png}} 
 + 
 +上図の部分に、Kerasプログラミングを開始するために必要な、以下のImport文をコピペします。
  
 <code> <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 import numpy as np
-import chainer +from PIL import Image 
-from chainer import cuda, Function, report, training, utils, Variable +import os
-from chainer import datasets, iterators, optimizers, serializers +
-from chainer import Link, Chain, ChainList +
-import chainer.functions as F +
-import chainer.links as L +
-from chainer.training import extensions+
 </code> </code>
  
-さらに、Shift + Enter を押てから、数秒待つと、以下のようにな+さらに、Shift + Enter を押てから、数秒待つと、以下のようになります
  
-{{:pasted:20171019-225550.png}}+{{:pasted:20171106-042357.png}}
  
 これで、Import文の入力は終了です。 これで、Import文の入力は終了です。
  
-次に、[[(2)データ準備・設定]]を行っていきます。+次に、<wrap hi>[[(2)データ準備(Keras)]]</wrap>を行っていきます。
  
 ===== 参考文献 ===== ===== 参考文献 =====
-Chainer: ビギナー向けチュートリアル Vol.1 +初めてKerasプログラミングをやるときの超おすすめ本。\\
-mitmul +
-2017年05月18日に更新\\ +
-https://qiita.com/mitmul/items/eccf4e0a84cb784ba84a+
  
 <html> <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=B01NBMKH21&linkId=a7a35903a4c55f62d8aa012c3d0277d8"></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=4873117585&linkId=13a7db2c19cc5f40d6ab48906de8abd1"></iframe> 
 + 
 +&nbsp; 
 + 
 +<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
 +
  
 ===== リンク ===== ===== リンク =====
  
-<KerasでMNIST目次>\\ +次 [[(2)データ準備(Keras)]] 
-[[Kerasプログラミングの全体図]]\\ + 
-[[(1)Kerasを使用するためのimport文]]\\ +前 [[Kerasプログラミングの全体図]] 
-[[(2)データ準備・設定]]\\ + 
-[[(3)モデルの記述]]\\ + 
-[[(4)モデルと最適化アルゴリズムの設定]]\\ +<wrap hi>Keras2でMNIST目次</wrap>\\ 
-[[(5)学習(Trainerを利用しない場合)]]\\ +[[Kerasプログラミングの全体図]] 
-[[(6)結果の出力]]\\+  -[[(1)Kerasを使用するためのimport文]] 
 +  -[[(2)データ準備(Keras)]] 
 +  -[[(3)モデル設定(Keras)]] 
 +  -[[(4)モデル学習(Keras)]] 
 +  -[[(5)結果の出力(Keras)]] 
 +  -[[(6)学習結果の保存(Keras)]] 
 +  -[[(7)推測(Keras)]] 
  

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

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki