|
a |
|
b/code/detectorSimple.lua |
|
|
1 |
require 'torch'; |
|
|
2 |
require 'nn'; |
|
|
3 |
require 'image'; |
|
|
4 |
cuda = false |
|
|
5 |
--if cuda then |
|
|
6 |
require 'cutorch'; |
|
|
7 |
require 'cunn'; |
|
|
8 |
--end |
|
|
9 |
require 'sys'; |
|
|
10 |
local dir = require 'pl.dir'; |
|
|
11 |
|
|
|
12 |
local c = os.clock() |
|
|
13 |
local t = os.time() |
|
|
14 |
|
|
|
15 |
local trainFolder = '/home/andrew/mitosis/MITOS/training/' |
|
|
16 |
local mapFolder = '/home/andrew/mitosis/maps/' |
|
|
17 |
local netPath = '/home/andrew/mitosis/nets/net.t7' |
|
|
18 |
|
|
|
19 |
dofile("getImagePaths.lua") |
|
|
20 |
imagePaths = getImagePaths(trainFolder) |
|
|
21 |
|
|
|
22 |
if paths.dirp(mapFolder) == false then |
|
|
23 |
paths.mkdir(mapFolder) |
|
|
24 |
end |
|
|
25 |
|
|
|
26 |
dofile("scan.lua") |
|
|
27 |
dofile("expand.lua") |
|
|
28 |
|
|
|
29 |
for k,imagePath in ipairs(imagePaths) do |
|
|
30 |
print(k) |
|
|
31 |
|
|
|
32 |
local c1 = os.clock() |
|
|
33 |
local t1 = os.time() |
|
|
34 |
|
|
|
35 |
local net = torch.load(netPath) |
|
|
36 |
net = expand(net) |
|
|
37 |
if cuda then |
|
|
38 |
net = net:cuda() |
|
|
39 |
else |
|
|
40 |
net = net:float() |
|
|
41 |
end |
|
|
42 |
|
|
|
43 |
local img = image.load(imagePath, 3, 'float') |
|
|
44 |
if cuda then |
|
|
45 |
img = img:cuda() |
|
|
46 |
else |
|
|
47 |
img = img:float() |
|
|
48 |
end |
|
|
49 |
local map = scan(img, net) |
|
|
50 |
local outfile = paths.concat(mapFolder, paths.basename(imagePath)) |
|
|
51 |
|
|
|
52 |
image.save(outfile, map) |
|
|
53 |
|
|
|
54 |
print(os.clock()-c1) |
|
|
55 |
print(os.time()-t1) |
|
|
56 |
|
|
|
57 |
end |
|
|
58 |
|
|
|
59 |
print(os.clock()-c) |
|
|
60 |
print(os.time()-t) |