【TensorFlow】InternalError: Failed copying input tensor
TensorFlow-GPU 执行模型训练时报错:
InternalError: Failed copying input tensor from /job:localhost/replica:0/task:0/device:CPU:0 to /job:localhost/replica:0/task:0/device:GPU:0 in order to run _EagerConst: Dst tensor is not initialized.
解决方案:『TensorFlow: Dst tensor is not initialized - Stack Overflow』
主要原因在于 batch_size 太大,内存无法负载,将 batch_size 适当调小即可正常运行。
【注】默认情况下,TF 会尽可能地多分配占用 GPU 内存,通过调整 GPUConfig 可以设置为按需分配内存,参考 TensorFlow 文档和 TensorFlow 代码。
另外,使用 Jupyter Notebook 进行长期模型训练时,可能由于 GPU 内存无法及时释放导致该报错。参考此答案可以解决此问题,定义如下函数:
from keras.backend import set_session
from keras.backend import clear_session
from keras.backend import get_session
import gc # Reset Keras Session
def reset_keras():
sess = get_session()
clear_session()
sess.close()
sess = get_session() try:
del classifier # this is from global space - change this as you need
except:
pass print(gc.collect()) # if it does something you should see a number as output # use the same config as you used to create the session
config = tf.compat.v1.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 1
config.gpu_options.visible_device_list = "0"
set_session(tf.compat.v1.Session(config=config))
需要清除 GPU 内存时,直接调用 reset_keras 函数即可。例如:
dense_layers = [0, 1, 2]
layer_sizes = [32, 64, 128]
conv_layers = [1, 2, 3] for dense_layer in dense_layers:
for layer_size in layer_sizes:
for conv_layer in conv_layers:
reset_keras()
# training your model here
【TensorFlow】InternalError: Failed copying input tensor的更多相关文章
- 【Tensorflow】tf.nn.depthwise_conv2d如何实现深度卷积?
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/mao_xiao_feng/article/ ...
- 【Tensorflow】tf.nn.atrous_conv2d如何实现空洞卷积?膨胀卷积
介绍关于空洞卷积的理论可以查看以下链接,这里我们不详细讲理论: 1.Long J, Shelhamer E, Darrell T, et al. Fully convolutional network ...
- 【TensorFlow】tf.nn.max_pool实现池化操作
max pooling是CNN当中的最大值池化操作,其实用法和卷积很类似 有些地方可以从卷积去参考[TensorFlow]tf.nn.conv2d是怎样实现卷积的? tf.nn.max_pool(va ...
- 【TensorFlow】自主实现包含全节点Cell的LSTM层 Cell
0x00 前言 常用的LSTM,或是双向LSTM,输出的结果通常是以下两个:1) outputs,包括所有节点的hidden2) 末节点的state,包括末节点的hidden和cell大部分任务有这些 ...
- 【TensorFlow】tf.nn.softmax_cross_entropy_with_logits的用法
在计算loss的时候,最常见的一句话就是 tf.nn.softmax_cross_entropy_with_logits ,那么它到底是怎么做的呢? 首先明确一点,loss是代价值,也就是我们要最小化 ...
- 【TensorFlow】:解决TensorFlow的ImportError: DLL load failed: 动态链接库(DLL)初始化例程失败
[背景] 在scikit-learn基础上系统结合数学和编程的角度学习了机器学习后(我的github:https://github.com/wwcom614/machine-learning),意犹未 ...
- 【转载】 【TensorFlow】static_rnn 和dynamic_rnn的区别
原文地址: https://blog.csdn.net/qq_20135597/article/details/88980975 ----------------------------------- ...
- 【TensorFlow】tf.nn.conv2d是怎样实现卷积的?
tf.nn.conv2d是TensorFlow里面实现卷积的函数,参考文档对它的介绍并不是很详细,实际上这是搭建卷积神经网络比较核心的一个方法,非常重要 tf.nn.conv2d(input, fil ...
- 【LeetCode】Two Sum II - Input array is sorted
[Description] Given an array of integers that is already sorted in ascending order, find two numbers ...
- 【tensorflow】1.安装Tensorflow开发环境,安装Python 的IDE--PyCharm
================================================== 安装Tensorflow开发环境,安装Python 的IDE--PyCharm 1.PyCharm ...
随机推荐
- C语言数据结构串的表示与操作的实现
串的堆分配储存表示 typedef struct { char* ch;//若是非空字符串,则按串长分配存储区,否则ch为NULL int length;//串长度 } HString; 生成一个其值 ...
- Mogeaver 连接数据库
下载安装Mogeaver是一款开源软件,下载地址如下:https://docs.mogdb.io/zh/mogdb/v3.0/mogeaver-release-notes 根据您的操作系统选择相应的安 ...
- fields设计与测试
菲尔兹管理用例 一.向开发找到需求ID 需求设计文档ID 二.在fields的需求列表中,填入ID,创建计划 1.状态:测试接手 2.日期:冒烟日期,测试日期 3.可能遇到的问题: * 搜不到ID ...
- 使用伪元素 before 叹号
.tip { width: 400px; line-height: 150%; border-left-color: #f66; color: #666; padding: 12px 24px 12p ...
- zabbix-agent2安装问题汇总
1.yum源报错 # 具体报错信息 failure: repodata/4bb73bd0742c638c3cd1e73a5f3dc8838c7b0d693c9f50b7ed8266c3e83308d3 ...
- charles证书安装-客户端证书
1.iOS设置教程: 1)wifi中配置代理 2)浏览器中输入chls.pro/ssl,进行证书下载 3)证书下载成功后,设置--通用--描述文件–安装刚下载的证书 4)设置--通用--关于本机--证 ...
- 【剑指Offer】【字符串】字符串的排列
题目:输入一个字符串,按字典序打印出该字符串中字符的所有排列.例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba. 输入一个字符串,长 ...
- php 关于 json字符串使用json_decode 转数组为空
项目中遇见一个之前没有遇见的问题,就是 转化一个json字符串为数组时 为空,解决办法是使用 htmlspecialchars_decode 处理一下json字符串 然后 再使用 json_decod ...
- express的使用:web开发(四)
1.开发模式 1.服务端渲染 2.前后端分离 2.身份认证 1.服务端渲染推荐使用session认证机制 2.前端后端分离建议使用JWT认证机制 3.http协议的无状态性 4.cookie特性 1. ...
- Windows下安装和使用Masscan
http://zone.secevery.com/article/1098 0x00 前言Masscan号称最快的互联网端口扫描器,本文来探测一下Masscan在Windows下的安装和使用.mass ...