-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.lua
57 lines (48 loc) · 1.86 KB
/
test.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
require 'image'
require 'utility'
require 'paths'
require 'io'
-- Makes a striped image of the colors we assign to each class
function make_comp()
x = torch.zeros(500, 500)
for i=1,10 do
x[{{}, {(i-1)*50+1, i*50}}] = i
end
label2img(x, "comp.png")
end
make_comp()
-- Example of how to test our model
for filename in io.popen('find test/*.jpg | sort -r -R | head -n 10'):lines() do
--filename = './test/9004581.jpg'
-- filename = 'large_test_img.jpg'
local bn = paths.basename(filename)
local input = image.load(filename)
local res = test_model("./Models/nhu=25,50,pools=8,2,conv_kernels=6,3,7,droput=0,indropout=0,num_images=-1,shifted_inputs=false.net", input, nil, filename)
local out = torch.zeros(input:size())
image.scale(out, res)
local blended = out * 0.5 + input * 0.5
local img = torch.zeros(3, input:size(2), 3*input:size(3))
img[{{},{},{1, input:size(3)}}] = input
img[{{},{},{input:size(3)+1, 2*input:size(3)}}] = blended
img[{{},{},{2*input:size(3)+1, 3*input:size(3)}}] = out
image.save("sampleimg/"..bn, img)
local img = torch.zeros(3, input:size(2), 3*input:size(3))
local ansfile = filename:sub(1,-4) .. "regions.txt"
local file = io.open(ansfile)
local answer = {}
for i=1,input:size(2) do
answer[i] = {}
for j=1,input:size(3) do
answer[i][j] = file:read("*number")+2
end
end
answer = torch.Tensor(answer)
answer = label2img(answer)
local blended = answer*0.5 + input*0.5
local img = torch.zeros(3, input:size(2), 3*input:size(3))
img[{{},{},{1, input:size(3)}}] = input
img[{{},{},{input:size(3)+1, 2*input:size(3)}}] = blended
img[{{},{},{2*input:size(3)+1, 3*input:size(3)}}] = answer
image.save("sampleimg/"..bn:sub(1,-4).."true.jpg", img)
end
--for word in string.gmatch(s,"pools+") do; print(word); end