Gee*_*esu 11 python keras tensorflow
我正在开发一个Python 3 API w/gunicorn,它使用keras来计算图像的向量,非常简单.
如何为每个请求重置存储在内存中的数据?随着时间的推移,请求会增加响应所需的时间.我运行了一个分析器,它特别是在tensorflow中的这一行(每个进程的内存使用量随着时间的推移而缓慢上升):
#tensorflow/python/framework/ops.py:2317:_as_graph_def
graph.node.extend([op.node_def])
Run Code Online (Sandbox Code Playgroud)
随着节点中的数据越来越多,需要更长的时间.这是我执行的代码:
# We have 11439MiB of GPU memory, lets only use 2GB of it:
config = tf.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.22
sess = tf.Session(config=config)
set_session(sess)
sess.graph.as_default()
# Get the vector for the image
img_size = (224,224)
vgg = VGG16(include_top=False, weights='imagenet')
img = kimage.load_img(tmpfile.name, target_size=img_size)
x = kimage.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
pred = vgg.predict(x)
vectors = pred.ravel().tolist()
Run Code Online (Sandbox Code Playgroud)
我认为as_default()会有所帮助,但事实并非如此.在获得向量列表后,我也尝试关闭会话,但失败了.
Mic*_*erl 29
from keras import backend as K
K.clear_session()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9108 次 |
| 最近记录: |