Skip to content

Commit 750aa22

Browse files
committed
Changed vote construction to non-allocating array using view (addresses #26)
1 parent 61b0382 commit 750aa22

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

examples/basic.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ println("...done")
2323

2424
function main(;
2525
smart_choose_feats::Bool=false,
26-
alt::Bool=false
26+
alt::Bool=false,
27+
scale::Bool=false,
28+
scale_to::Tuple=(200, 200)
2729
)
2830
include("constants.jl")
2931

@@ -38,7 +40,7 @@ function main(;
3840
# For performance reasons restricting feature size
3941
notify_user("Selecting best feature width and height...")
4042

41-
max_feature_width, max_feature_height, min_feature_height, min_feature_width, min_size_img = determine_feature_size(pos_training_path, neg_training_path; scale = false, scale_to = (577, 577))
43+
max_feature_width, max_feature_height, min_feature_height, min_feature_width, min_size_img = determine_feature_size(pos_training_path, neg_training_path; scale = scale, scale_to = scale_to)
4244

4345
println("...done. Maximum feature width selected is $max_feature_width pixels; minimum feature width is $min_feature_width; maximum feature height is $max_feature_height pixels; minimum feature height is $min_feature_height.\n")
4446
else
@@ -49,7 +51,7 @@ function main(;
4951
end
5052

5153
# classifiers are haar like features
52-
classifiers = FD.learn(pos_training_path, neg_training_path, num_classifiers, min_feature_height, max_feature_height, min_feature_width, max_feature_width; scale = false, scale_to = (577, 577))
54+
classifiers = FD.learn(pos_training_path, neg_training_path, num_classifiers, min_feature_height, max_feature_height, min_feature_width, max_feature_width; scale = scale, scale_to = scale_to)
5355

5456
FD.notify_user("Testing selected classifiers...")
5557
num_faces = length(filtered_ls(pos_testing_path))
@@ -74,4 +76,4 @@ function main(;
7476
@printf("%10.9s %10.15s %15s\n\n", "Non-faces:", non_faces_frac, non_faces_percent)
7577
end
7678

77-
@time main(smart_choose_feats=true, alt=false)
79+
@time main(smart_choose_feats=true, alt=false, scale=true, scale_to=(19, 19))

src/AdaBoost.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,10 @@ function learn(
129129
# next!(p)
130130
# end
131131
Base.Threads.@threads for image_file in image_files
132-
println("about to load images")
133132
ii_img = load_image(image_file, scale=scale, scale_to=scale_to)
134133
num_processed += 1
135-
println("putting votes into array")
136-
votes[num_processed, :] .= map(f -> get_vote(f, ii_img), features)
137-
# map!(f -> get_vote(f, ii_img), view(votes, num_processed, :), features)
134+
# votes[num_processed, :] .= map(f -> get_vote(f, ii_img), features)
135+
map!(f -> get_vote(f, ii_img), view(votes, num_processed, :), features)
138136
139137
# increment progress bar
140138
next!(p)
@@ -146,7 +144,7 @@ function learn(
146144
classifiers = []
147145
p = Progress(num_classifiers, 1)
148146
Base.Threads.@threads for t in 1:num_classifiers # previously, zerosarray
149-
classification_errors = spzeros(length(feature_indices))
147+
classification_errors = zeros(length(feature_indices))
150148
# normalize the weights $w_{t,i}\gets \frac{w_{t,i}}{\sum_{j=1}^n w_{t,j}}$
151149
weights = float(weights) / sum(weights)
152150

0 commit comments

Comments
 (0)