5 Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/
6 Written by Francois Fleuret <francois.fleuret@idiap.ch>
8 This file is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 3 as
10 published by the Free Software Foundation.
12 It is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this file. If not, see <http://www.gnu.org/licenses/>.
29 local w, h, fs = 50, 50, 3
30 local nhu = (w - fs + 1) * (h - fs + 1)
32 local model = nn.Sequential()
34 :add(nn.SpatialConvolution(1, 1, fs, fs))
36 :add(nn.Linear(nhu, 1000))
39 :add(nn.Linear(1000, 100))
41 -- Decorate it for profiling
43 profiler.decorate(model)
45 -- Create the data and criterion
47 local input = torch.Tensor(1000, 1, h, w)
48 local target = torch.Tensor(input:size(1), 100)
49 local criterion = nn.MSECriterion()
55 -- Loop five times through the data forward and backward
58 local t1 = sys.clock()
63 local t2 = sys.clock()
65 local output = model:forward(input)
66 local loss = criterion:forward(output, target)
67 local dloss = criterion:backward(output, target)
68 model:backward(input, dloss)
70 local t3 = sys.clock()
72 dataTime = dataTime + (t2 - t1)
73 modelTime = modelTime + (t3 - t2)
75 nbSamples = nbSamples + input:size(1)
78 -- Print the accumulated timings
81 -- profiler.color = false
82 profiler.print(model, nbSamples)
83 -- profiler.print(model)
85 print(string.format('Total model time %.02fs', modelTime))
86 print(string.format('Total data time %.02fs', dataTime))