breezedeus / CnSTD

CnSTD: 基于 PyTorch/MXNet 的 中文/英文 场景文字检测(Scene Text Detection)、数学公式检测(Mathematical Formula Detection, MFD)、篇章分析(Layout Analysis)的Python3 包
https://www.breezedeus.com/article/cnocr
Apache License 2.0
658 stars 101 forks source link

连续调用时会消耗越来越多的内存 #4

Closed breezedeus closed 2 years ago

breezedeus commented 4 years ago

memory_profiler 打了下内存消耗:

   169   3045.3 MiB      0.0 MiB           h, w, _ = resize_img.shape
   170   3054.2 MiB      8.9 MiB           resize_img = normalize_img_array(resize_img)
   171   3054.2 MiB      0.0 MiB           im_res = mx.nd.array(resize_img)
   172   3054.5 MiB      0.3 MiB           im_res = self._trans(im_res)
   173
   174   3054.7 MiB      0.2 MiB           t1 = time.time()
   175   3064.7 MiB     10.0 MiB           seg_maps = self._model(im_res.expand_dims(axis=0).as_in_context(self._context))
   176   4056.1 MiB    991.4 MiB           mx.nd.waitall()
   177   4056.1 MiB      0.0 MiB           seg_maps = seg_maps.asnumpy()
   178   4056.1 MiB      0.0 MiB           t2 = time.time()
   179   4056.1 MiB      0.0 MiB           boxes, scores, rects = detect_pse(
   180   4056.1 MiB      0.0 MiB               seg_maps,
   181   4056.1 MiB      0.0 MiB               threshold=pse_threshold,
   182   4056.1 MiB      0.0 MiB               threshold_k=pse_threshold,

发现是 mx.nd.waitall()每预测一张图片就会消耗不少内存,而这些内存好像没完全被释放,导致内存消耗越来越大。

网上搜了下,好像是MXNet的一个未解问题: Memory leak when running cpu inference - Gluon - MXNet Forum