0
1

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.

8GPUでKeras (TensorFlow1.2統合版)が使えるか試してみる

Last updated at Posted at 2017-07-10

動作環境

  • Ubuntu16.04.2 desktop amd64
  • Nvidia GeForce GTX 680 を8枚

ではまず

nvida-smiの出力はこのような結果

nvidia-smi-8gpu.png

nvidiaドライバは動作している。

次に、以下のような簡単なKeras-tensorflowコードを用意して、

#!/usr/bin/env python3
import numpy as np

import tensorflow.contrib.keras as keras
from tensorflow.contrib.keras.python.keras.models import Sequential
from tensorflow.contrib.keras.python.keras.layers import Dense, Activation, Dropout
from tensorflow.contrib.keras.python.keras.optimizers import SGD
from tensorflow.contrib.keras.python.keras import backend as K

if __name__ == '__main__':

    x_train = np.random.random((1000, 20))
    y_train = keras.utils.to_categorical(np.random.randint(10, size=(1000, 1)), num_classes=10)
    x_test = np.random.random((100, 20))
    y_test = keras.utils.to_categorical(np.random.randint(10, size=(100, 1)), num_classes=10)

    model = Sequential()
    model.add(Dense(64, activation='relu', input_dim=20))
    model.add(Dropout(0.5))
    model.add(Dense(64, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(10, activation='softmax'))

    sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
    model.compile(loss='categorical_crossentropy',
                                optimizer=sgd,
                                metrics=['accuracy'])

    model.fit(x_train, y_train,
                        epochs=1000,
                        batch_size=128)

    score = model.evaluate(x_test, y_test, batch_size=128)

    K.clear_session()

そして、実行してみる。

keras-8gpu.png

8GPUを認識まではしている。

さてさて、次回のお楽しみ

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?