8000 Julia MNIST classification e2e test example by oubotong · Pull Request #1484 · tensorchord/envd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Julia MNIST classification e2e test example #1484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions e2e/v1/docs/julia_mnist_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package docs

import (
"strconv"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

e2e "github.com/tensorchord/envd/e2e/v1"
)

var _ = Describe("julia_mnist", Ordered, func() {
exampleName := "julia_mnist"
testcase := "e2e"
e := e2e.NewExample(e2e.BuildContextDirWithName(exampleName), testcase)
BeforeAll(e.BuildImage(true))
BeforeEach(e.RunContainer())
It("execute runtime command `julia-mnist`", func() {
res, err := e.ExecRuntimeCommand("julia-mnist")
Expect(err).To(BeNil())
IsNumber := func(s string) bool {
_, err = strconv.ParseFloat(s, 64)
return err == nil
}
Expect(res).To(Satisfy(IsNumber))
})
AfterEach(e.DestroyContainer())
})
7 changes: 7 additions & 0 deletions e2e/v1/docs/testdata/julia_mnist/build.envd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# syntax=v1
def build():
base(dev=True)

install.julia()
install.julia_packages(name=["Flux", "MLDatasets"])
runtime.command(commands={"julia-mnist": "julia mnist.jl"})
43 changes: 43 additions & 0 deletions e2e/v1/docs/testdata/julia_mnist/mnist.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Flux, MLDatasets
using Flux: train!, onehotbatch

ENV["DATADEPS_ALWAYS_ACCEPT"] = "true"

# Load training data (images, labels)
< 87D4 /td> x_train, y_train = MLDatasets.MNIST(split=:train)[:]
# Load test data (images, labels)
x_test, y_test = MLDatasets.MNIST(split=:test)[:]
# Convert grayscale to float
x_train = Float32.(x_train)
# Create labels batch
y_train = Flux.onehotbatch(y_train, 0:9)

model = Chain(
Dense(784, 256, relu),
Dense(256, 64, relu),
Dense(64, 10, relu),
softmax
)

loss(x, y) = Flux.Losses.logitcrossentropy(model(x), y)

optimizer = ADAM(0.0001)

parameters = Flux.params(model)
# flatten() function converts array 28x28x60000 into 784x60000 (28*28x60000)
train_data = [(Flux.flatten(x_train), Flux.flatten(y_train))]
# Range in loop can be used smaller
for i in 1:100
Flux.train!(loss, parameters, train_data, optimizer)
end

test_data = [(Flux.flatten(x_test), y_test)]
accuracy = 0
for i in 1:length(y_test)
global accuracy
if findmax(model(test_data[1][1][:, i]))[2] - 1 == y_test[i]
accuracy = accuracy + 1
end
end

print(accuracy / length(y_test))
0