Skip to content

Commit

Permalink
Rectify a remaining Pythonic reference
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewilliami committed Aug 26, 2020
1 parent f9da7db commit a9e10eb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/Adaboost.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ function learn(positiveIIs::AbstractArray, negativeIIs::AbstractArray, numClassi
# featureWeight = 0.5 * log((1 - bestError) / bestError)
featureWeight = (1 - bestError) / bestError # β
# println(typeof(featureWeight))
bestFeature.weight = featureWeight # need to element-wise alter the struct `weight`; else we get `setfield! immutable struct of type HaarLikeFeature cannot be changed`
bestFeature.weight = featureWeight

# classifiers = vcat(classifiers, bestFeature)
# println(classifiers)
classifiers = push!(classifiers, bestFeature)

# update image weights $w_{t+1,i}=w_{t,i}\beta_{t}^{1-e_i}$
Expand All @@ -184,6 +185,7 @@ function learn(positiveIIs::AbstractArray, negativeIIs::AbstractArray, numClassi
next!(p)
end

# println(typeof(classifiers[1]))
return classifiers

end
Expand Down
12 changes: 9 additions & 3 deletions src/FDA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ function main(alt::Bool=false)
println("Determining classifiers; this may take a while...")
classifiers = learn(facesIITraining, nonFacesIITraining, numClassifiers, minFeatureHeight, maxFeatureHeight, minFeatureWidth, maxFeatureWidth)

# [println(c) for c in classifiers]
# println(typeof(classifiers))
# for c in classifiers
# println(typeof(c))
# end

println("Loading test faces...")
facesTesting = loadImages(posTestingPath)
facesIITesting = map(toIntegralImage, facesTesting) # list(map(...))
Expand All @@ -79,9 +85,9 @@ function main(alt::Bool=false)
correctNonFaces = length(nonFacesTesting) - sum(ensembleVoteAll(nonFacesIITesting, classifiers))

println("...done.\n\nResult:\n Faces: ", correctFaces, "/", length(faces_testing)
, " (", ((float(correctFaces) / len(facesTesting)) * 100), "%)\n non-Faces: "
, (correct_non_faces), "/", len(non_faces_testing), " ("
, ((float(correct_non_faces) / len(non_faces_testing)) * 100), "%)")
, " (", ((deepfloat(correctFaces) / length(facesTesting)) * 100), "%)\n non-Faces: "
, (correct_non_faces), "/", length(non_faces_testing), " ("
, ((deepfloat(correct_non_faces) / length(non_faces_testing)) * 100), "%)")

# Just for fun: putting all haar-like features over each other generates a face-like image
recon = reconstruct(classifiers, size(facesTesting[1]))
Expand Down
29 changes: 26 additions & 3 deletions src/Utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ function ensembleVote(intImg::AbstractArray, classifiers::AbstractArray)
# return 0
# end

return (sum([c.get_vote(int_img) for c in classifiers]) >= 0 ? 1 : 0)
# println([typeof(c) for c in classifiers])
# println(typeof(classifiers))
return deepsum([getVote(c, intImg) for c in classifiers]) >= 0 ? 1 : 0

# >= 0 ? 1 : 0
end

function ensembleVoteAll(intImgs::AbstractArray, classifiers::AbstractArray)
Expand All @@ -148,9 +152,28 @@ function ensembleVoteAll(intImgs::AbstractArray, classifiers::AbstractArray)
[type: Abstract Arrays (array of Integers)]
=#

votePartial = partial(ensembleVote, classifiers)
# [println(typeof(c)) for c in classifiers]
# println(typeof(classifiers))

# votePartial = [partial(ensembleVote, c) for c in classifiers]
# votePartial = partial(ensembleVote, [c for c in classifiers])
# votePartial = partial(ensembleVote, classifiers)
#
# return map(votePartial, intImgs)

# map(i -> ensembleVote(classifiers, i), intImgs)
return map(i -> ensembleVote(i, classifiers), intImgs)

# votePartial = partial(ensembleVote, intImgs)
#
# return map(votePartial, classifiers)


# map(imgIDX -> (labels[imgIDX] ≠ votes[imgIDX, bestFeatureIDX]) ? weights[imgIDX] * featureWeight : weights[imgIDX] * featureWeight, 1:numImgs)
#
# map(i -> (), intImgs)
#

return map(votePartial, intImgs)
end


Expand Down

0 comments on commit a9e10eb

Please sign in to comment.