【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 ...
随机推荐
- 【8】java之引用传递
一.引用传递 引用传递是整个 java 的精髓所在 引用传递核心意义:同一块堆内存空间可以被不同的栈内存所指向,不同栈内存可以对同一块堆内存内容进行修改. 范例:第一道引用传递范例 class Me ...
- .NET 中创建录音机和播放器应用
前言 在本博客中,你将了解如何在 .NET MAUI 中开发录音机和播放器.音频播放器将录制和播放音频文件.此应用程序可以在Android和iOS上部署和使用. 预览 以下是该录音机和播放录音的应用程 ...
- .net core 3.1 上传大文件报错413 Payload Too Large
IIS配置如下 https://www.cnblogs.com/hallejuayahaha/p/12884347.html 代码里面新增 services.Configure<FormOpti ...
- 监控平台prometheus+grafana+snmp_explorer+blackbox_exporter+alertmanager
一.背景介绍 公司需要监控交换机和IP设备,能够放在展示屏幕,及时发出告警信息.网上有很多监控软件,prometheus系列已经能够满足我们需求.prometheus功能强大,本次只用到一部功能.咱们 ...
- 运行springboot的时候访问本地图片地址的问题
@Configuration public class MyConfigrauration implements WebMvcConfigurer { /** * 当有请求经过[/myUpload/* ...
- Python的100个小技巧
文章转自:https://mp.weixin.qq.com/s/w5do8QYMkO_gLgPupDdJqg 分享100个Python小技巧,帮助大家更好的了解和学习Python. ▍1.for循环中 ...
- 内网Linux下安装Nginx1.23,添加stream模块实现tcp/udp代理转发
环境:centos7.6 ngx_stream_core_module 这个模块在1.9.0版本后将被启用.但是并不会默认安装,需要在编译时通过指定 --with-stream 参数来激活这个模块,w ...
- vue-表格拖拽
1. el-table结合sortable 参考:https://blog.csdn.net/weixin_42460570/article/details/125765599?ops_request ...
- 错误:[ERROR] 不再支持源选项 5。请使用 6 或更高版本。 [ERROR] 不再支持目标选项 1.5。请使用 1.6 或更高版本。
解决方案 pom.xml文件中增加maven编译的java.version jdk版本设置,以及maven.compiler.source 资源编译jdk版本设置和maven.compiler.tar ...
- LNK2038: 检测到“RuntimeLibrary”的不匹配项
VS编译找到几十个这样的报错,是因为引用的库是Release版本,编译也是这个版本但C语言标准却用的是默认旧版,需要改为2018标准,并且Release版本对应运行库 多线程DLL(/MD),再次编译 ...