【发布时间】:2019-02-19 18:31:20
【问题描述】:
如你所知,我是 lua 的初学者。我试图理解一个我被困在以下代码段的功能?
在最后一行的下面代码sn-p中使用:
function classify(txt_dir, img_dir, cls_list)
local acc = 0.0
local total = 0.0
local fea_img = {}
local fea_txt = {}
for fname in io.lines(cls_list) do
local imgpath = img_dir .. '/' .. fname .. '.t7'
local txtpath = txt_dir .. '/' .. fname .. '.t7'
fea_img[#fea_img + 1] = extract_img(imgpath)
fea_txt[#fea_txt + 1] = extract_txt(txtpath)
end
for i = 1,#fea_img do
-- loop over individual images.
for k = 1,fea_img[i]:size(1) do
local best_match = 1
local best_score = -math.huge
for j = 1,#fea_txt do
local cur_score = torch.dot(fea_img[i][{k,{}}], fea_txt[j])
据我了解,fea_img 是一个 lua 表。 fea_img[i][{k,{}}] 行是否对表 fea_img 中键“i”的值进行了某种切片?
我尝试搜索更多示例,发现这里也使用了这个(最后一行):
for i = 1,nsamples,batchsize do
-- indices
local lasti = math.min(i+batchsize-1,nsamples)
local m = lasti - i + 1
-- k-means step, on minibatch
local batch = x[{ {i,lasti},{} }]
对此的任何帮助将不胜感激。谢谢!
【问题讨论】: