ユーザ用ツール

サイト用ツール


2_データ準備_keras

文書の過去の版を表示しています。


(2)データの準備(Keras)

Keras2でMNIST目次

Kerasプログラミングの全体図

  1. (2)データ準備(Keras) ⇐ いまココ

以下のような流れになります。Numpy配列についての知識が必要です。Numpy配列については、Chainer用の画像処理メモ(5)初めてのNumPy"import numpy as np"Chainer用の画像処理メモ(6)画像をNumpy配列に変換をご覧いただければ幸いです。

#2 データ準備(Keras)
image_list = []
label_list = []
# 画像を読み込み、リサイズ、正規化などを行い、
# Numpy配列に変換し、「学習用データ」と「テストデータ」を作成する。
X_train, X_test, y_train, y_test = train_test_split(image_list, label_list, test_size=0.33, random_state=111)

自前データを利用する場合に最も大事な部分であり、最初は、かなりとっつきにくい部分となります。
具体的な方法について興味のある方はKeras2用自前データの準備をご覧ください。
今回は一番最初のチュートリアルなので、以下のようにKerasが用意しているMNISTデータセット(画像ではなく、既に数値の配列に変換されているもの)を用いて行います。
(MNISTデータを用いるときしかできません。自前データを利用する場合は真似できない方法であり、あくまでチュートリアル用の方法です。)

#2 データ準備(Keras)(MNISTの場合)
# Kerasが用意しているMNISTデータセットをダウンロードしてx_train, y_train, x_test, y_testに代入
(x_train, y_train), (x_test, y_test) = mnist.load_data()

x_train = x_train.reshape(60000, 784)
x_test = x_test.reshape(10000, 784)
x_train = x_train.astype('float32')
x_test = x_test.astype('float32')
x_train /= 255
x_test /= 255

参考文献

初めて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>

&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>

リンク

2_データ準備_keras.1509911426.txt.gz · 最終更新: 2018/10/07 (外部編集)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki