Skip to content

Commit

Permalink
removed tmp dir; fixed array mismatch; need to work on feature::??? e…
Browse files Browse the repository at this point in the history
…rror
  • Loading branch information
jakewilliami committed Aug 19, 2020
1 parent 97ca3c6 commit 2fcae63
Show file tree
Hide file tree
Showing 56 changed files with 240 additions and 726,350 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ docs/site/
# It records a fixed state of all packages used by the project. As such, it should not be
# committed for packages, but should be committed for applications that require a static
# environment.
Manifest.tomltest/images/pos/
test/images/neg
Manifest.toml

#
data/images/pos/
data/images/neg
15 changes: 10 additions & 5 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ trap "exit" INT
echo "Please ensure FaceDetection.jl is installed in your home directory..."
sleep 5

mkdir -p ~/FaceDetection.jl/test/images/testing/pos/
mkdir -p ~/FaceDetection.jl/test/images/testing/neg/
mkdir -p ~/FaceDetection.jl/test/images/testing/testing/pos/
mkdir -p ~/FaceDetection.jl/test/images/testing/testing/neg/

brew list > /tmp/brewlist
if ! grep "^imagemagick$" /tmp/brewlist > /dev/null 2>&1
then
Expand Down Expand Up @@ -39,11 +44,11 @@ cd ~/FaceDetection.jl/ && \
mv face-detection-data/pos/ test/images/ && \
mv face-detection-data/neg/ test/images/ && \
rm -rf face-detection-data/
# echo "Pruning the positive training images to have the same number as the negative images, or else there will be an array mismatch when constructing the image array in src/Adaboost.jl"
# for i in $(seq $(ls ~/FaceDetection.jl/test/images/neg/ | wc -l) $(ls ~/FaceDetection.jl/test/images/pos/ | wc -l)); do
# rm ~/FaceDetection.jl/test/images/pos/${i}.pgm
# # echo "${i}"
# done
echo "Pruning the positive training images to have the same number as the negative images, or else there will be an array mismatch when constructing the image array in src/Adaboost.jl"
for i in $(seq $(ls ~/FaceDetection.jl/test/images/neg/ | wc -l) $(($(ls ~/FaceDetection.jl/test/images/pos/ | wc -l)-1)); do
rm ~/FaceDetection.jl/test/images/pos/${i}.pgm
# echo "${i}"
done
#### The following step was only for python testing code. Netpbm.jl is powerful and fixed this.
Expand Down
42 changes: 24 additions & 18 deletions src/Adaboost.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using ProgressMeter
using Distributed # for parallel processing (namely, @everywhere)

include("HaarFeatureSelection.jl")
include("HaarLikeFeature.jl")



Expand All @@ -31,7 +31,7 @@ function learn(positiveIIs, negativeIIs, numClassifiers=-1, minFeatureWidth=1, m
"""
numPos = length(positiveIIs)
numNeg = length(negativeIIs)
numImgs = numPos + numNeg
global numImgs = numPos + numNeg
imgHeight, imgWidth = size(positiveIIs[1])

# Maximum feature width and height default to image width and height
Expand All @@ -48,8 +48,8 @@ function learn(positiveIIs, negativeIIs, numClassifiers=-1, minFeatureWidth=1, m
weights = hcat((posWeights, negWeights))
labels = hcat((ones(numPos), ones(numNeg) * -1))

# images = positiveIIs + negativeIIs
images = vcat(positiveIIs, negativeIIs)
global images = positiveIIs + negativeIIs
# global images = vcat(positiveIIs, negativeIIs)

# Create features for all sizes and locations
features = _create_features(imgHeight, imgWidth, minFeatureWidth, maxFeatureWidth, minFeatureHeight, maxFeatureHeight)
Expand All @@ -63,12 +63,14 @@ function learn(positiveIIs, negativeIIs, numClassifiers=-1, minFeatureWidth=1, m

votes = zeros((numImgs, numFeatures))
# bar = progressbar.ProgressBar()
# @everywhere numImgs begin
@everywhere begin
n = numImgs
processes = length(numImgs)
p = Progress(n, 1) # minimum update interval: 1 second
for i in processes
# votes[i, :] = np.array(pool.map(partial(_get_feature_vote, image=images[i]), features))
votes[i, :] = Array(_get_feature_vote, image=images[i]), features
for i in processes # bar(range(num_imgs)):
# votes[i, :] = np.array(partial(_get_feature_vote, image=images[i]), features)
votes[i, :] = Array(map(partial(_get_feature_vote)(image=images[i])), features)
next!(p)
end
end # end everywhere (end parallel processing)
Expand Down Expand Up @@ -131,28 +133,32 @@ end

function _create_features(imgHeight::Int64, imgWidth::Int64, minFeatureWidth::Int64, maxFeatureWidth::Int64, minFeatureHeight::Int64, maxFeatureHeight::Int64)
println("Creating Haar-like features...")
features = Array()
# features = Array()
features = []

for feature in FeatureTypes
for feature in FeatureTypes # from HaarLikeFeature.jl
# FeatureTypes are just tuples
println(typeof(feature), " " , feature)
featureStartWidth = max(minFeatureWidth, feature[1])
for featureWidth in range(featureStartWidth, stop=maxFeatureWidth, step=feature[1])
for x in 1:(imgWidth - featureWidth)
for y in 1:(imgHeight - featureHeight)
#=features.append(HaarLikeFeature(feature, (x, y), feature_width, feature_height, 0, 1))
features.append(HaarLikeFeature(feature, (x, y), feature_width, feature_height, 0, -1))=#
end # end for y
end # end for x
featureStartHeight = max(minFeatureHeight, feature[2])
for featureHeight in range(featureStartHeight, stop=maxFeatureHeight, step=feature[2])
for x in 1:(imgWidth - featureWidth)
for y in 1:(imgHeight - featureHeight)
feature = vcat(feature, HaarLikeFeature(feature, (x, y), featureWidth, featureHeight, 0, 1))
feature = vcat(feature, HaarLikeFeature(feature, (x, y), featureWidth, featureHeight, 0, -1))
end # end for y
end # end for x
end # end for feature height
end # end for feature width
end # end for feature in feature types

println("...finished processing; ", str(len(features)) + " features created.")
println("...finished processing; ", length(features), " features created.")

return features
end




export learn
export _get_feature_vote
export _create_features
Expand Down
18 changes: 14 additions & 4 deletions src/FDA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
Adapted from https://github.com/Simon-Hohberg/Viola-Jones/
"""

println("Loading required libraries (it will take a moment to precompile is this is your first time doing this)...")
println("Loading required libraries (it will take a moment to precompile if it is your first time doing this)...")

include("IntegralImage.jl")
include("AdaBoost.jl")
include("Utils.jl")


function main()
posTrainingPath = "/Users/jakeireland/FaceDetection.jl/test/images/pos/"
negTrainingPath = "/Users/jakeireland/FaceDetection.jl/test/images/neg/"
posTestingPath = "/Users/jakeireland/FaceDetection.jl/test/images/testing/pos/"
posTrainingPath = "/Users/jakeireland/FaceDetection.jl/data/images/pos/"
negTrainingPath = "/Users/jakeireland/FaceDetection.jl/data/images/neg/"
posTestingPath = "/Users/jakeireland/FaceDetection.jl/data/images/testing/pos/"
negTestingPath = "/Users/jakeireland/Desktop/Assorted Personal Documents/Wallpapers copy/"

numClassifiers = 2
Expand All @@ -38,6 +38,16 @@ function main()
nonFacesTraining = loadImages(negTrainingPath)
nonFacesIITraining = map(toIntegralImage, nonFacesTraining) # list(map(...))
println("...done. ", length(nonFacesTraining), " non-faces loaded.\n")

# println("Writing arrays to files for testing...")
# rm(joinpath(homedir(), "Desktop", "facesIITraining.txt"))
# rm(joinpath(homedir(), "Desktop", "nonFacesIITraining.txt"))
# open(joinpath(homedir(), "Desktop", "facesIITraining.txt"), "w") do io
# write(io, string(facesIITraining))
# end
# open(joinpath(homedir(), "Desktop", "nonFacesIITraining.txt"), "w") do io
# write(io, string(nonFacesIITraining))
# end

# classifiers are haar like features
println("Determining classifiers; this will take a while...")
Expand Down
179 changes: 0 additions & 179 deletions src/HaarFeatureSelection.jl

This file was deleted.

Loading

0 comments on commit 2fcae63

Please sign in to comment.