-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
executable file
·68 lines (57 loc) · 1.72 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
-- @author Qi Hu, Sachin Mehta
--- -----
-- Module to start training
-- @module main
require 'torch'
require 'paths'
require 'optim'
require 'nn'
torch.setdefaulttensortype('torch.FloatTensor')
--- parse the command line arguments
local opts = require 'opts'
opt = opts.parse(arg) --global variable (can be accessed across files)
opt.cacheDir = opt.dataCache .. '/' .. opt.dataset
opt.dataCacheFileName = opt.cacheDir .. '/data.t7'
if opt.dataset == 'cv' then
if not paths.filep(opt.dataCacheFileName) then
print('Loading Camvid dataset from loadCamVid')
require 'loadCamVid'
else
print('loading cached Camvid file')
end
dataset = torch.load(opt.dataCacheFileName)
elseif opt.dataset == 'pcon' then
if not paths.filep(opt.dataCacheFileName) then
print('Loading Pascal Context dataset from loadPascalContext')
require 'loadPascalContext'
else
print('loading cached file')
end
dataset = torch.load(opt.dataCacheFileName)
elseif opt.dataset == 'pas' then
if not paths.filep(opt.dataCacheFileName) then
print('Loading Pascal dataset from loadPascal')
require 'loadPascal'
else
print('loading cached file')
end
dataset = torch.load(opt.dataCacheFileName)
else
print('Wrong dataset specified. Please check')
print('Exiting')
os.exit()
end
--number of classes in the dataset
opt.classes = dataset.classes
print('Dataset has ' .. opt.classes .. ' classes including background')
-- load the model
local models = require 'init'
model, criterion, epochNo = models.modelSetup()
local train = require 'train'
local test = require 'test'
-- start training and validation
for ep = epochNo, opt.maxEpoch do
model, criterion, confusionMat = train(ep, dataset)
test(ep, dataset)
collectgarbage()
end