简体   繁体   English

Keras model.predict 函数写入文件(而不是内存)

[英]Keras model.predict function write on file (instead of memory)

I have a fairly large image dataset and I want to know if there's a way I can make keras model.predict 'dump' results on a file on my disk intead of loading a large numpy array on memory, to avoid out of memory issues.我有一个相当大的图像数据集,我想知道是否有办法在我的磁盘上的文件上制作 keras model.predict 'dump' 结果,而不是在内存上加载一个大的 numpy 数组,以避免内存不足问题。

I know I can split the file in small batches and process each batch separately, but I'm wondering if I can alter keras (or python) behavior to direct the result to file (maybe a pickle object?).我知道我可以小批量拆分文件并分别处理每个批次,但我想知道是否可以更改 keras(或 python)行为以将结果定向到文件(也许是泡菜对象?)。

You can probably use np.savetxt to save the ndarray returned by model.predict directly,你大概可以使用np.savetxt直接保存ndarray返回的model.predict

np.savetxt( 'results.gz' , model.predict( test_images ) )

Also, the documentation for np.savetxt suggests,此外, np.savetxt的文档建议,

If the filename ends in .gz, the file is automatically saved in compressed gzip format.如果文件名以 .gz 结尾,文件将自动以压缩的 gzip 格式保存。 loadtxt understands gzipped files transparently. loadtxt 透明地理解 gzip 压缩文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM