The Method of Memory Overflow in the Generation of python with Subgraph

  • 2021-07-10 20:17:06
  • OfStack

Today, I want to use python to make an demo, a dynamic gif with two sub-diagrams. The code is as follows:


import matplotlib.pyplot as plt
import imageio,os
import matplotlib
 
 
# plt.ion()
 
fig=plt.figure(0)
ax1=plt.subplot(121)
ax2=plt.subplot(122)
 
ax1.set_title('input')
ax2.set_title('GT')
 
 
for i in range(1000):
  img1=plt.imread('F:\\pythonprogram\\test_bord/path\\enc_in_img\\{}.png'.format(i))
  img2 = plt.imread('F:\\pythonprogram\\test_bord/path\\dec_out_img\\{}.png'.format(i))
  ax1.imshow(img1)
  ax2.imshow(img2)
  # ax2.axis('off')
  plt.pause(0.00001)
  plt.cla()
 
plt.show()

First, divide the canvas into two pieces, read the picture cyclically, pause after displaying the picture, and then clear the original image ~

However, because plt. cla () can only act on the last subgraph, the first subgraph takes up a lot of memory during reading, which leads to memory overflow. At present, no solution has been found.

Finally, this work is completed on matlab.


Related articles: