0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Windows10でTensorFlow2.0,Keras,MNISTメモ

Posted at

動作環境

Windows10 Home
RTX2080

Anacondaのインストール

CUDA

cuDNN

Anacondapromptを起動

conda create -n [仮想環境名] python=3.7 jupyter
activate [仮想環境名]

tensorflowをインストール

pip install tensorflow-gpu

バージョン確認
import tensorflow as tf
tf.__version__
'2.0.0'

kerasをインストール

pip install keras

バージョン確認
import keras
Using TensorFlow backend.
keras.__version__
'2.3.1'

MNISTで動作確認

mnist.py
import tensorflow as tf

# MNIST データセットをロードして準備します。サンプルを整数から浮動小数点数に変換します。
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0

# 層を積み重ねてtf.keras.Sequentialモデルを構築します。訓練のためにオプティマイザと損失関数を選びます。
model = tf.keras.models.Sequential([
  tf.keras.layers.Flatten(input_shape=(28, 28)),
  tf.keras.layers.Dense(128, activation='relu'),
  tf.keras.layers.Dropout(0.2),
  tf.keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

# モデルを訓練してから評価します。
model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test,  y_test, verbose=2)

その他必要なものをインストール

pip install Protobuf Pillow lxml
pip install Jupyter
pip install Matplotlib

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?