-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayers.jl
66 lines (47 loc) · 1.59 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: relu, gpu
@testset "layer" begin
atype = gpu() >= 0 ? KnetArray{Float64} : Array{Float64}
input = rand(1:10)
output = rand(1:10)
layer = AutoML.LinearLayer(input, output)
batchsize = map(x->2^x, rand(3:10))
x = atype(randn(input, batchsize))
y = atype(randn(output, batchsize))
output = layer(x)
@test typeof(output) <: atype
error = layer(x, y)
@test typeof(error) == typeof(float(rand(1:2)))
end
@testset "linearchain" begin
atype = gpu() >= 0 ? KnetArray{Float64} : Array{Float64}
input = rand(1:10)
hidden = rand(1:10)
output = rand(1:10)
layer = AutoML.LinearLayer(input, hidden)
layer2 = AutoML.LinearLayer(hidden, output)
chain = AutoML.LinearChain(layer, layer2)
batchsize = map(x->2^x, rand(3:10))
x = atype(randn(input, batchsize))
y = atype(randn(output, batchsize))
output = chain(x)
@test typeof(output) <: atype
error = chain(x, y)
@test typeof(error) == typeof(float(rand(1:2)))
end
@testset "classificationchain" begin
atype = gpu() >= 0 ? KnetArray{Float64} : Array{Float64}
input = rand(1:10)
hidden = rand(1:10)
output = rand(1:10)
layer = AutoML.LinearLayer(input, hidden)
layer2 = AutoML.LinearLayer(hidden, output)
chain = AutoML.CategoricalChain(layer, layer2)
batchsize = map(x->2^x, rand(3:10))
numclass = rand(2:10)
x = atype(randn(input, batchsize))
y = rand([1:numclass;], 1, batchsize)
output = chain(x)
@test typeof(output) <: atype
error = chain(x, y)
@test typeof(error) == typeof(float(rand(1:2)))
end