简体   繁体   English

如何使用 Conda 安装 Tensorflow 2.0 安装?

[英]How to install Tensorflow 2.0 install with Conda?

I get this error when I try to run a test example.当我尝试运行测试示例时出现此错误。

Failed to get convolution algorithm.获取卷积算法失败。 This is probably because cuDNN failed to >initialize, so try looking to see if a warning log message was printed above.这可能是因为 cuDNN 未能>初始化,因此请尝试查看上面是否打印了警告日志消息。

I have tried a recommended process for conda found here .我已经尝试了在这里找到的 conda 的推荐过程。 Create new environment install Tensorflow-GPU.创建新环境安装 Tensorflow-GPU。 Install Jupyter Notebook and test some code.安装 Jupyter Notebook 并测试一些代码。 I have tried changing versions of cudatoolkit and cudnn but I can't seem to figure out how to do this.我曾尝试更改 cudatoolkit 和 cudnn 的版本,但我似乎无法弄清楚如何做到这一点。 The install Tensorflow-GPU puts Cudatoolkit 10.0.130 and cudnn 7.6.安装 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))

For the benefit of stack overflow community, posting solution here though it presented in GitHub.为了堆栈溢出社区的利益,尽管它在 GitHub 中提出,但在此处发布解决方案。

You can add below code in the beginning of program, will resolve your issue您可以在程序开头添加以下代码,将解决您的问题

from tensorflow.compat.v1 import ConfigProto
from tensorflow.compat.v1 import InteractiveSession

config = ConfigProto()
config.gpu_options.allow_growth = True
session = InteractiveSession(config=config)

For more details please refer this Github thread.有关更多详细信息,请参阅此Github线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM