|
| 1 | +# AxonDatasets |
| 2 | + |
| 3 | +## Usage |
| 4 | + |
| 5 | +```elixir |
| 6 | +{train_images, train_labels} = AxonData.MNIST.download() |
| 7 | + |
| 8 | +{images_binary, tensor_type, shape} = train_images |
| 9 | + |
| 10 | +# Transform the data as it's fetched |
| 11 | +transform_images = fn {binary, type, shape} -> |
| 12 | + binary |
| 13 | + |> Nx.from_binary(type) |
| 14 | + |> Nx.reshape(shape) |
| 15 | + |> Nx.divide(255) |
| 16 | + |> Nx.to_batched_list(32) |
| 17 | +end |
| 18 | + |
| 19 | +{train_images, train_labels} = |
| 20 | + AxonData.MNIST.download(transform_images: transform_images) |
| 21 | + |
| 22 | +# Transform labels as well, e.g. get one-hot encoding |
| 23 | +transform_labels = fn {labels_binary, type, _shape} -> |
| 24 | + labels_binary |
| 25 | + |> Nx.from_binary(type) |
| 26 | + |> Nx.new_axis(-1) |
| 27 | + |> Nx.equal(Nx.tensor(Enum.to_list(0..9))) |
| 28 | + |> Nx.to_batched_list(32) |
| 29 | +end |
| 30 | + |
| 31 | +{images, labels} = |
| 32 | + AxonData.MNIST.download( |
| 33 | + transform_images: transform_images, |
| 34 | + transform_labels: transform_labels |
| 35 | + ) |
| 36 | + |
| 37 | +``` |
| 38 | + |
| 39 | +## Installation |
| 40 | + |
| 41 | +```elixir |
| 42 | +def deps do |
| 43 | + [ |
| 44 | + {:axon_datasets, "~> 0.1.0-dev", github: "t-rutten/axon_datasets", branch: "main"} |
| 45 | + ] |
| 46 | +end |
| 47 | +``` |
| 48 | + |
| 49 | +Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) |
| 50 | +and published on [HexDocs](https://hexdocs.pm). Once published, the docs can |
| 51 | +be found at [https://hexdocs.pm/axon_data](https://hexdocs.pm/axon_data). |
0 commit comments