5 Written by Francois Fleuret (francois@fleuret.org)
7 This is free and unencumbered software released into the public
10 Anyone is free to copy, modify, publish, use, compile, sell, or
11 distribute this software, either in source code form or as a
12 compiled binary, for any purpose, commercial or non-commercial, and
15 In jurisdictions that recognize copyright laws, the author or
16 authors of this software dedicate any and all copyright interest in
17 the software to the public domain. We make this dedication for the
18 benefit of the public at large and to the detriment of our heirs
19 and successors. We intend this dedication to be an overt act of
20 relinquishment in perpetuity of all present and future rights to
21 this software under copyright law.
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
27 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
28 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 For more information, please refer to <http://unlicense.org/>
42 local w, h, fs = 50, 50, 3
43 local nhu = (w - fs + 1) * (h - fs + 1)
45 local model = nn.Sequential()
47 :add(nn.SpatialConvolution(1, 1, fs, fs))
49 :add(nn.Linear(nhu, 1000))
52 :add(nn.Linear(1000, 100))
54 -- Decorate it for profiling
56 profiler.decorate(model)
58 -- torch.save('model.t7', model)
60 -- Create the data and criterion
62 local input = torch.Tensor(1000, 1, h, w)
63 local target = torch.Tensor(input:size(1), 100)
64 local criterion = nn.MSECriterion()
70 -- Loop five times through the data forward and backward
73 local t1 = sys.clock()
78 local t2 = sys.clock()
80 local output = model:forward(input)
81 local loss = criterion:forward(output, target)
82 local dloss = criterion:backward(output, target)
83 model:backward(input, dloss)
85 local t3 = sys.clock()
87 dataTime = dataTime + (t2 - t1)
88 modelTime = modelTime + (t3 - t2)
90 nbSamples = nbSamples + input:size(1)
93 -- Print the accumulated timings
96 profiler.print(model, nbSamples)
97 -- profiler.print(model)
99 print(string.format('Total model time %.02fs', modelTime))
100 print(string.format('Total data time %.02fs', dataTime))