-
Notifications
You must be signed in to change notification settings - Fork 0
/
kfp_nn_model.jl
92 lines (72 loc) · 1.65 KB
/
kfp_nn_model.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using ImageView
using CSV
using Flux
using Flux: @epochs
using LinearAlgebra
using DataFrames
using CuArrays
using CUDAnative
using Statistics
using ProgressBars
using MLDataUtils
using MLDataPattern
train = CSV.read("data/training.csv") |> DataFrame;
X = train[:Image];
deletecols!(train, :Image);
describe(train)
## Lots of missing values
"""
Calculates all missing values of a DF Col
"""
function missing_by_col(x)
sum(ismissing.(x))
end
[missing_by_col(col) for col = eachcol(train)]
"""
Replaces all missing values for a dataframe.
N.B. This only works on numeric columns.
"""
function replace_missing(df)
for col in names(df)
col_mean = mean(skipmissing(df[col]))
df[ismissing.(df[col]), col] = col_mean
end
return df
end
trian = replace_missing(train);
[missing_by_col(col) for col = eachcol(train)] |> sum
## Image Manipulator
"""
Creates list of image values.
"""
function image_manipulator(X)
l = []
for i ∈ ProgressBar(1:size(X, 1))
img = img_vals(X[i])
img = Float64.(img) # Might have to make it 32
append!(l, img)
end
l = reshape(l, 1, 96, 96, size(X, 1))
Float64.(l)
end
"""
Splits cell of a dataframe into an image when seperated by spaces.
"""
function img_vals(x)
img = split(x)
img = tryparse.(Float64, img)
img = reshape(img, 96, 96)
img = img' # To fix the orientation of the images
img = Float32.(img)
img
end
x = image_manipulator(X);
imshow(x[1, :, :, 2])
# Make train test split
y_train, y_val = splitobs(train, 0.7);
x_train, x_val = splitobs(x, 0.7);
## Model
@info("constructing the model")
model = Chain(
Conv((3,3), 1=>16, relu)
)