-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathnet_utils.lua
70 lines (62 loc) · 1.83 KB
/
net_utils.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
69
70
require 'loadcaffe'
local net_utils = {}
function net_utils.load_cnn(name, backend, path_offset)
local model_dir, proto_file, model_file = nil, nil, nil
if name == 'vgg-16' then
model_dir = 'data/models/vgg-16'
proto_file = 'VGG_ILSVRC_16_layers_deploy.prototxt'
model_file = 'VGG_ILSVRC_16_layers.caffemodel'
else
error(string.format('Unrecognized model "%s"', name))
end
if path_offset then
model_dir = paths.concat(path_offset, model_dir)
end
print('loading network weights from .. ' .. model_file)
proto_file = paths.concat(model_dir, proto_file)
model_file = paths.concat(model_dir, model_file)
local cnn = loadcaffe.load(proto_file, model_file, backend)
return net_utils.cudnn_tune_cnn(name, cnn)
end
-- Hardcode good cudnn v3 algorithms for different networks and GPUs.
-- We can't just run cudnn in benchmark mode because it will recompute
-- benchmarks for every new image size, which will be very slow; instead
-- we just pick some good algorithms for large images (800 x 600). They
-- might not be optimal for all image sizes but will probably be better
-- than the defaults.
local cudnn_algos = {}
cudnn_algos['vgg-16'] = {}
cudnn_algos['vgg-16']['GeForce GTX TITAN X'] = {
[1] = {1, 0, 0},
[3] = {1, 1, 0},
[6] = {1, 1, 3},
[8] = {1, 1, 3},
[11] = {1, 1, 3},
[13] = {1, 1, 3},
[15] = {1, 1, 3},
[18] = {1, 1, 3},
[20] = {1, 1, 0},
[22] = {1, 1, 0},
[25] = {1, 1, 0},
[27] = {1, 1, 0},
[29] = {1, 1, 0},
}
--[[
-- These seeem to use too much memory =(
cudnn_algos['vgg-16']['GeForce GTX TITAN Z'] = {
[1] = {0, 0, 1},
[3] = {2, 1, 1},
[6] = {1, 0, 3},
[8] = {1, 1, 3},
[11] = {1, 0, 0},
[13] = {1, 0, 0},
[15] = {1, 0, 0},
[18] = {1, 0, 0},
[20] = {1, 0, 0},
[22] = {1, 0, 0},
[25] = {1, 0, 3},
[27] = {1, 0, 3},
[29] = {1, 0, 3},
}
--]]
return net_utils