-
Notifications
You must be signed in to change notification settings - Fork 1
/
layers.jl
66 lines (54 loc) · 1.38 KB
/
layers.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
using Knet
# Deep Convolutional Generator
function dcGbn_input(w, m, x, training)
x = deconv4(w[1], x, mode=1)
x = batchnorm(x, m, w[2], training=training)
return relu.(x)
end
function dcGbn_hidden(w, m, x, training)
x = deconv4(w[1], x, stride=2, padding=1, mode=1)
x = batchnorm(x, m, w[2], training=training)
return relu.(x)
end
function dcGbn_out(w, x)
x = deconv4(w, x, stride=2, padding=1, mode=1)
return tanh.(x)
end
# Deep Convolutional Discriminator
# Input does not have batchnorm
function dcDin(w, x, leak)
x = conv4(w, x, stride=2, padding=1, mode=1)
return leakyrelu.(x, leak)
end
function dcD(w, m, x, leak, training)
x = conv4(w[1], x, stride=2, padding=1, mode=1)
x = batchnorm(x, m, w[2], training=training)
return leakyrelu.(x, leak)
end
function dcDout(w, x)
return conv4(w, x, mode=1)
end
# Deep Convolutional Generator with no batchnorm
function dcGinput(w, x)
x = deconv4(w, x, mode=1)
return relu.(x)
end
function dcGhidden(w, x)
x = deconv4(w, x, stride=2, padding=1, mode=1)
return relu.(x)
end
function dcGout(w, x)
x = deconv4(w, x, stride=2, padding=1, mode=1)
return tanh.(x)
end
# Common MLP layer
function mlp(w, x)
return relu.(w[1] * x .+ w[2])
end
# Common MLP output layer
function mlpout(w, x)
return w[1] * x .+ w[2]
end
function leakyrelu(x, alpha)
return max(alpha*x, x)
end