Python使用PIL Image.open打开大量图片时占用内存过高

在用Image.open获取jpg图片rgb值的时候占用大量内存,进而导致崩溃。gc.collect()是后来添加的解决方案,但是用处不大。各位大佬帮忙看下我代码哪里有问题嘛,谢谢啦

segments_lst = []
lst = sorted(glob.glob('DeepSBD/tv7789/segments/*/*/*.jpg'))#大约共6000张320x240规格的jpg图片
count = 0
array = np.zeros((16,3,320,240))
for i in range(0,len(lst)-1,16):
    for j in range(0,15):
        x = Image.open(lst[i+j])
        data = np.asarray(x)
        data = np.transpose(x, (2, 1, 0))
        array[count] = data
    segments_lst.append(array)
    array = np.zeros((16,3,320,240))
    count = 0
    gc.collect()

https://blog.csdn.net/u011394059/article/details/78112838?utm_source=blogxgwz8