In [120]:
using DataFrames
using Gadfly
using Images
using ImageMagick
In [1]:
path = "/home/fliang/tmp/facial-keypoints"
Out[1]:
In [12]:
train_data = readtable("$(path)/training.csv")
test_data = readtable("$(path)/test.csv")
describe(train_data)
Converts Image
column from strings into Images
In [114]:
function stringToImage(image_string)
return grayim(convert(Array{UInt8}, reshape(readdlm(IOBuffer(image_string)), 96, 96)))
end
train_data[:Image] = map(stringToImage, train_data[:Image])
test_data[:Image] = map(stringToImage, test_data[:Image])
Out[114]:
Visualize some of the data
In [140]:
example_id = 1
train_data[:Image][example_id]
Out[140]:
In [198]:
train_idx = 1
xs = convert(Array{Float64}, train_data[train_idx,[:left_eye_center_x, :right_eye_center_x, :nose_tip_x, :mouth_center_top_lip_x]])
ys = -1*convert(Array{Float64}, train_data[train_idx,[:left_eye_center_y, :right_eye_center_y, :nose_tip_y, :mouth_center_top_lip_y]])
plot(x=xs,y=ys, Coord.Cartesian(xmin=0, xmax=96, ymin=-96, ymax=0))
Out[198]:
In [265]:
colMeans = map(x -> x[1], colwise(x -> mean(dropna(x)), train_data[names(train_data) .!= :Image]))
Out[265]:
In [313]:
predictions = DataFrame()
predictions[:ImageId] = 1:size(test_data,1)
mat = repmat(colMeans', size(test_data,1), 1)
predictions = hcat(predictions, DataFrame([mat[:,i] for i in 1:size(mat,2)], names(train_data)[names(train_data) .!= :Image]))
head(predictions)
Out[313]:
In [331]:
submission = stack(predictions, names(predictions[names(predictions) .!= :ImageId]))
submission = hcat(DataFrame(RowId=1:size(submission, 1)), submission)
rename!(submission, :variable, :FeatureName)
rename!(submission, :value, :Location)
example = readtable("$(path)/SampleSubmission.csv")
delete!(example, :Location)
submission = join(example, submission, on=:RowId)
submission = submission[:,[:RowId, :Location]]
writetable("$(path)/output.csv", submission)
The idea is to extract an image patch centered at each keypoint and train a classifier on these. Then, for a test image we run a sliding window across the image and predict the keypoint to be where the activation of the sliding window is maximized.
In [ ]: