def make_gif(parent_folder,frame_duration=0.3):
items = os.listdir(parent_folder)
png_filenames = []
for elem in items:
if elem.find(".png")!=-1 and elem.find("heatmap")!=-1:
png_filenames.append(elem)
sorted_png = []
while True:
lowest = 10000000
lowest_idx = -1
for p in png_filenames:
old_save_format=False
if old_save_format:
iter_val = int(p.split("-")[2].split(":")[1])
epoch_val = int(p.split("-")[3].split(":")[1].split(".")[0])
val = float(iter_val)+0.1*epoch_val
else:
iter_val = int(p.split("-")[3].split(":")[1].split(".")[0])
epoch_val = int(p.split("-")[2].split(":")[1])
val = float(epoch_val)+0.1*iter_val
if lowest_idx==-1 or val<lowest:
lowest = val
lowest_idx = png_filenames.index(p)
sorted_png.append(png_filenames[lowest_idx])
del png_filenames[lowest_idx]
if len(png_filenames)==0: break
png_filenames = sorted_png
with imageio.get_writer(parent_folder+"/prediction-heatmap.gif", mode='I',duration=frame_duration) as writer:
for filename in png_filenames:
image = imageio.imread(parent_folder+"/"+filename)
writer.append_data(image)
评论列表
文章目录