np.genfromtxt读点云非常的慢,并且需要读取文件的10倍内存
2021/11/24 7:14:03
本文主要是介绍np.genfromtxt读点云非常的慢,并且需要读取文件的10倍内存,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
issue 连接
https://github.com/numpy/numpy/issues/3477
今天使用np.genfromtxt加载一个5G不到的csv文件,把我30G内存+10Gswap都干满了还是报了out of memory.
一开始以为是open方法慢呢,原来是np.genfromtxt
一定要注意!!!!
np.genfromtxt非常的慢,并且需要读取文件的10倍内存
有问题的代码实例
with open(bin_file, 'r') as f: #读取5G的文件居然需要10倍大小的内存!!!!! csv = np.genfromtxt(f, delimiter=",", dtype='float32') csv = csv.reshape((count, shape_x, shape_y, shape_c)) print(csv.shape) for i in range(count): dset[i,:,:,:] = csv[i, :,:,:]
替换方案
使用np.loadtxt
def write_h5(file): print("load file ", file) #csv = np.genfromtxt(f, delimiter=",", dtype='float32') csv = np.loadtxt(file, delimiter=',') print("load completed! ") csv = csv.reshape((total_count, shape_x, shape_y, shape_c)) h5f = h5py.File(file_name, 'w') print("create h5file ", file_name) h5f.create_dataset(name='data', data=csv) print("create h5file dataset") h5f.close()
————————————————
版权声明:本文为CSDN博主「安安爸Chris」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/mimiduck/article/details/116954108
这篇关于np.genfromtxt读点云非常的慢,并且需要读取文件的10倍内存的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-26结对编程到底难不难?答案在这里
- 2024-06-19《2023版Java工程师》课程升级公告
- 2024-06-15matplotlib作图不显示3D图,怎么办?
- 2024-06-1503-Loki 日志监控
- 2024-06-1504-让LLM理解知识 -Prompt
- 2024-06-05做软件测试需要懂代码吗?
- 2024-06-0514-ShardingSphere的分布式主键实现
- 2024-06-03为什么以及如何要进行架构设计权衡?
- 2024-05-31全网首发第二弹!软考2024年5月《软件设计师》真题+解析+答案!(11-20题)
- 2024-05-31全网首发!软考2024年5月《软件设计师》真题+解析+答案!(21-30题)