Skip to content
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

Fix Fashion MNIST autoencoder example #439

Merged
merged 6 commits into from
Jan 16, 2023
Merged
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
19 changes: 9 additions & 10 deletions examples/generative/fashionmnist_autoencoder.exs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
Mix.install([
{:axon, "~> 0.1.0"},
{:exla, "~> 0.2.2"},
{:nx, "~> 0.2.1"},
{:scidata, "~> 0.1.6"}
{:axon, "~> 0.3.0"},
{:exla, "~> 0.4.1"},
{:nx, "~> 0.4.1"},
{:scidata, "~> 0.1.9"}
])

# Configure default platform with accelerator precedence as tpu > cuda > rocm > host
EXLA.set_as_nx_default([:tpu, :cuda, :rocm, :host])

defmodule Fashionmist do
defmodule FashionMNIST do
require Axon
alias Axon.Loop.State

defmodule Autoencoder do
defp encoder(x, latent_dim) do
Expand All @@ -22,7 +21,7 @@ defmodule Fashionmist do
defp decoder(x) do
x
|> Axon.dense(784, activation: :sigmoid)
|> Axon.reshape({1, 28, 28})
|> Axon.reshape({:batch, 1, 28, 28})
end

def build_model(input_shape, latent_dim) do
Expand All @@ -37,7 +36,7 @@ defmodule Fashionmist do
|> Nx.from_binary(type)
|> Nx.reshape({elem(shape, 0), 1, 28, 28})
|> Nx.divide(255.0)
|> Nx.to_batched_list(32)
|> Nx.to_batched(32)
end

defp train_model(model, train_images, epochs) do
Expand All @@ -58,7 +57,7 @@ defmodule Fashionmist do

sample_image =
train_images
|> hd()
|> Enum.fetch!(0)
|> Nx.slice_along_axis(0, 1)
|> Nx.reshape({1, 1, 28, 28})

Expand All @@ -71,4 +70,4 @@ defmodule Fashionmist do
end
end

Fashionmist.run()
FashionMNIST.run()