【发布时间】:2017-03-01 07:16:11
【问题描述】:
我有大量的 .txt 文件(可能大约 1000 万个),每个文件的行数/列数相同。它们实际上是一些单通道图像,像素值用空格分隔。这是我为完成这项工作而编写的代码,但速度很慢。我想知道是否有人可以建议一种更优化/更有效的方法:
require 'torch'
f = assert(io.open(txtFilePath, 'r'))
local tempTensor = torch.Tensor(1, 64, 64):fill(0)
local i = 1
for line in f:lines() do
local l = line:split(' ')
for key, val in ipairs(l) do
tempTensor[{1, i, key}] = tonumber(val)
end
i = i + 1
end
f:close()
【问题讨论】:
标签: optimization machine-learning lua torch