Skip to content

Commit

Permalink
Changed vote construction to non-allocating array using view (addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewilliami committed Oct 27, 2020
1 parent 61b0382 commit 750aa22
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 6 additions & 4 deletions examples/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ println("...done")

function main(;
smart_choose_feats::Bool=false,
alt::Bool=false
alt::Bool=false,
scale::Bool=false,
scale_to::Tuple=(200, 200)
)
include("constants.jl")

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

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))
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)

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")
else
Expand All @@ -49,7 +51,7 @@ function main(;
end

# classifiers are haar like features
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))
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)

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

@time main(smart_choose_feats=true, alt=false)
@time main(smart_choose_feats=true, alt=false, scale=true, scale_to=(19, 19))
8 changes: 3 additions & 5 deletions src/AdaBoost.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,10 @@ function learn(
# next!(p)
# end
Base.Threads.@threads for image_file in image_files
println("about to load images")
ii_img = load_image(image_file, scale=scale, scale_to=scale_to)
num_processed += 1
println("putting votes into array")
votes[num_processed, :] .= map(f -> get_vote(f, ii_img), features)
# map!(f -> get_vote(f, ii_img), view(votes, num_processed, :), features)
# votes[num_processed, :] .= map(f -> get_vote(f, ii_img), features)
map!(f -> get_vote(f, ii_img), view(votes, num_processed, :), features)

# increment progress bar
next!(p)
Expand All @@ -146,7 +144,7 @@ function learn(
classifiers = []
p = Progress(num_classifiers, 1)
Base.Threads.@threads for t in 1:num_classifiers # previously, zerosarray
classification_errors = spzeros(length(feature_indices))
classification_errors = zeros(length(feature_indices))
# normalize the weights $w_{t,i}\gets \frac{w_{t,i}}{\sum_{j=1}^n w_{t,j}}$
weights = float(weights) / sum(weights)

Expand Down

0 comments on commit 750aa22

Please sign in to comment.