Python 使用会话运行tf.contrib.image.sparse\u image\u warp导致内存泄漏
我有一个功能,可以使用目标地标扭曲一些人脸图像。但我注意到,随着时间的推移,我有一个内存泄漏,我用内存分析器检查了它。代码如下:Python 使用会话运行tf.contrib.image.sparse\u image\u warp导致内存泄漏,python,tensorflow,image-processing,Python,Tensorflow,Image Processing,我有一个功能,可以使用目标地标扭曲一些人脸图像。但我注意到,随着时间的推移,我有一个内存泄漏,我用内存分析器检查了它。代码如下: def image_warping(src_img, src_landmarks, dest_landmarks): expanded_src_landmarks = np.expand_dims(np.float32(src_landmarks), axis=0) expanded_dest_landmarks = np.expand_dims(np
def image_warping(src_img, src_landmarks, dest_landmarks):
expanded_src_landmarks = np.expand_dims(np.float32(src_landmarks), axis=0)
expanded_dest_landmarks = np.expand_dims(np.float32(dest_landmarks), axis=0)
expanded_src_img = np.expand_dims(np.float32(src_img) / 255, axis=0)
warped_img, dense_flows = sparse_image_warp.sparse_image_warp(expanded_src_img,
expanded_src_landmarks,
expanded_dest_landmarks,
interpolation_order=1,
regularization_weight=0.1,
num_boundary_points=2,
name='sparse_image_warp')
with tf.Session() as sess:
out_img = sess.run(warped_img)
warp_img = np.uint8(out_img[0, :, :, :] * 255)
session.close()
return warp_img
内存探查器显示的466.645 MiB和174.574 MiB增量,其中tf.Session()分别作为sess:
和out\u img=sess.run(warped\u img)
行
有没有其他方法可以将扭曲的_img从张量转换为numpy数组,而不是按会话运行?这个tf函数的结果比任何其他可用的图像扭曲代码都要好,但我想知道为什么它返回张量,因为输入都是numpy数组。我没有在深度学习算法中使用这个函数