TF预测服务接口上线后内存泄漏'std::bad_alloc'等问题集锦

楼主环境:

	python3.6.8
	centos 7.2
	tensorflow 1.14.0

一 泄漏位置查找方法:

报错部分原文:

	 terminate called after throwing an instance of 'std::bad_alloc'

工具:pympler

from pympler import tracker,summary,muppy

在web主程序添加:
memory_tracker = tracker.SummaryTracker()

在接口返回前添加:
memory_tracker.print_diff()

反人类办法:把怀疑的模块一个一个替换着注释掉,找到内存泄漏模块,
然后再进行代码排查

二 由tf.train.Saver()引起的

在session开始前进行模型的重新设置,
tf.reset_default_graph()

解决办法:

在with tf.Session() as sess: 之后同时也要在with的范围以外(注意),添加

tf.reset_default_graph()

代码来重置默认的图,这样就能解决下一步执行代码
self.sess = tf.Session()
self.saver = tf.train.import_meta_graph(’./Model/model.ckpt.meta’)
self.saver.restore(self.sess, tf.train.latest_checkpoint(’./Model/’))

三 OOM问题

报错原文:

tensorflow:OOM when allocating tensor with shape[225,256,256,36] and type float on /job:localhost/re

原因是GPU OOM内存不够,因此可尝试改成批处理。即将训练的数据块调小。

参考链接:
https://stackoverflow.com/questions/39076388/tensorflow-deep-mnist-resource-exhausted-oom-when-allocating-tensor-with-shape

https://github.com/tensorflow/tensorflow/issues/609

四 编码问题

报错部分原文:

SyntaxError: Non-UTF-8 code starting with '\xe5' in file

原因:编码格式不对

把相应Python程序文件的编码转成UTF-8格式
1、在文件第一行添加# encoding:utf-8

或2.在文件第一行添加# -- coding: gbk --

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章