Skip to content

Commit

Permalink
Added more specific zero and one types (addresses #26)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewilliami committed Oct 27, 2020
1 parent 7887e44 commit 23f889f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/AdaBoost.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/HaarLikeFeature.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions src/IntegralImage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/Utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

#=
Expand Down

0 comments on commit 23f889f

Please sign in to comment.