【问题标题】:Numpy array/asarray leak?Numpy 数组/asarray 泄漏?
【发布时间】:2020-07-17 20:51:40
【问题描述】:

使用 pytorch 在服务器上处理图像并面临内存问题。特别是:

场景 1:

#before execution memory used is 1518
temp = PIL.Image.open(im) #no leak
del im
del temp
gc.collect()
#after execution x5 times memory used is 1518

场景 2:

#before execution memory used is 1518
temp = PIL.Image.open(im) #no leak
del im
temp2 = np.array(temp) #leak? (asarray has same behaviour)
del temp
temp2 = None
del temp2
gc.collect()
#after execution x5 times memory used is 2385

详情:

numpy==1.19.0
python==3.6.9
flask
apache2
libapache2-mod-wsgi-py3
virtualenv
watching memory using 'watch free -m'

我认为这与烧瓶或 wsgi 无关

但是,如果我在python3环境下做一个简单的实验:

#before execution memory used is 2418
a = [random.random()]*100000000
b = np.array(a)
del a
del b
#after execution memory used is 2418

【问题讨论】:

  • 手动调用import gc; gc.collect()会释放内存吗?
  • @DanielS。我稍后会在代码中调用 gc.collect,但它不会影响这个简单示例的内存使用
  • 对于free -m的输出,你是哪一列
  • @DanielS。 'used' 列 'mem' 行

标签: python-3.x numpy flask virtualenv mod-wsgi


【解决方案1】:

尝试方案 2:

temp = PIL.Image.open(im)
del im
temp2 = np.array(temp) 
temp2 = None
del temp
del temp2
gc.collect()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-03
    • 1970-01-01
    • 2013-09-28
    • 2021-12-09
    • 1970-01-01
    • 2012-10-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多