RTX显卡 运行TensorFlow=1.14.0 代码 报错 Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
硬件环境:
RTX2070super 显卡
软件环境:
Ubuntu18.04.5
Tensorflow = 1.14.0
---------------------------------------------------------------------
运行代码:
- import numpy as np
- import tensorflow as tf
- from tensorflow.examples.tutorials.mnist import input_data
- mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
- def dense(x, size, scope):
- return tf.contrib.layers.fully_connected(x, size,
- activation_fn=None, scope=scope)
- def dense_relu(x, size, scope):
- with tf.variable_scope(scope):
- h1 = dense(x, size, 'dense')
- return tf.nn.relu(h1, 'relu')
- tf.reset_default_graph()
- x = tf.placeholder('float32', (None, 784), name='x')
- y = tf.placeholder('float32', (None, 10), name='y')
- phase = tf.placeholder(tf.bool, name='phase')
- h1 = dense_relu(x, 100, 'layer1')
- h1 = tf.contrib.layers.batch_norm(h1,
- center=True, scale=True,
- is_training=phase,
- scope='bn_1')
- h2 = dense_relu(h1, 100, 'layer2')
- h2 = tf.contrib.layers.batch_norm(h2,
- center=True, scale=True,
- is_training=phase,
- scope='bn_2')
- logits = dense(h2, 10, scope='logits')
- with tf.name_scope('accuracy'):
- accuracy = tf.reduce_mean(tf.cast(
- tf.equal(tf.argmax(y, 1), tf.argmax(logits, 1)),
- 'float32'))
- with tf.name_scope('loss'):
- loss = tf.reduce_mean(
- tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=y))
- def train():
- update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
- with tf.control_dependencies(update_ops):
- train_step = tf.train.GradientDescentOptimizer(0.01).minimize(loss)
- sess = tf.Session()
- sess.run(tf.global_variables_initializer())
- history = []
- iterep = 500
- for i in range(iterep * 30):
- x_train, y_train = mnist.train.next_batch(100)
- sess.run(train_step,
- feed_dict={'x:0': x_train,
- 'y:0': y_train,
- 'phase:0': 1})
- if (i + 1) % iterep == 0:
- epoch = (i + 1)/iterep
- tr = sess.run([loss, accuracy],
- feed_dict={'x:0': mnist.train.images,
- 'y:0': mnist.train.labels,
- 'phase:0': 1})
- t = sess.run([loss, accuracy],
- feed_dict={'x:0': mnist.test.images,
- 'y:0': mnist.test.labels,
- 'phase:0': 0})
- history += [[epoch] + tr + t]
- print( history[-1] )
- return history
- train()
报错, 具体如下:
- 2020-08-09 21:03:53.837785: E tensorflow/stream_executor/cuda/cuda_dnn.cc:329] Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
- 2020-08-09 21:03:53.837987: W ./tensorflow/stream_executor/stream.h:1995] attempting to perform DNN operation using StreamExecutor without DNN support
- Traceback (most recent call last):
- File "/home/devil/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1356, in _do_call
- return fn(*args)
- File "/home/devil/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1341, in _run_fn
- options, feed_dict, fetch_list, target_list, run_metadata)
- File "/home/devil/anaconda3/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1429, in _call_tf_sessionrun
- run_metadata)
- tensorflow.python.framework.errors_impl.InternalError: cuDNN launch failure : input shape ([100,100,1,1])
- [[{{node bn_1/cond/FusedBatchNorm}}]]
- During handling of the above exception, another exception occurred:
不使用 显卡 进行计算,正常运行:
或:
主要语句:
- CUDA_VISIBLE_DEVICES=-1
正常运行:
如果 这种情况要仍然要使用 RTX 显卡, 那么 加入下面语句(对 会话session 的创建不使用默认设置,而是进行配置):
使用非交互的session时候,如下:
- gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.5)
- sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
或
- gpu_options = tf.GPUOptions( allow_growth = True )
- sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
或
- gpu_options = tf.GPUOptions( per_process_gpu_memory_fraction=0.5, allow_growth = True )
- sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
总之,就是不能使用默认配置的session,需要配置一下。
其中,
- per_process_gpu_memory_fraction=0.5
是指为该程序分配使用的显卡其内存不超过总内存的 0.5倍。
--------------------------------------------------------
发生该问题的原因:
Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR 这个问题大部分是因为RTX显卡不兼容它出生前的接口有关。
原因解释出自资料:
https://blog.csdn.net/pkuyjxu/article/details/89402298
-------------
对上面代码中对 tensor 进行运算的代码中 feed_dict 的形式不是很熟悉,即:
因为以前经常使用的形式为:
于是很好奇,将代码改为如下:
发现报错:
从报错中可以知道,原来 feed_dict 中的key 是可以用 所构建的图的tensor(用函数tf.placeholder生成的tensor) 在图内的名字来表示的,即 "<op_name>:<output_index>" , 也就是这里的 “x:0” 。
而我们以前常用的形式是 将构建图中tensor (用tf.placeholder生成的tensor)的那个变量 即 x 作为 feed_dict 中的key 的。
比如:
这里,我们相当于构建了一个tensor (用函数tf.placeholder生成的tensor), tensor的名字为 'xxx:0' , 但是所构建的这个tensor 的变量为 x 。
详细的说就是:
x = tf.placeholder('float32', (None, 784), name='x') 中, name="x" 是说这个tf.placeholer函数在图中所定义的操作( operation)的名字(name) 是 “xxx” , 而图中的这个操作产生的第0个tensor在图中的名字为 “xxx:0” , 而这个名字为 “xxx:0” 的tensor又传递给了python变量x , 因此在 feed_dict 中我们可以使用变量x 来表示这个tensor, 也可以使用这个tensor的图内的名字“xxx:0” 来表示。需要注意的是“xxx”是操作(operation)的名字,而不是tensor的名字。
对于 tensor 的这个 "<op_name>:<output_index>" 形式的表示还是很长知识的。
注:
这里传给 feed_dict 的变量都是使用 tf.placeholder生成的 tensor 的变量, 这种变量也是整个图所依赖的起始tensor的变量。
-----------------------------------------------------
以下给出 feed_dict 的两个混合写法的 代码:
- import numpy as np
- import tensorflow as tf
- from tensorflow.examples.tutorials.mnist import input_data
- mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
- def dense(x, size, scope):
- return tf.contrib.layers.fully_connected(x, size,
- activation_fn=None, scope=scope)
- def dense_relu(x, size, scope):
- with tf.variable_scope(scope):
- h1 = dense(x, size, 'dense')
- return tf.nn.relu(h1, 'relu')
- tf.reset_default_graph()
- x = tf.placeholder('float32', (None, 784), name='x')
- y = tf.placeholder('float32', (None, 10), name='y')
- phase = tf.placeholder(tf.bool, name='phase')
- h1 = dense_relu(x, 100, 'layer1')
- h1 = tf.contrib.layers.batch_norm(h1,
- center=True, scale=True,
- is_training=phase,
- scope='bn_1')
- h2 = dense_relu(h1, 100, 'layer2')
- h2 = tf.contrib.layers.batch_norm(h2,
- center=True, scale=True,
- is_training=phase,
- scope='bn_2')
- logits = dense(h2, 10, scope='logits')
- with tf.name_scope('accuracy'):
- accuracy = tf.reduce_mean(tf.cast(
- tf.equal(tf.argmax(y, 1), tf.argmax(logits, 1)),
- 'float32'))
- with tf.name_scope('loss'):
- loss = tf.reduce_mean(
- tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=y))
- def train():
- update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
- with tf.control_dependencies(update_ops):
- train_step = tf.train.GradientDescentOptimizer(0.01).minimize(loss)
- gpu_options = tf.GPUOptions( per_process_gpu_memory_fraction=0.5, allow_growth = True )
- sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
- #sess = tf.Session()
- sess.run(tf.global_variables_initializer())
- history = []
- iterep = 500
- for i in range(iterep * 30):
- x_train, y_train = mnist.train.next_batch(100)
- sess.run(train_step,
- feed_dict={x: x_train,
- 'y:0': y_train,
- phase: 1})
- if (i + 1) % iterep == 0:
- epoch = (i + 1)/iterep
- tr = sess.run([loss, accuracy],
- feed_dict={'x:0': mnist.train.images,
- y: mnist.train.labels,
- phase: 1})
- t = sess.run([loss, accuracy],
- feed_dict={x: mnist.test.images,
- y: mnist.test.labels,
- 'phase:0': 0})
- history += [[epoch] + tr + t]
- print( history[-1] )
- return history
- train()
RTX显卡 运行TensorFlow=1.14.0 代码 报错 Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR的更多相关文章
- Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR tensorflow-1.13.1和1.14windows版本目前不支持CUDA10.0
报错出现 Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR tensorflow-1.13.1和1.14windows版本目前不支持 ...
- CUDA报错: Cannot create Cublas handle. Cublas won't be available. 以及:Check failed: status == CUBLAS_STATUS_SUCCESS (1 vs. 0) CUBLAS_STATUS_NOT_INITIALIZED
Error描述: aita@aita-Alienware-Area-51-R5:~/AITA2/daisida/ssd-github/caffe$ make runtest -j8 .build_re ...
- 首次运行tensorflow-gpu 1.0 报错 failed to create cublas handle: CUBLAS_STATUS_NOT_INITIALIZED
发现博客: https://blog.csdn.net/u010752600/article/details/79534910 于是找到解决方法. sudo rm -rf ~/.nv/
- SQL Developer 4.0 启动报错“unable to create an instance of the java virtual machine located at path”
安装了Oracle之后,第一件事情就是想想怎么去连接,进而操作.SQL Developer是官方提供的强大工具,个人看来也是第一选择. 目前官网提供的最新版是4.0.1.14.48,下载下来之后,就跃 ...
- svn 提交代码报错
svn 提交代码报错 最近新安装了TortoiseSvn 1.92,在上传代码,其中有新增加的文件,出现如下错误: 解决方法: 1.用vs生成patch文件 2.生成的patch文件中讲nonexis ...
- Idea下的springboot mysql8.0等报错解决随笔
cannot load jdbc class path:mysql8.0装载失败,可能原因,驱动名称错误,连接字符串中需要加入时区UTC,否则8.0一定会报错无法连接,关闭SSL 在applicati ...
- 执行Spark运行在yarn上的命令报错 spark-shell --master yarn-client
1.执行Spark运行在yarn上的命令报错 spark-shell --master yarn-client,错误如下所示: // :: ERROR SparkContext: Error init ...
- 如何解决spring boot 项目导入依赖后代码报错问题
如何解决spring boot 项目导入依赖后代码报错问题 2020-08-15 14:17:18 代码截图如图所示(由于本人问题已经解决,没来得及截图,所以在网上找了一张图片)
- Tomcat7.0启动报错:java.lang.illegalargumentexception:taglib definition not consisten with specification version
Tomcat7.0启动报错:java.lang.illegalargumentexception:taglib definition not consisten with specification ...
- wince6.0 编译报错:"error C2220: warning treated as error - no 'object' file generated"的解决办法
内容提要:wince6.0编译报错:"error C2220: warning treated as error - no 'object' file generated" 原因是 ...
随机推荐
- 使用edge浏览器时,怎么让alt+tab不切换他的子标签页而只在程序间切换?
使用搜索按钮(WIN+Q),搜索"多任务设置",在弹出的窗口中看到"alt+tab"相关设置.选择"仅打开的窗口",ok搞定.
- post请求方式 - 使用restTemplate而不使用httpClient,headers.setContentType(MediaType.APPLICATION_JSON_UTF8)
public static String doPostForJson(String url, String json,String byteAuthorization) { RestTemplate ...
- C# 语言在AGI 赛道上能做什么
自从2022年11月OpenAI正式对外发布ChatGPT依赖,AGI 这条赛道上就挤满了重量级的选手,各大头部公司纷纷下场布局.原本就在机器学习.深度学习领域占据No.1的Python语言更是继续稳 ...
- FEL - Fast Expression Language
开源好用的表达式计算语言FEL,可惜了官网文档不在国内,我来copy个过来. Fel是轻量级的高效的表达式计算引擎 Fel在源自于企业项目,设计目标是为了满足不断变化的功能需求和性能需求. Fel是开 ...
- 使用Kubesec检查YAML文件安全
目录 一.系统环境 二.前言 三.Kubesec简介 四.使用Kubesec检查YAML文件安全 五.总结 一.系统环境 本文主要基于Kubernetes1.22.2和Linux操作系统Ubuntu ...
- C#去除时间格式化之后中间的T字母
需求是这样的, 前后端传参,然后后端序列化把字符串存在数据库. 然后发现时间类型的字段,序列化之后 ,有个字母T, DateTime dt = DateTime.Parse("2024-05 ...
- python_8 拆包、内置函数和高阶函数
一.查缺补漏 1. \t 子表符,用于对其二.拆包 1. 拆包:顾名思义就是将可迭代的对象如元组,列表,字符串,集合,字典,拆分出相对应的元素 2. 形式:拆包一般分两种方式,一种是以变量的方式来接收 ...
- unity中Shader实现地形中根据实际高度绘制等高线,剖切功能,颜色渐变等功能
问题背景 在做地形模块时,需要根据实际地形高度画出世界相应的等高线,以及根据高度做颜色渐变,以及剖切功能. 解决方法 通过像素点在世界坐标系下的真实高度值来判断计算绘制等高线,剖切功能以及颜色渐变均有 ...
- 在OwinSelfHost项目中获取客户端IP地址
在OwinSelfHost项目中,获取客户端的IP地址可以通过以下方法获得: base.Request.GetOwinContext().Request.RemoteIpAddress 创建一个Owi ...
- 4. 简明说一下 CSS link 与 @import 的区别和用法?
两者的基本语法 link语法结构 <link href="外部CSS文件的URL路径" rel="stylesheet" type="text/ ...