Skip to content

Commit

Permalink
Fix luacheck warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Amos committed Dec 27, 2015
1 parent 419ea9b commit ff51b2c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ install:

script:
- flake8 --ignore=E402,E501 .
- luacheck . --no-global
- luacheck . --no-global --no-self --exclude-files '*/torch-TripletEmbedding'
- |
docker run -v $PWD:/root/src/openface bamos/openface \
/bin/bash -l -c "cd /root/src/openface; \
Expand Down
4 changes: 2 additions & 2 deletions batch-represent/batch-represent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ function batchRepresent()
local indexEnd = math.min(nImgs, indexStart + opt.batchSize - 1)
local inputs, labels = dumpLoader:get(indexStart, indexEnd)
local paths = {}
for i=indexStart,indexEnd do
table.insert(paths, ffi.string(dumpLoader.imagePath[i]:data()))
for j=indexStart,indexEnd do
table.insert(paths, ffi.string(dumpLoader.imagePath[j]:data()))
end
repBatch(paths, inputs, labels)
if i % 5 == 0 then
Expand Down
36 changes: 17 additions & 19 deletions batch-represent/dataset.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
require 'torch'
torch.setdefaulttensortype('torch.FloatTensor')
local ffi = require 'ffi'
local class = require('pl.class')
local dir = require 'pl.dir'
local tablex = require 'pl.tablex'
local argcheck = require 'argcheck'
require 'sys'
require 'xlua'
Expand All @@ -22,7 +20,7 @@ local initcheck = argcheck{
]],
{check=function(paths)
local out = true;
for k,v in ipairs(paths) do
for _,v in ipairs(paths) do
if type(v) ~= 'string' then
print('paths can only be of string input');
out = false
Expand Down Expand Up @@ -104,9 +102,9 @@ function dataset:__init(...)
-- loop over each paths folder, get list of unique class names,
-- also store the directory paths per class
-- for each class,
for k,path in ipairs(self.paths) do
for _,path in ipairs(self.paths) do
local dirs = dir.getdirectories(path);
for k,dirpath in ipairs(dirs) do
for _,dirpath in ipairs(dirs) do
local class = paths.basename(dirpath)
local idx = tableFind(self.classes, class)
if not idx then
Expand Down Expand Up @@ -160,9 +158,9 @@ function dataset:__init(...)
local tmpfile = os.tmpname()
local tmphandle = assert(io.open(tmpfile, 'w'))
-- iterate over classes
for i, class in ipairs(self.classes) do
for i, _ in ipairs(self.classes) do
-- iterate over classPaths
for j,path in ipairs(classPaths[i]) do
for _,path in ipairs(classPaths[i]) do
local command = find .. ' "' .. path .. '" ' .. findOptions
.. ' >>"' .. classFindFiles[i] .. '" \n'
tmphandle:write(command)
Expand All @@ -173,8 +171,8 @@ function dataset:__init(...)
os.execute('rm -f ' .. tmpfile)

print('now combine all the files to a single large file')
local tmpfile = os.tmpname()
local tmphandle = assert(io.open(tmpfile, 'w'))
tmpfile = os.tmpname()
tmphandle = assert(io.open(tmpfile, 'w'))
-- concat all finds to a single large file in the order of self.classes
for i=1,#self.classes do
local command = 'cat "' .. classFindFiles[i] .. '" >>' .. combinedFindList .. ' \n'
Expand Down Expand Up @@ -214,16 +212,16 @@ function dataset:__init(...)
local runningIndex = 0
for i=1,#self.classes do
if self.verbose then xlua.progress(i, #(self.classes)) end
local length = tonumber(sys.fexecute(wc .. " -l '"
local clsLength = tonumber(sys.fexecute(wc .. " -l '"
.. classFindFiles[i] .. "' |"
.. cut .. " -f1 -d' '"))
if length == 0 then
if clsLength == 0 then
error('Class has zero samples: ' .. self.classes[i])
else
self.classList[i] = torch.linspace(runningIndex + 1, runningIndex + length, length):long()
self.imageClass[{{runningIndex + 1, runningIndex + length}}]:fill(i)
self.classList[i] = torch.linspace(runningIndex + 1, runningIndex + clsLength, clsLength):long()
self.imageClass[{{runningIndex + 1, runningIndex + clsLength}}]:fill(i)
end
runningIndex = runningIndex + length
runningIndex = runningIndex + clsLength
end

--==========================================================================
Expand Down Expand Up @@ -253,7 +251,7 @@ function dataset:__init(...)
-- split the classList into classListTrain and classListTest
for i=1,#self.classes do
local list = self.classList[i]
local count = self.classList[i]:size(1)
count = self.classList[i]:size(1)
local splitidx = math.floor((count * self.split / 100) + 0.5) -- +round
local perm = torch.randperm(count)
self.classListTrain[i] = torch.LongTensor(splitidx)
Expand Down Expand Up @@ -375,7 +373,7 @@ function dataset:sample(quantity)
quantity = quantity or 1
local dataTable = {}
local scalarTable = {}
for i=1,quantity do
for _=1,quantity do
local class = torch.random(1, #self.classes)
local out = self:getByClass(class)
table.insert(dataTable, out)
Expand All @@ -396,7 +394,7 @@ function dataset:sampleTriplet(quantity)
local scalarTable = {}

-- Anchors
for i=1,quantity do
for _=1,quantity do
local anchorClass = torch.random(1, #self.classes)
table.insert(dataTable, self:getByClass(anchorClass))
table.insert(scalarTable, anchorClass)
Expand Down Expand Up @@ -444,8 +442,8 @@ function dataset:samplePeople(peoplePerBatch, imagesPerPerson)
local cls = classes[i]
local n = numPerClass[i]
local shuffle = torch.randperm(n)
for i=1,n do
imgNum = self.classListSample[cls][shuffle[i]]
for j=1,n do
imgNum = self.classListSample[cls][shuffle[j]]
imgPath = ffi.string(torch.data(self.imagePath[imgNum]))
data[dataIdx] = self:sampleHookTrain(imgPath)
dataIdx = dataIdx + 1
Expand Down
2 changes: 0 additions & 2 deletions batch-represent/opts.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
local lfs = require 'lfs'

local M = { }

-- http://stackoverflow.com/questions/6380820/get-containing-path-of-lua-file
Expand Down
2 changes: 1 addition & 1 deletion models/openface/nn2.def.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
-- limitations under the License.


function createModel(nGPU)
function createModel()
local net = nn.Sequential()

net:add(nn.SpatialConvolutionMM(3, 64, 7, 7, 2, 2, 3, 3))
Expand Down
2 changes: 1 addition & 1 deletion openface/openface_server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ while true do
if imgPath and imgPath:len() ~= 0 then
img[1] = image.load(imgPath, 3, byte)
img[1] = image.scale(img[1], opt.imgDim, opt.imgDim)
local rep = nil
local rep
if opt.cuda then
imgCuda:copy(img)
rep = net:forward(imgCuda):float()
Expand Down
4 changes: 2 additions & 2 deletions training/data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ do -- start K datathreads (donkeys)
else -- single threaded data loading. useful for debugging
paths.dofile('donkey.lua')
donkeys = {}
function donkeys.addjob(_, f1, f2) f2(f1()) end
function donkeys.synchronize(_) end
function donkeys:addjob(f1, f2) f2(f1()) end
function donkeys:synchronize() end
end
end

Expand Down

0 comments on commit ff51b2c

Please sign in to comment.