anacondaを導入し仮想環境作成, gpuをpcに認識させることはできたのですが, tensorflow-gpuが上手く動いていないのか,kerasの問題なのかわかりませんが, お試しのコードを実行する際エラーを吐きます.versionをいじったりしてみたのですが原因が特定できません.知識のある方良ければ教えていただけると幸いです.osはubuntu Linuxです
各version情報↓
python 3.6.13 cudatoolkit 9.0 cuDNN 7.1.2 tensorflow -gpu 1.10.0
また, cuda-smiで表示されるcudaのversionは11.2となっているのですがこれはどうしてなんでしょうか...
コード↓
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout
from keras.layers import Flatten, MaxPooling2D, Conv2D
from keras.callbacks import TensorBoard
(X_train,y_train), (X_test, y_test) = mnist.load_data()
X_train = X_train.reshape(60000,28,28,1).astype('float32')
X_test = X_test.reshape(10000,28,28,1).astype('float32')
X_train /= 255
X_test /= 255
n_classes = 10
y_train = keras.utils.to_categorical(y_train, n_classes)
y_test = keras.utils.to_categorical(y_test, n_classes)
model = Sequential()
model.add(Conv2D(32, kernel_size=(3,3), activation='relu', input_shape=(28,28,1)) )
model.add(Conv2D(64, kernel_size=(3,3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(n_classes, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
tensor_board = TensorBoard('./logs/LeNet-MNIST-1')
model.fit(X_train, y_train, batch_size=128, epochs=15, verbose=1,
validation_data=(X_test,y_test), callbacks=[tensor_board])
エラー↓
AttributeError Traceback (most recent call last)
<ipython-input-1-0e059a229002> in <module>
----> 1 import keras
2 from keras.datasets import mnist
3 from keras.models import Sequential
4 from keras.layers import Dense, Dropout
5 from keras.layers import Flatten, MaxPooling2D, Conv2D
~/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/keras/init.py in <module>
1 from future import absolute_import
2
----> 3 from . import utils
4 from . import activations
5 from . import applications
~/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/keras/utils/init.py in <module>
4 from . import data_utils
5 from . import io_utils
----> 6 from . import conv_utils
7 from . import losses_utils
8 from . import metrics_utils
~/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/keras/utils/conv_utils.py in <module>
7 from six.moves import range
8 import numpy as np
----> 9 from .. import backend as K
10
11
~/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/keras/backend/init.py in <module>
----> 1 from .load_backend import epsilon
2 from .load_backend import set_epsilon
3 from .load_backend import floatx
4 from .load_backend import set_floatx
5 from .load_backend import cast_to_floatx
~/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/keras/backend/load_backend.py in <module>
88 elif _BACKEND == 'tensorflow':
89 sys.stderr.write('Using TensorFlow backend.\n')
---> 90 from .tensorflow_backend import *
91 else:
92 # Try and load external backend.
~/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py in <module>
52
53 # Private TF Keras utils
---> 54 get_graph = tf_keras_backend.get_graph
55 # learning_phase_scope = tf_keras_backend.learning_phase_scope # TODO
56 name_scope = tf.name_scope
AttributeError: module 'tensorflow.python.keras.backend' has no attribute 'get_graph'
回答1件
あなたの回答
tips
プレビュー