【问题标题】:Slow Writing to File in Lua在 Lua 中缓慢写入文件
【发布时间】:2016-05-15 08:21:14
【问题描述】:

我正在尝试将一些数据写入 Lua 中的文本文件,但由于某种原因它非常慢(仅 100 行 8 秒)。超过 100 行进一步减慢,超过 1000 行,我的 GPU 内存不足。请问我哪里错了?我需要在某处添加collectgarbage() 吗?谢谢。

fp = io.open(('predictions/valid_test.txt'), "w")
local soft = nn.SoftMax()
local n = 100

for i = 1, n do
   local t_data = data[{{start_idx, end_idx},{},{},{}}]
   local outputs = model:forward(t_data):float()
   local soft_data = soft:forward(outputs)
   fp:write(fname[i] .. ',' ..  soft_data[1] .. ',' .. '\n')
   xlua.progress(i, n)
end
fp.close()

【问题讨论】:

  • 只需评论fp:write( 行并运行以查看文件写入速度是否缓慢。
  • Lua 可以非常快速地写入文件。我相信您遇到的让它变慢的问题是循环中的其他行。你测试过他们的速度吗?

标签: file file-io io lua file-writing


【解决方案1】:

该错误实际上是 Torch 中的内存泄漏。不知道为什么这被否决了,我并不是在暗示 Lua 有缺陷! ;o

【讨论】:

    猜你喜欢
    • 2016-01-19
    • 2017-08-22
    • 1970-01-01
    • 2016-10-29
    • 2020-05-15
    • 1970-01-01
    • 2021-11-06
    • 2019-12-29
    • 2016-05-23
    相关资源
    最近更新 更多