Flux.jl/test/backend/mxnet.jl

52 lines
1.1 KiB
Julia
Raw Normal View History

2017-02-23 22:28:18 +00:00
using MXNet
Flux.loadmx()
@testset "MXNet" begin
xs = rand(20)
d = Affine(20, 10)
2017-03-08 17:35:15 +00:00
dm = mxnet(d, (1, 20))
2017-02-23 22:28:18 +00:00
@test d(xs) dm(xs)
2017-03-06 17:20:15 +00:00
m = Multi(20, 15)
2017-03-08 17:35:15 +00:00
mm = mxnet(m, (1, 20))
2017-03-06 17:20:15 +00:00
@test all(isapprox.(mm(xs), m(xs)))
2017-02-23 22:51:37 +00:00
@testset "Backward Pass" begin
d = deepcopy(d)
@test dm(xs) d(xs)
@test dm(xs) d(xs)
Δ = back!(dm, randn(10), xs)
@test length(Δ) == 20
update!(dm, 0.1)
@test dm(xs) d(xs)
@test dm(xs) d(xs)
end
2017-02-23 22:28:18 +00:00
@testset "FeedForward interface" begin
f = mx.FeedForward(Chain(d, softmax))
@test mx.infer_shape(f.arch, data = (20, 1))[2] == [(10, 1)]
m = Chain(Input(28,28), Conv2D((5,5), out = 3), MaxPool((2,2)),
flatten, Affine(1587, 10), softmax)
f = mx.FeedForward(m)
2017-02-23 22:51:37 +00:00
# TODO: test run
2017-02-23 22:28:18 +00:00
@test mx.infer_shape(f.arch, data = (20, 20, 5, 1))[2] == [(10, 1)]
end
@testset "Stack Traces" begin
model = TLP(Affine(10, 20), Affine(21, 15))
info("The following warning is normal")
e = try mxnet(model, (10, 1))
catch e e end
@test isa(e, DataFlow.Interpreter.Exception)
@test e.trace[1].func == Symbol("Flux.Affine")
@test e.trace[2].func == :TLP
end
end