gpt4 book ai didi

python-3.x - Numpy 数组/asarray 泄漏?

转载 作者:行者123 更新时间:2023-12-04 04:01:40 24 4
gpt4 key购买 nike

使用 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'

我不认为这是 flask 或 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

最佳答案

尝试场景 2:

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

关于python-3.x - Numpy 数组/asarray 泄漏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62961616/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com