From 23f889f08818bc2bf509e2f5297a7b05eaeb0614 Mon Sep 17 00:00:00 2001 From: "Jake W. Ireland" Date: Tue, 27 Oct 2020 15:13:57 +1300 Subject: [PATCH] Added more specific zero and one types (addresses #26) --- src/AdaBoost.jl | 2 +- src/HaarLikeFeature.jl | 2 +- src/IntegralImage.jl | 10 +++++----- src/Utils.jl | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/AdaBoost.jl b/src/AdaBoost.jl index d4a61ddb4..92c80d039 100755 --- a/src/AdaBoost.jl +++ b/src/AdaBoost.jl @@ -153,7 +153,7 @@ function learn( f_idx = feature_indices[j] # classifier error is the sum of image weights where the classifier is right # ε = sum(map(img_idx -> labels[img_idx] ≠ votes[img_idx, f_idx] ? weights[img_idx] : zero(Integer), 1:num_imgs)) - ε = sum([labels[img_idx] ≠ votes[img_idx, f_idx] ? weights[img_idx] : zero(Integer) for img_idx in 1:num_imgs]) + ε = sum([labels[img_idx] ≠ votes[img_idx, f_idx] ? weights[img_idx] : zero(Float64) for img_idx in 1:num_imgs]) classification_errors[j] = ε end diff --git a/src/HaarLikeFeature.jl b/src/HaarLikeFeature.jl index a3a93ee65..4399687ef 100755 --- a/src/HaarLikeFeature.jl +++ b/src/HaarLikeFeature.jl @@ -118,5 +118,5 @@ Get vote of this feature for given integral image. function get_vote(feature::HaarLikeObject, int_img::AbstractArray) score = get_score(feature, int_img)[1] # we only care about score here - return (feature.weight * score) < (feature.polarity * feature.threshold) ? one(Integer) : -one(Integer) + return (feature.weight * score) < (feature.polarity * feature.threshold) ? one(Int8) : -one(Int8) end diff --git a/src/IntegralImage.jl b/src/IntegralImage.jl index 161ddae56..79ec44aa0 100755 --- a/src/IntegralImage.jl +++ b/src/IntegralImage.jl @@ -70,13 +70,13 @@ getindex(A::IntegralArray, ids::Tuple...) = getindex(A, ids[1]...) =# function sum_region( integral_image_arr::AbstractArray, - top_left::Tuple{Int64,Int64}, - bottom_right::Tuple{Int64,Int64} + top_left::Tuple{Integer,Integer}, + bottom_right::Tuple{Integer,Integer} ) sum = integral_image_arr[bottom_right[2], bottom_right[1]] - sum -= top_left[1] > 1 ? integral_image_arr[bottom_right[2], top_left[1] - 1] : zero(Integer) - sum -= top_left[2] > 1 ? integral_image_arr[top_left[2] - 1, bottom_right[1]] : zero(Integer) - sum += top_left[2] > 1 && top_left[1] > 1 ? integral_image_arr[top_left[2] - 1, top_left[1] - 1] : zero(Integer) + sum -= top_left[1] > 1 ? integral_image_arr[bottom_right[2], top_left[1] - 1] : zero(Int64) + sum -= top_left[2] > 1 ? integral_image_arr[top_left[2] - 1, bottom_right[1]] : zero(Int64) + sum += top_left[2] > 1 && top_left[1] > 1 ? integral_image_arr[top_left[2] - 1, top_left[1] - 1] : zero(Int64) return sum end diff --git a/src/Utils.jl b/src/Utils.jl index 8dffa5e01..dd47c4f9c 100755 --- a/src/Utils.jl +++ b/src/Utils.jl @@ -165,7 +165,7 @@ function ensemble_vote(int_img::AbstractArray, classifiers::AbstractArray) # weightedSum = sum([c[2] for c in classifiers]) # return evidence >= (weightedSum / 2) ? 1 : -1 - return sum([get_vote(c, int_img) for c in classifiers]) >= 0 ? one(Integer) : zero(Integer) + return sum([get_vote(c, int_img) for c in classifiers]) >= 0 ? one(Int8) : zero(Int8) end #=