python - 在 python 循环中保存预测图像每次迭代都会变慢
问题描述
我在 keras 中的 predict_generator() 函数生成的 cnn 中循环预测图像,并在循环中使用 matplotlib> plt.savefig 保存它们。由于某种原因,这个循环的每次迭代都变得越来越慢;在 2000 次迭代之后,完成循环的时间从 <1s/it 变为 ~56s/it。什么可能导致放缓,以及可以采取什么措施来解决它?
循环结构如下:
results = model.predict_generator(test_img_gen,len(os.listdir(child)),verbose=1)
for i,img in tqdm(enumerate(results)):
plt.imshow(np.reshape(img,(512,512)), interpolation='nearest')
resultDir = '{}_{}_{}.png'.format(resdir,filenames[i],str(i))
plt.savefig(resultDir)
解决方案
推荐阅读
- vlc - Icecast+vlc 不流式传输
- node.js - 赛普拉斯依赖模块存根不工作并在运行时抛出错误
- python - 将产品条形码添加到 Odoo excel 报告时出错
- postgresql - Spring JPaRepository 无法识别列
- react-native - 有关 Java 端 React Native 错误的更多信息?
- java - 记录对 Java servlet 的访问
- upscale - 如何在 SAP Commerce Upscale 上添加外部样式?
- java - 从上下文操作模式删除后RecyclerView复制项目
- c# - 无法使用 Azure 在 YAML 中运行自动化测试
- ssl - Poco 库中的手动 SSL 服务器初始化问题