From 750aa22df45365c9e9dbe3ce3c0e3f09a71929cd Mon Sep 17 00:00:00 2001 From: "Jake W. Ireland" Date: Tue, 27 Oct 2020 15:10:37 +1300 Subject: [PATCH] Changed vote construction to non-allocating array using view (addresses #26) --- examples/basic.jl | 10 ++++++---- src/AdaBoost.jl | 8 +++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/basic.jl b/examples/basic.jl index ae743213a..b0846545f 100755 --- a/examples/basic.jl +++ b/examples/basic.jl @@ -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") @@ -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 @@ -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)) @@ -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)) diff --git a/src/AdaBoost.jl b/src/AdaBoost.jl index 5d84004ee..d4a61ddb4 100755 --- a/src/AdaBoost.jl +++ b/src/AdaBoost.jl @@ -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) @@ -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)