2015-09-24 07:49:45 +08:00
|
|
|
require 'nn'
|
2015-12-21 11:23:15 +08:00
|
|
|
|
2015-09-24 07:49:45 +08:00
|
|
|
require 'dpnn'
|
2015-12-21 11:23:15 +08:00
|
|
|
|
2015-09-24 07:49:45 +08:00
|
|
|
require 'optim'
|
|
|
|
|
2016-01-12 04:36:58 +08:00
|
|
|
if opt.cuda then
|
|
|
|
require 'cunn'
|
|
|
|
if opt.cudnn then
|
|
|
|
require 'cudnn'
|
|
|
|
cudnn.benchmark = false
|
|
|
|
cudnn.fastest = true
|
|
|
|
cudnn.verbose = false
|
|
|
|
end
|
|
|
|
end
|
2016-01-07 05:04:10 +08:00
|
|
|
|
2015-09-24 07:49:45 +08:00
|
|
|
paths.dofile('torch-TripletEmbedding/TripletEmbedding.lua')
|
|
|
|
|
|
|
|
if opt.retrain ~= 'none' then
|
|
|
|
assert(paths.filep(opt.retrain), 'File not found: ' .. opt.retrain)
|
|
|
|
print('Loading model from file: ' .. opt.retrain);
|
2016-01-07 05:04:10 +08:00
|
|
|
model = torch.load(opt.retrain)
|
2016-04-06 06:01:15 +08:00
|
|
|
print("Using imgDim = ", opt.imgDim)
|
2015-09-24 07:49:45 +08:00
|
|
|
else
|
|
|
|
paths.dofile(opt.modelDef)
|
2016-01-12 05:44:50 +08:00
|
|
|
assert(imgDim, "Model definition must set global variable 'imgDim'")
|
|
|
|
assert(imgDim == opt.imgDim, "Model definiton's imgDim must match imgDim option.")
|
2016-01-07 05:04:10 +08:00
|
|
|
model = createModel()
|
2015-09-24 07:49:45 +08:00
|
|
|
end
|
|
|
|
|
2016-01-07 05:04:10 +08:00
|
|
|
criterion = nn.TripletEmbeddingCriterion(opt.alpha)
|
2015-09-24 07:49:45 +08:00
|
|
|
|
2016-01-12 04:36:58 +08:00
|
|
|
if opt.cuda then
|
|
|
|
model = model:cuda()
|
2016-03-11 18:09:23 +08:00
|
|
|
if opt.cudnn then
|
|
|
|
cudnn.convert(model,cudnn)
|
|
|
|
end
|
2016-01-12 04:36:58 +08:00
|
|
|
criterion:cuda()
|
|
|
|
end
|
2015-09-24 07:49:45 +08:00
|
|
|
|
2016-04-06 06:01:15 +08:00
|
|
|
optimizeNet(model, opt.imgDim)
|
2016-03-31 05:21:13 +08:00
|
|
|
|
2015-09-24 07:49:45 +08:00
|
|
|
print('=> Model')
|
|
|
|
print(model)
|
2016-01-09 00:18:44 +08:00
|
|
|
print(('Number of Parameters: %d'):format(model:getParameters():size(1)))
|
2015-09-24 07:49:45 +08:00
|
|
|
|
|
|
|
print('=> Criterion')
|
|
|
|
print(criterion)
|
|
|
|
|
|
|
|
collectgarbage()
|