Skip to content

Commit

Permalink
Updated example files
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewilliami committed Oct 27, 2020
1 parent ff690f4 commit 9ba461e
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 233 deletions.
17 changes: 0 additions & 17 deletions examples/alt_data.jl

This file was deleted.

12 changes: 3 additions & 9 deletions examples/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,11 @@ println("...done")

function main(;
smart_choose_feats::Bool=false,
alt::Bool=false,
scale::Bool=false,
scale_to::Tuple=(200, 200)
)
include("constants.jl")

if ! alt
include("main_data.jl")
else
include("alt_data.jl")
end
include("constants.jl")
include("main_data.jl")

min_size_img = (19, 19) # default for our test dataset
if smart_choose_feats
Expand Down Expand Up @@ -74,4 +68,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, scale=true, scale_to=(19, 19))
@time main(smart_choose_feats=true, scale=true, scale_to=(20, 20))
2 changes: 0 additions & 2 deletions examples/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ main_image_path = joinpath(main_path, "data", "main")
alt_image_path = joinpath(main_path, "data", "alt")

num_classifiers = 10

data_file = joinpath(dirname(@__FILE__), "data", "haar-like_features_c$(num_classifiers)")
16 changes: 7 additions & 9 deletions examples/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,20 @@ using Printf: @printf
using Images: imresize
using Serialization: deserialize

println("...done")
println("...done\n")

function main(;
smart_choose_feats::Bool=false,
alt::Bool=false,
scale::Bool=false,
scale_to::Tuple=(200, 200)
)

include("constants.jl")

if ! alt
include("main_data.jl")
else
include("alt_data.jl")
end
include("main_data.jl")

max_feature_width, max_feature_height, min_feature_height, min_feature_width, min_size_img = determine_feature_size(pos_testing_path, neg_testing_path; scale = scale, scale_to = scale_to)
img_size = scale ? scale_to : min_size_img
data_file = joinpath(dirname(@__FILE__), "data", "haar-like_features_c$(num_classifiers)_$(img_size)")

if ! isfile(data_file)
error(throw("You do not have a data file. Ensure you run \"write.jl\" to obtain your Haar-like features before running this script/"))
Expand Down Expand Up @@ -65,4 +63,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, scale=true, scale_to=(20, 20))
@time main(smart_choose_feats=true, scale=true, scale_to=(20, 20))
15 changes: 4 additions & 11 deletions examples/scores.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,9 @@ using Serialization: deserialize

println("...done")

function main(;
smart_choose_feats::Bool=false, alt::Bool=false
)
include("constants.jl")

if ! alt
include("main_data.jl")
else
include("alt_data.jl")
end
function main(smart_choose_feats::Bool=false)
include("constants.jl")
include("main_data.jl")

# read classifiers from file
classifiers = deserialize(data_file)
Expand Down Expand Up @@ -103,4 +96,4 @@ function main(;
println("...done. Plot created at ", joinpath(dirname(dirname(@__FILE__)), "figs", "scores.pdf"), "\n")
end

@time main(smart_choose_feats=true, alt=false)
@time main(smart_choose_feats=true)
49 changes: 26 additions & 23 deletions examples/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,51 +23,54 @@ println("...done")

function main(;
smart_choose_feats::Bool=false,
alt::Bool=false,
image_reconstruction::Bool=true,
feat_validation::Bool=true
feat_validation::Bool=true,
scale::Bool=false,
scale_to::Tuple=(200, 200)
)
include("constants.jl")

if ! alt
include("main_data.jl")
else
include("alt_data.jl")
end
include("main_data.jl")

max_feature_width, max_feature_height, min_feature_height, min_feature_width, min_size_img = determine_feature_size(pos_testing_path, neg_testing_path; scale = scale, scale_to = scale_to)
img_size = scale ? scale_to : min_size_img
data_file = joinpath(dirname(@__FILE__), "data", "haar-like_features_c$(num_classifiers)_$(img_size)")

# read classifiers from file
classifiers = deserialize(data_file)

FD.notify_user("Loading test faces...")

faces_testing = FD.load_images(pos_testing_path)[1]
# FD.notify_user("Loading test faces...")
#
# faces_testing = FD.load_images(pos_testing_path)[1]
# # faces_ii_testing = map(FD.to_integral_image, faces_testing)
# faces_ii_testing = map(FD.to_integral_image, faces_testing)
faces_ii_testing = map(FD.to_integral_image, faces_testing)
println("...done. ", length(faces_testing), " faces loaded.")

FD.notify_user("Loading test non-faces..")

non_faces_testing = FD.load_images(neg_testing_path)[1]
non_faces_ii_testing = map(FD.to_integral_image, non_faces_testing)
println("...done. ", length(non_faces_testing), " non-faces loaded.\n")
# println("...done. ", length(faces_testing), " faces loaded.")
#
# FD.notify_user("Loading test non-faces..")
#
# non_faces_testing = FD.load_images(neg_testing_path)[1]
# non_faces_ii_testing = map(FD.to_integral_image, non_faces_testing)
# println("...done. ", length(non_faces_testing), " non-faces loaded.\n")

random_image = get_random_image(pos_testing_path)

if image_reconstruction
# Just for fun: putting all Haar-like features over each other generates a face-like image
FD.notify_user("Constructing an image of all Haar-like Features found...")

reconstructed_image = FD.reconstruct(classifiers, size(faces_testing[1]))
reconstructed_image = FD.reconstruct(classifiers, img_size)
save(joinpath(dirname(dirname(@__FILE__)), "figs", "reconstruction.png"), Gray.(map(clamp01nan, reconstructed_image)))

println("...done. See ", joinpath(dirname(dirname(@__FILE__)), "figs", "reconstruction.png"), ".\n")
end

if feat_validation
FD.notify_user("Constructing a validation image on a random image...")

FD.generate_validation_image(FD.get_random_image(joinpath(dirname(dirname(@__FILE__)), "figs", "validation.png")), classifiers)

validation_image = FD.generate_validation_image(random_image, classifiers)
save(joinpath(dirname(dirname(@__FILE__)), "figs", "validation.png"), validation_image)

println("...done. See ", joinpath(dirname(dirname(@__FILE__)), "figs", "validation.png"), ".\n")
end
end

@time main(smart_choose_feats=true, alt=false, image_reconstruction=true, feat_validation=true)
@time main(smart_choose_feats=true, image_reconstruction=true, feat_validation=false)
15 changes: 5 additions & 10 deletions examples/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,15 @@ const FD = FaceDetection
using Printf: @printf
using Serialization: serialize

println("...done")
println("...done\n")

function main(;
smart_choose_feats::Bool=false,
alt::Bool=false,
scale::Bool=false,
scale_to::Tuple=(200, 200)
)
include("constants.jl")

if ! alt
include("main_data.jl")
else
include("alt_data.jl")
end
include("main_data.jl")

min_size_img = (19, 19) # default for our test dataset
if smart_choose_feats
Expand All @@ -54,8 +48,9 @@ function main(;
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)

# write classifiers to file
data_file = joinpath(dirname(@__FILE__), "data", "haar-like_features_c$(num_classifiers)")
img_size = scale ? scale_to : min_size_img
data_file = joinpath(dirname(@__FILE__), "data", "haar-like_features_c$(num_classifiers)_$(img_size)")
serialize(data_file, classifiers)
end

@time main(smart_choose_feats=true, alt=false, scale=true, scale_to=(20, 20))
@time main(smart_choose_feats=true, scale=true, scale_to=(20, 20))
Loading

0 comments on commit 9ba461e

Please sign in to comment.