Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save kawashimaken/816040e167958586d9e6b98f7e017cda to your computer and use it in GitHub Desktop.

Select an option

Save kawashimaken/816040e167958586d9e6b98f7e017cda to your computer and use it in GitHub Desktop.

Revisions

  1. kawashimaken revised this gist Apr 19, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tensorflow_simplest_neural_network_program.py
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@

    # データセットをロードする
    # アンパックして、それぞれtraine_dataとtest_dataに格納
    # train_Data:60000個、test_data:10000個
    # train_data:60000個、test_data:10000個
    (train_data, train_teacher_labels), (test_data, test_teacher_labels) = mnist.load_data()

    # 正則化
  2. kawashimaken created this gist Apr 19, 2019.
    41 changes: 41 additions & 0 deletions tensorflow_simplest_neural_network_program.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    from __future__ import absolute_import, division, print_function, unicode_literals
    import tensorflow as tf

    # MNISTのデータセットを使う
    mnist = tf.keras.datasets.mnist

    # データセットをロードする
    # アンパックして、それぞれtraine_dataとtest_dataに格納
    # train_Data:60000個、test_data:10000個
    (train_data, train_teacher_labels), (test_data, test_teacher_labels) = mnist.load_data()

    # 正則化
    # 0-1の間に分布するように変換
    train_data, test_data = train_data / 255.0, test_data / 255.0

    # シーケンシャルモデル定義
    # 入力層ニューロン数:28x28個
    # 中間層ニューロン数:512個、ReLu活性化関数
    # ドロップアウト層
    # 出力層ニューロン数:10個、ソフトマックス活性化関数、確率へ変換してくれる
    model = tf.keras.models.Sequential([
    tf.keras.layers.Flatten(input_shape=(28, 28)),
    tf.keras.layers.Dense(512, activation=tf.nn.relu),
    tf.keras.layers.Dropout(0.2),
    tf.keras.layers.Dense(10, activation=tf.nn.softmax)
    ])

    # モデルのセットアップ
    # 最適化アルゴリズム:Adam
    # 損失関数:sparse_categorical_crossentropy
    # 評価関数:accuracy
    model.compile(optimizer='adam',
    loss='sparse_categorical_crossentropy',
    metrics=['accuracy'])

    # 学習
    # エポック5回
    model.fit(train_data, train_teacher_labels, epochs=5)

    # 検証
    model.evaluate(test_data, test_teacher_labels)