nd-mlp-mixer | TensorFlow
pip install nd-mlp-mixer
Based on MLP-Mixer [1], but with variants generalized to n-dimensions.
See a basic n-dimensional mixer example in nd-examples.ipynb.
Original MLP-Mixer
To use the model as described in the paper:
from nd_mlp_mixer import MLPMixer
# S/32, from table 1
mlp_mixer = MLPMixer(num_classes=1000,
num_blocks=8,
patch_size=32,
hidden_dim=512,
tokens_mlp_dim=256,
channels_mlp_dim=2048)
Or a more reasonable size model, on MNIST:
import tensorflow as tf
from tensorflow.keras import datasets, layers
from nd_mlp_mixer import MLPMixer
# Load data
(train_images, train_labels), (test_images, test_labels) = datasets.mnist.load_data()
train_images, test_images = train_images / 255.0, test_images / 255.0
train_images, test_images = train_images.astype("float32"), test_images.astype("float32")
height, width = train_images.shape[-2:]
num_classes = 10
# Prepare the model (add channel dimension to images)
inputs = layers.Input(shape=(height, width))
h = layers.Reshape([28, 28, 1])(inputs)
mlp_mixer = MLPMixer(num_classes=10,
num_blocks=2,
patch_size=4,
hidden_dim=28,
tokens_mlp_dim=28,
channels_mlp_dim=28)(h)
model = tf.keras.Model(inputs=inputs, outputs=mlp_mixer)
print(model.summary())
# Train
model.compile(optimizer='adam',
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=['accuracy'])
history = model.fit(train_images, train_labels, batch_size=64, epochs=10,
validation_data=(test_images, test_labels), verbose=2)
[1] MLP-Mixer paper:
https://arxiv.org/abs/2105.01601
@misc{tolstikhin2021mlpmixer,
title={MLP-Mixer: An all-MLP Architecture for Vision},
author={Ilya Tolstikhin and Neil Houlsby and Alexander Kolesnikov and Lucas Beyer and Xiaohua Zhai and Thomas Unterthiner and Jessica Yung and Daniel Keysers and Jakob Uszkoreit and Mario Lucic and Alexey Dosovitskiy},
year={2021},
eprint={2105.01601},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
Metadata
Release files for nd-mlp-mixer 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| nd_mlp_mixer-0.1.1.tar.gz | 9.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| nd_mlp_mixer-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.0 kB
Release files / nd_mlp_mixer-0.1.1.tar.gz
| Download URL | nd_mlp_mixer-0.1.1.tar.gz |
|---|---|
| Size | 9.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
967ab51ed433183bcfa31542f70b31a9ab8e86204acd074640762e0d56f0fdf9
|
|
BLAKE2b-256 checksum How to use checksums |
bf5e8e6416c1e0ea03d0155904cb2e6223c3fdb3924467f5db4e1acfd1205133
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.6.0.post20210108 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
|
Release files / nd_mlp_mixer-0.1.1-py3-none-any.whl
| Download URL | nd_mlp_mixer-0.1.1-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8fd96a2397c1b5a89ba8067223a4e704ec77b83cda7501e39742a691dcbbb8fb
|
|
BLAKE2b-256 checksum How to use checksums |
1b51a843d6b3d477e82aafdacd97463a759d6d16e0faa508add88a6e8ef2fe3a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.6.0.post20210108 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8
|
Security for nd-mlp-mixer 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.