我正在尝试运行一个while循环,最后创建并保存图像。不幸的是,每个循环都会更新以前保存的图像文件,而不是创建新的图像文件。因此,在运行5次的while循环结束时(并且应该创建5个单独的图像),我最终得到一个运行5次的while循环,但只创建一个更新5次的图像。 这是我的相关代码块:
i = 5
while i > 0:
layer_name = 'pool'+str(i)
# Number of output classes of model being used
nb_classes = 1000
cam3 = grad_cam(x, vgg, sess, predicted_class, layer_name, nb_classes)
img = img.astype(float)
img /= img.max()
# Superimposing the visualization with the image.
new_img = img+3*cam3
new_img /= new_img.max()
# Display and save
#io.imshow(new_img)
#plt.show()
io.imsave(FLAGS.output, new_img)
i = i-1
print (i)
任何建议都受到高度赞赏,因为我已经被困在这几个小时了。感谢