Ich habe eine ähnliche Frage gefunden, aber ohne Antwort! Ich hoffe, eine Lösung für dieses Problem zu erhalten. < /P>
Code: Select all
from __future__ import division
import os
import numpy as np
import gc
from os import listdir
from os.path import isfile, join
import matplotlib.pyplot as plt
from PIL import Image
def test():
entries = os.listdir(r"D:\Images")
for entry in entries:
if entry.endswith(".jpg"):
img = np.array(Image.open(r"D:\Images\{}".format(entry)))
fig, ax = plt.subplots(1)
#Many ways I added to free the memory#
plt.close('all')
fig.clear()
ax.clear()
plt.clf()
gc.collect()
plt.close(fig)
del img
#####################################
Meine Umgebung ist Anaconda 3, OS: Windows 10
Update:
Ich habe diese Linie ersetzt:
Ich habe diese Zeile ersetzt:
fig, ax = plt.subplots(1)
< /code>
mit < /p>
fig, ax = plt.subplots(num=1, clear=True)
< /code>
und der Code wurde länger ausgeführt, bevor ich nach dem Laden von 185 Bildern den Fehler bekam, aber jetzt, nachdem ich "clear = true" hinzugefügt hatte, erscheint der Fehler nach 369 Bildern, so dass dies fast zum Doppel wurde. Aber das Problem ist immer noch!