I have this part of code:
import matplotlib.pyplot as plt
for i in range(1, 5, 1):
    x, y = valid_gen.__getitem__(i)
    result = model.predict(x)
    result = result > 0.4
    for i in range(len(result)):
        fig = plt.figure()
        fig.subplots_adjust(hspace=0.4, wspace=0.4)
        ax = fig.add_subplot(1, 2, 1)
        ax.imshow(np.reshape(y[i] * 255, (image_size, image_size)), cmap="gray")
        ax = fig.add_subplot(1, 2, 2)
        ax.imshow(np.reshape(result[i] * 255, (image_size, image_size)), cmap="gray")
But I am getting an error when I am trying to plot it:
RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory.
So I want to save figures instead to plot it, how should I do?
 
     
    