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语言开发:typedef
#include <stdio.h> #include <string.h> typedef struct Books { ]; ]; ]; int book_id; } Bo ...
- ubuntu Python 升级
安装时ubuntu提示: DEPRECATION: Python 3.4 support has been deprecated. pip 19.1 will be the last one supp ...
- 【flask】RestFul的基本鉴权
编写API的基本鉴权 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Author : shenqiang from flask import Fla ...
- 国内外主流的三维GIS软件
我国GIS经过三十多年的发展,理论和技术日趋成熟,在传统二维GIS已不能满足应用需求的情况下,三维GIS应运而生,并成为GIS的重要发展方向之一.上世纪八十年代末以来,空间信息三维可视化技术成为业界研 ...
- [LC] 19. Remove Nth Node From End of List
Given a linked list, remove the n-th node from the end of list and return its head. Example: Given l ...
- VisionPro控件的使用 C# 开发篇
VisionPro 常用控件的说明 工具设置窗体 CogPMAlignEditV2 [ 模版匹配设置窗体控件 ] CogPMAlignEditV2.Subject : 工具关联对象 如:CogPMA ...
- mac osx 下 浏览器 开启 java
工作环境mac osx 浏览器 chrome:63.0.3239.132 (Official Build) (64-bit)firefox: 57.0.4 (64 位)safari:Version 1 ...
- HLS图像处理总结(一)
HLS工具 以个人的理解,xilinx将HLS(高层次综合)定位于更方便的将复杂算法转化为硬件语言,通过添加某些配置条件HLS工具可以把可并行化的C/C++的代码转化为vhdl或verilog,相比于 ...
- WebFilter 在springBoot工程中不起作用
[1]@ServletComponentScan 必须有一个注解将带有@WebFilter的类包含进去. [2]自定义 FiltersConfig extends WebMvcConfigurerAd ...
- spring学习笔记四:spring常用注解总结
使用spring的注解,需要在配置文件中配置组件扫描器,用于在指定的包中扫描注解 <context:component-scan base-package="xxx.xxx.xxx.x ...