OOM when allocating tensor of shape [] and type float [[node conv2d_224/kernel/Initializer/random_uniform/min (defined at ./intances/utils.py:19) ]]
当你们在用模型加载,tensorflow-gpu预测的时候,有没有出现这样的错误??
经过网上的资料查阅,更多的解释是GPU的显存不足造成的,于是乎,我查看了一下GPU显存:nvidia-smi
不看不知道,一看确实是那么回事:tensorflow-gpu执行默认将GPU显存占满,官网也做了解释说明:https://www.tensorflow.org/guide/using_gpu
刚开始没有看到官网的解释,思路是当程序执行完成之后,能不能自动的执行释放显存的程序,网上这方面的代码不多,后来又看到上面官网的解释,显存不能释放,可能会有更严重的内存碎片,因此程序释放显存的想法就打消了。
在仔细看官网的解释,可能比较好的方法是指定GPU所占的比例,于是乎,我又多次的尝试:一般来说,这些指定的过程都放在代码的开始处,因为我用的框架是python的Flask框架,所以我的想法也是将这个指定GPU显存的代码放在Flask开始处,不执行不知道,一执行整个人都不好了,报了这个错:
could not retrieve CUDA device count: CUDA_ERROR_NOT_INITIALIZED: initialization error
What??这是什么错!在百度,Google,StackOverflow,Github等等网站查找相关问题解释,大多数解释是multiprocessing等等的解释,说实话我确实不是很明白,但我总觉得这个问题没有复杂到这个地步,因为几行代码应该是放在: 使用tensorflow之前!
因为Flask接口用到这个tensorflow之前,我需要初始化一个类实例,在初始化类的时候也用到tensorflow,于是乎,我想把这几行代码放在初始化类实例的地方,心态崩了,还是不行!还是报:
could not retrieve CUDA device count: CUDA_ERROR_NOT_INITIALIZED: initialization error
相同的错误!这可怎么办,如果执行一次默认把显存占满,后面相同的操作就可能没办法执行了,所以必须分配GPU!
想了2天,今天上午,灵感来了,因为我是需要调用接口用到tensorflow,初始化类也是在这个接口里面,意思就是调用这个接口的时候,才会用到tensorflow,于是乎,我这个笨脑子也突然来了想法:直接在调用这个接口的时候,把这几行代码放进去,也就相当于初始化的时候执行了这几行代码,开始操作:
如图,将这几行代码放在这个位置,在本地尝试了一下没有什么问题,于是乎,在服务器代码执行了相同的操作,开启服务,跑,跑,跑,没有报错!
查看nvidia-smi:GPU显存占用率果然只占了40%!!!解决了我心头大患!!
写这篇随笔没有什么其他想法,只是记录一下自己的坑!记录一下自己的知识盲点,如果有朋友遇到这样的问题,可以作为参考,不足的地方望指正批评!
OOM when allocating tensor of shape [] and type float [[node conv2d_224/kernel/Initializer/random_uniform/min (defined at ./intances/utils.py:19) ]]的更多相关文章
- 【tf.keras】Resource exhausted: OOM when allocating tensor with shape [9216,4096] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
运行以下类似代码: while True: inputs, outputs = get_AlexNet() model = tf.keras.Model(inputs=inputs, outputs= ...
- Resource exhausted: OOM when allocating tensor with shape[3,3,384,384] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0。。。。。
报错信息: OP_REQUIRES failed at assign_op.h:111 : Resource exhausted: OOM when allocating tensor with sh ...
- tensorflow报错 tensorflow Resource exhausted: OOM when allocating tensor with shape
在使用tensorflow的object detection时,出现以下报错 tensorflow Resource exhausted: OOM when allocating tensor wit ...
- 显存不够----ResourceExhaustedError (see above for traceback): OOM when allocating tensor with shape[4096]
ResourceExhaustedError (see above for traceback): OOM when allocating tensor with shape[4096] 类似问题 h ...
- TensorFlow OOM when allocating tensor with shape[5000,384707]
在session范围内不要进行eval()或者convert_to_tensor()操作, 否则会造成OOM,或者报出错误:GraphDef cannot be larger than 2GB usi ...
- ''tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocating tensor with shape[?]'' 错误分析
这是tensorflow 一个经常性错误,错误的原因在于:显卡内存不够. 解决方法就是降低显卡的使用内存,途径有以下几种措施: 1 减少Batch 的大小 2 分析错误的位置,在哪一层出现显卡不够,比 ...
- OP_REQUIRES failed at conv_ops.cc:386 : Resource exhausted: OOM when allocating tensor with shape..
tensorflow-gpu验证准确率是报错如上: 解决办法: 1. 加入os.environ['CUDA_VISIBLE_DEVICES']='2' 强制使用CPU验证-----慢 2.'batch ...
- ValueError: Argument must be a dense tensor:... got shape [6, 60, 160, 3], but wanted [6].
在将 列表或元组 数据转换成 dataset类型时 import numpy as np import tensorflow as tffrom sklearn.cross_validation im ...
- Format specifies type 'int' but the argument has type 'struct node *'
/Users/Rubert/IOS/iworkspace/LineList/LineList/main.c::: Format specifies type 'int' but the argumen ...
随机推荐
- C++ sizeof 运算符
sizeof 是一个关键字,它是一个编译时运算符,用于判断变量或数据类型的字节大小. sizeof 运算符可用于获取类.结构.共用体和其他用户自定义数据类型的大小. 使用 sizeof 的语法如下: ...
- Datagridview 实现二维表头和行合并
借鉴别人的,改了改,没用timer using System;using System.Collections.Generic;using System.ComponentModel;using Sy ...
- 基于css完成网页的国际化
css完成国际化 前提 在日常处理国际化的时候,通常是将key通过类似intl.xx(key)转换为对应环境的文案,可是如果需要在css中加入对应逻辑应该怎么做呢(比如在after的伪元素中显示不同的 ...
- cannot be found on object of type xx.CacheExpressionRootObject
0 环境 系统环境:win10 编辑器:IDEA 1 前言->环境搭建 1-1 pom依赖 <?xml version="1.0" encoding="UTF ...
- [LC] 23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. E ...
- Ribosome profiling|N-terminomics|蛋白质基因组学
生物医学大数据-蛋白质基因组学:质谱注释 蛋白质组与其他组学的关系便是互为印证:蛋白质基因组学原本用于基因组注释,后面扩展到蛋白质与转录组或可变剪接之间关系,同时,蛋白质组依赖于基因组注释作为验证.许 ...
- Point Estimate|unbiased estimator|Confidence-Interval Estimate
8.1 Estimating a Population Mean Point Estimate estimate a single number, or point. 因为:the mean of ...
- python3下scrapy爬虫(第十一卷:scrapy数据存储进mongodb)
说起python爬虫数据存储就不得不说到mongodb,现在我们来试一下scrapy操作mongodb 首先开启mongodb mongod --dbpath=D:\mongodb\db 开启服务后就 ...
- Java POI导出Excel不弹框选择下载路径(下载文件不选择下载路径,默认) Chrome
在Chrome浏览器中,Java导出Excel文件时,浏览器弹出提示框,需要选择下载路径 在Chrome中的高级设置中,把“下载前询问每个文件的保存位置”去掉就解决了 DEEPLOVE(LC)
- 关于Synchornized,Lock,AtomicBoolean和volatile的区别介绍
1. volatile 变量可以被看作是一种 "程度较轻的 synchronized". 2. Lock 实现提供了比使用 synchronized 方法和语句可获得的更广泛的 ...