当你们在用模型加载,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) ]]的更多相关文章

  1. 【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= ...

  2. 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 ...

  3. tensorflow报错 tensorflow Resource exhausted: OOM when allocating tensor with shape

    在使用tensorflow的object detection时,出现以下报错 tensorflow Resource exhausted: OOM when allocating tensor wit ...

  4. 显存不够----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 ...

  5. TensorFlow OOM when allocating tensor with shape[5000,384707]

    在session范围内不要进行eval()或者convert_to_tensor()操作, 否则会造成OOM,或者报出错误:GraphDef cannot be larger than 2GB usi ...

  6. ''tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocating tensor with shape[?]'' 错误分析

    这是tensorflow 一个经常性错误,错误的原因在于:显卡内存不够. 解决方法就是降低显卡的使用内存,途径有以下几种措施: 1 减少Batch 的大小 2 分析错误的位置,在哪一层出现显卡不够,比 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. [APIO2009-C]抢掠计划

    题:https://www.cometoj.com/problem/0461 分析:求边双,最后求多汇点最长路 #include<iostream> #include<cstring ...

  2. Minimum Sum

    题目描述 One day, Snuke was given a permutation of length N, a1,a2,…,aN, from his friend. Find the follo ...

  3. php获取mysql大小

      查看指定数据库大小:  SELECT sum(DATA_LENGTH)+sum(INDEX_LENGTH) FROM information_schema.TABLES where    TABL ...

  4. spring cache问题记录

    1.是否可以设置过期时间 timeout ttl 对于单个key设置过期时间 需要自定义CacheManager, 见3中的问题 spring boot 1版本可以重写RedisCacheManage ...

  5. derby数据库

    derby数据库 https://www.cnblogs.com/zuzZ/p/8107915.html Derby数据库的使用 https://www.cnblogs.com/wkfvawl/p/1 ...

  6. 在CentOS安装CMake (CentOS7 64位适用)

    在CentOS安装CMake 转自:http://www.cnblogs.com/mophee/archive/2013/03/19/2969456.html 一.环境描述 1.系统:CentOS 6 ...

  7. 二、RabbitMQ简介及AMQP协议

    RabbitMQ简介 RabbitMQ是开源的消息代理和队列服务器,是由Erlang语言开发的,基于AMQP协议(Advanced Message Queuing Protocol高级消息队列协议)的 ...

  8. [LC] 359. Logger Rate Limiter

    Design a logger system that receive stream of messages along with its timestamps, each message shoul ...

  9. java170道面试题汇总+详细解析

    2013年年底的时候,我看到了网上流传的一个叫做<Java面试题大全>的东西,认真的阅读了以后发现里面的很多题目是重复且没有价值的题目,还有不少的参考答案也是错误的,于是我花了半个月时间对 ...

  10. 成组vs成对|H1是受保护的|U检验

    生物统计与实验设计 样本均值的分布推导 概率密度曲线上每点x取值概率是不相等的.标准化是转化为无量纲的表面误差,该分布是误差分布,置信区间是可接受该误差是随机误差的误差区间.上面的部分是该估计参数与平 ...