尝试运行测试示例时出现此错误。
无法获得卷积算法。这可能是因为cuDNN无法初始化,所以请尝试查看上面是否打印了警告日志消息。
我尝试了对发现here的conda的推荐过程。创建新环境,安装Tensorflow-GPU。安装Jupyter Notebook并测试一些代码。我曾尝试更改cudatoolkit和cudnn的版本,但似乎无法弄清楚该如何做。安装Tensorflow-GPU会将Cudatoolkit 10.0.130和cudnn 7.6放入。
import tensorflow as tf
mnist = tf.keras.datasets.mnist
(train_images, train_labels), (test_images, test_labels) = mnist.load_data()
train_images = train_images.reshape(60000, 28, 28, 1)
test_images = test_images.reshape(10000, 28, 28, 1)
train_images, test_images = train_images/255, test_images/255
model = tf.keras.Sequential([
tf.keras.layers.Conv2D(32, (3,3), activation='relu', input_shape (28,28,1)),
tf.keras.layers.Conv2D(64, (3,3), activation='relu'),
tf.keras.layers.MaxPooling2D(2,2),
tf.keras.layers.Dropout(0.25),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dropout(0.5),
tf.keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
import time
start_time=time.time()
model.fit(train_images, train_labels, batch_size=128, epochs=15, verbose=1,
validation_data=(test_images, test_labels))
print('Training took {} seconds'.format(time.time()-start_time))
答案 0 :(得分:0)
为了使堆栈溢出社区受益,尽管在GitHub中提供了解决方案,但仍在此处发布解决方案。
您可以在程序的开头添加以下代码,将解决您的问题
from tensorflow.compat.v1 import ConfigProto
from tensorflow.compat.v1 import InteractiveSession
config = ConfigProto()
config.gpu_options.allow_growth = True
session = InteractiveSession(config=config)
有关更多详细信息,请参阅此Github线程。