-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* mldatasets new release * cleanup * neuralode example * docs * fix node test * cleanup * cleanup * julia 1.6 compat * more tests * cleanup
- Loading branch information
1 parent
eb43bc9
commit 57d84ef
Showing
16 changed files
with
217 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
# Datasets | ||
|
||
GraphNeuralNetworks.jl doesn't come with its own datasets, but leverages those available in the Julia (and non-Julia) ecosystem. In particular, the [examples in the GraphNeuralNetworks.jl repository](https://github.com/CarloLucibello/GraphNeuralNetworks.jl/tree/master/examples) make use of the [MLDatasets.jl](https://github.com/JuliaML/MLDatasets.jl) package. There you will find common graph datasets such as Cora, PubMed, and Citeseer. | ||
Also MLDatasets gives access to the [TUDataset](https://chrsmrrs.github.io/datasets/docs/datasets/) repository and its numerous datasets. | ||
GraphNeuralNetworks.jl doesn't come with its own datasets, but leverages those available in the Julia (and non-Julia) ecosystem. In particular, the [examples in the GraphNeuralNetworks.jl repository](https://github.com/CarloLucibello/GraphNeuralNetworks.jl/tree/master/examples) make use of the [MLDatasets.jl](https://github.com/JuliaML/MLDatasets.jl) package. There you will find common graph datasets such as Cora, PubMed, Citeseer, TUDataset and [many others](https://juliaml.github.io/MLDatasets.jl/dev/datasets/graphs/). | ||
|
||
GraphNeuralNetworks.jl provides the [`mldatasets2gnngraph`](@ref) method for interfacing with MLDatasets.jl. | ||
|
||
```@docs | ||
mldatasets2gnngraph | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Load the packages | ||
using GraphNeuralNetworks, DiffEqFlux, DifferentialEquations | ||
using Flux: onehotbatch, onecold | ||
using Flux.Losses: logitcrossentropy | ||
using Flux | ||
using Statistics: mean | ||
using MLDatasets | ||
using CUDA | ||
# CUDA.allowscalar(false) # Some scalar indexing is still done by DiffEqFlux | ||
|
||
# device = cpu # `gpu` not working yet | ||
device = CUDA.functional() ? gpu : cpu | ||
|
||
# LOAD DATA | ||
X, y = MNIST(:train)[:] | ||
y = onehotbatch(y, 0:9) | ||
|
||
|
||
# Define the Neural GDE | ||
diffeqsol_to_array(x) = reshape(device(x), size(x)[1:2]) | ||
|
||
nin, nhidden, nout = 28*28, 100, 10 | ||
epochs = 10 | ||
|
||
node_chain = Chain(Dense(nhidden => nhidden, tanh), | ||
Dense(nhidden => nhidden)) |> device | ||
|
||
node = NeuralODE(node_chain, | ||
(0.f0, 1.f0), Tsit5(), save_everystep=false, | ||
reltol=1e-3, abstol=1e-3, save_start=false) |> device | ||
|
||
model = Chain(Flux.flatten, | ||
Dense(nin => nhidden, relu), | ||
node, | ||
diffeqsol_to_array, | ||
Dense(nhidden, nout)) |> device | ||
|
||
# # Training | ||
# ## Model Parameters | ||
ps = Flux.params(model); | ||
|
||
# ## Optimizer | ||
opt = ADAM(0.01) | ||
|
||
function eval_loss_accuracy(X, y) | ||
ŷ = model(X) | ||
l = logitcrossentropy(ŷ, y) | ||
acc = mean(onecold(ŷ) .== onecold(y)) | ||
return (loss = round(l, digits=4), acc = round(acc*100, digits=2)) | ||
end | ||
|
||
# ## Training Loop | ||
for epoch in 1:epochs | ||
gs = gradient(ps) do | ||
ŷ = model(X) | ||
logitcrossentropy(ŷ, y) | ||
end | ||
Flux.Optimise.update!(opt, ps, gs) | ||
@show eval_loss_accuracy(X, y) | ||
end |
File renamed without changes.
Oops, something went wrong.