Skip to content

Commit

Permalink
Fix anchor index calculation
Browse files Browse the repository at this point in the history
Fix anchor feature map source index calculation. Now returning a larger
portion of the feature rect in Localizer:inputToFeatureRect (inflating
rect by kernel width). Added debug-normalization function (to view
feature maps or weights).
  • Loading branch information
andreaskoepf committed Sep 21, 2015
1 parent ce5e246 commit 1f94e34
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
4 changes: 1 addition & 3 deletions Anchors.lua
Expand Up @@ -118,13 +118,11 @@ function Anchors:findPositive(roi_list, clip_rect, pos_threshold, neg_threshold,
for x=1,r.xs:size()[1] do
-- create rect, add layer & aspect info
local anchor_rect = Rect.new(r.xs[{x, 1}], minY, r.xs[{x, 2}], maxY)
--print(anchor_rect)
anchor_rect.layer = r.layer
anchor_rect.aspect = r.aspect
anchor_rect.index = { { r.aspect * 6 - 5, r.aspect * 6 }, r.ly + y - 1, r.ly + x - 1 }
anchor_rect.index = { { r.aspect * 6 - 5, r.aspect * 6 }, r.ly + y - 1, r.lx + x - 1 }

local v = Rect.IoU(roi.rect, anchor_rect)
--print(v)
if v > pos_threshold then
table.insert(matches, { anchor_rect, roi })
best = nil
Expand Down
2 changes: 1 addition & 1 deletion Localizer.lua
Expand Up @@ -43,7 +43,7 @@ function Localizer:inputToFeatureRect(rect, layer_index)
for i=1,layer_index do
local l = self.layers[i]
if l.dW < l.kW then
rect = rect:inflate((l.kW-l.dW)/2, (l.kH-l.dH)/2)
rect = rect:inflate((l.kW-l.dW), (l.kH-l.dH))
end

rect = rect:offset(l.padW, l.padH)
Expand Down
24 changes: 11 additions & 13 deletions main.lua
Expand Up @@ -48,9 +48,6 @@ if opt.seed ~= 0 then
cutorch.manualSeed(opt.seed)
end

-- precompute positive examples


function read_csv_file(fn)
-- format of RoI file:
-- filename, left, top, right, bottom, model_class_name, model_class_index, material_name, material_index
Expand Down Expand Up @@ -221,9 +218,10 @@ function create_optimization_target(pnet, cnet, weights, gradient, training_data
for i,x in ipairs(p) do
local anchor = x[1]
local roi = x[2]
local l = x[1].layer

local out = outputs[x[1].layer]
local delta_out = delta_outputs[x[1].layer]
local out = outputs[l]
local delta_out = delta_outputs[l]

local idx = x[1].index
local v = out[idx]
Expand All @@ -250,8 +248,9 @@ function create_optimization_target(pnet, cnet, weights, gradient, training_data

-- process negative
for i,x in ipairs(n) do
local out = outputs[x.layer]
local delta_out = delta_outputs[x.layer]
local l = x.layer
local out = outputs[l]
local delta_out = delta_outputs[l]
local idx = x.index
local v = out[idx]
local d = delta_out[idx]
Expand Down Expand Up @@ -419,7 +418,6 @@ function graph_evaluate(training_data_filename, network_filename, normalize)
for n,fn in ipairs(test_images) do

-- load image
print(fn)
local input = load_image_auto_size(fn, training_data.target_smaller_side, training_data.max_pixel_size, 'yuv')
local input_size = input:size()
input = normalize_image(input):cuda()
Expand Down Expand Up @@ -512,10 +510,10 @@ function graph_evaluate(training_data_filename, network_filename, normalize)

for i,m in ipairs(winners) do
local color
--if m.class ~= 17 and math.exp(m.confidence) > 0.25 then
if m.class ~= 17 and math.exp(m.confidence) > 0.25 then
draw_rectangle(img, m.r, blue)
draw_rectangle(img, m.r2, green)
--end
--draw_rectangle(img, m.r2, green)
end
end

image.saveJPG(string.format('dummy%d.jpg', n), img)
Expand Down Expand Up @@ -588,5 +586,5 @@ function graph_training(training_data_filename, network_filename)
end

--precompute_positive_list('training_data.t7', 0.6, 0.3)
graph_training('training_data.t7', 'full2_001000.t7')
--graph_evaluate('training_data.t7', 'full2_001000.t7', true)
graph_training('training_data.t7')
--graph_evaluate('training_data.t7', 'full2_022000.t7', true)
5 changes: 5 additions & 0 deletions utilities.lua
Expand Up @@ -141,3 +141,8 @@ end
function remove_quotes(s)
return s:gsub('^"(.*)"$', "%1")
end

function normalize_debug(t)
local lb, ub = t:min(), t:max()
return (t -lb):div(ub-lb+1e-10)
end

0 comments on commit 1f94e34

Please sign in to comment.