2016-03-05 07:30:39 +08:00
|
|
|
-- Copyright 2016 Carnegie Mellon University
|
|
|
|
--
|
|
|
|
-- Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
-- you may not use this file except in compliance with the License.
|
|
|
|
-- You may obtain a copy of the License at
|
|
|
|
--
|
|
|
|
-- http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
--
|
|
|
|
-- Unless required by applicable law or agreed to in writing, software
|
|
|
|
-- distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
-- See the License for the specific language governing permissions and
|
|
|
|
-- limitations under the License.
|
|
|
|
|
|
|
|
require 'io'
|
|
|
|
require 'string'
|
|
|
|
require 'sys'
|
|
|
|
|
2016-03-20 03:44:47 +08:00
|
|
|
local batchRepresent = "../batch-represent/main.lua"
|
|
|
|
local lfwEval = "../evaluation/lfw.py"
|
2016-03-05 07:30:39 +08:00
|
|
|
|
|
|
|
local testLogger = optim.Logger(paths.concat(opt.save, 'test.log'))
|
|
|
|
|
|
|
|
local function getLfwAcc(fName)
|
|
|
|
local f = io.open(fName, 'r')
|
|
|
|
io.input(f)
|
|
|
|
local lastLine = nil
|
|
|
|
while true do
|
|
|
|
local line = io.read("*line")
|
|
|
|
if line == nil then break end
|
|
|
|
lastLine = line
|
|
|
|
end
|
|
|
|
io.close()
|
|
|
|
return tonumber(string.sub(lastLine, 6, 11))
|
|
|
|
end
|
|
|
|
|
|
|
|
function test()
|
|
|
|
if opt.cuda then
|
|
|
|
model = model:float()
|
|
|
|
end
|
|
|
|
local latestModelFile = paths.concat(opt.save, 'model_' .. epoch .. '.t7')
|
|
|
|
local outDir = paths.concat(opt.save, 'lfw-' .. epoch)
|
|
|
|
print(latestModelFile)
|
|
|
|
print(outDir)
|
2016-03-20 03:44:47 +08:00
|
|
|
local cmd = batchRepresent
|
2016-03-05 07:30:39 +08:00
|
|
|
if opt.cuda then
|
|
|
|
cmd = cmd .. ' -cuda '
|
|
|
|
end
|
|
|
|
cmd = cmd .. ' -batchSize ' .. opt.testBatchSize ..
|
|
|
|
' -model ' .. latestModelFile ..
|
2016-03-20 03:44:47 +08:00
|
|
|
' -data ' .. opt.lfwDir ..
|
|
|
|
' -outDir ' .. outDir ..
|
|
|
|
' -imgDim ' .. opt.imgDim
|
2016-03-05 07:30:39 +08:00
|
|
|
os.execute(cmd)
|
|
|
|
|
2016-03-20 03:44:47 +08:00
|
|
|
cmd = lfwEval .. ' Epoch' .. epoch .. ' ' .. outDir
|
2016-03-05 07:30:39 +08:00
|
|
|
os.execute(cmd)
|
|
|
|
|
|
|
|
lfwAcc = getLfwAcc(paths.concat(outDir, "accuracies.txt"))
|
|
|
|
testLogger:add{
|
|
|
|
['lfwAcc'] = lfwAcc
|
|
|
|
}
|
|
|
|
end
|