{"id":13578357,"url":"https://github.com/leondgarse/keras_mlp","last_synced_at":"2026-03-05T18:38:19.391Z","repository":{"id":51343566,"uuid":"367288914","full_name":"leondgarse/keras_mlp","owner":"leondgarse","description":"Keras implementation of mlp-mixer, ResMLP, gmlp. imagenet/imagenet21k weights reloaded.","archived":false,"fork":false,"pushed_at":"2021-12-14T11:06:48.000Z","size":58,"stargazers_count":7,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-06T10:11:58.663Z","etag":null,"topics":["gmlp","keras","mlp","mlp-mixer","resmlp","tensorflow","tensorflow2","tf","tf2"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leondgarse.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-14T07:48:06.000Z","updated_at":"2023-11-12T12:10:01.000Z","dependencies_parsed_at":"2022-09-24T21:20:40.812Z","dependency_job_id":null,"html_url":"https://github.com/leondgarse/keras_mlp","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/leondgarse/keras_mlp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leondgarse%2Fkeras_mlp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leondgarse%2Fkeras_mlp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leondgarse%2Fkeras_mlp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leondgarse%2Fkeras_mlp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leondgarse","download_url":"https://codeload.github.com/leondgarse/keras_mlp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leondgarse%2Fkeras_mlp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30143177,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T16:58:46.102Z","status":"ssl_error","status_checked_at":"2026-03-05T16:58:45.706Z","response_time":93,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gmlp","keras","mlp","mlp-mixer","resmlp","tensorflow","tensorflow2","tf","tf2"],"created_at":"2024-08-01T15:01:29.753Z","updated_at":"2026-03-05T18:38:19.344Z","avatar_url":"https://github.com/leondgarse.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Keras_mlp\n- **Project Merged into [Github leondgarse/keras_cv_attention_models/mlp_family](https://github.com/leondgarse/keras_cv_attention_models/tree/main/keras_cv_attention_models/mlp_family).**\n\u003c!-- TOC depthFrom:1 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 --\u003e\n\n- [Keras_mlp](#kerasmlp)\n  - [Usage](#usage)\n  - [MLP mixer](#mlp-mixer)\n  - [ResMLP](#resmlp)\n  - [GMLP](#gmlp)\n\n\u003c!-- /TOC --\u003e\n***\n\n## Usage\n  - This repo can be installed as a pip package.\n    ```sh\n    pip install -U git+https://github.com/leondgarse/keras_mlp\n    ```\n    or just `git clone` it.\n    ```sh\n    git clone https://github.com/leondgarse/keras_mlp.git\n    cd keras_mlp \u0026\u0026 pip install .\n    ```\n  - **Basic usage**\n    ```py\n    import keras_mlp\n    # Will download and load `imagenet` pretrained weights.\n    # Model weight is loaded with `by_name=True, skip_mismatch=True`.\n    mm = keras_mlp.MLPMixerB16(num_classes=1000, pretrained=\"imagenet\")\n\n    # Run prediction\n    import tensorflow as tf\n    from tensorflow import keras\n    from skimage.data import chelsea # Chelsea the cat\n    imm = keras.applications.imagenet_utils.preprocess_input(chelsea(), mode='tf') # model=\"tf\" or \"torch\"\n    pred = mm(tf.expand_dims(tf.image.resize(imm, mm.input_shape[1:3]), 0)).numpy()\n    print(keras.applications.imagenet_utils.decode_predictions(pred)[0])\n    # [('n02124075', 'Egyptian_cat', 0.9568315), ('n02123045', 'tabby', 0.017994137), ...]\n    ```\n    For `\"imagenet21k\"` pre-trained models, actual `num_classes` is `21843`.\n  - **Exclude model top layers** by set `num_classes=0`.\n    ```py\n    import keras_mlp\n    mm = keras_mlp.ResMLP_B24(num_classes=0, pretrained=\"imagenet22k\")\n    print(mm.output_shape)\n    # (None, 784, 768)\n\n    mm.save('resmlp_b24_imagenet22k-notop.h5')\n    ```\n## MLP mixer\n  - [PDF 2105.01601 MLP-Mixer: An all-MLP Architecture for Vision](https://arxiv.org/pdf/2105.01601.pdf).\n  - [Github google-research/vision_transformer](https://github.com/google-research/vision_transformer#available-mixer-models).\n  - **Models** `Top1 Acc` is `Pre-trained on JFT-300M` model accuray on `ImageNet 1K` from paper.\n    | Model       | Params | Top1 Acc | ImageNet | Imagenet21k | ImageNet SAM |\n    | ----------- | ------ | -------- | --------------- | ------------------ | ------------------- |\n    | MLPMixerS32 | 19.1M  | 68.70    |                 |                    |                     |\n    | MLPMixerS16 | 18.5M  | 73.83    |                 |                    |                     |\n    | MLPMixerB32 | 60.3M  | 75.53    |                 |                    | [b32_imagenet_sam.h5](https://github.com/leondgarse/keras_mlp/releases/download/mlp_mixer/mlp_mixer_b32_imagenet_sam.h5) |\n    | MLPMixerB16 | 59.9M  | 80.00    | [b16_imagenet.h5](https://github.com/leondgarse/keras_mlp/releases/download/mlp_mixer/mlp_mixer_b16_imagenet.h5) | [b16_imagenet21k.h5](https://github.com/leondgarse/keras_mlp/releases/download/mlp_mixer/mlp_mixer_b16_imagenet21k.h5) | [b16_imagenet_sam.h5](https://github.com/leondgarse/keras_mlp/releases/download/mlp_mixer/mlp_mixer_b16_imagenet_sam.h5) |\n    | MLPMixerL32 | 206.9M | 80.67    |  |  |                     |\n    | MLPMixerL16 | 208.2M | 84.82    | [l16_imagenet.h5](https://github.com/leondgarse/keras_mlp/releases/download/mlp_mixer/mlp_mixer_l16_imagenet.h5) | [l16_imagenet21k.h5](https://github.com/leondgarse/keras_mlp/releases/download/mlp_mixer/mlp_mixer_l16_imagenet21k.h5) |                     |\n    | - input 448 | 208.2M | 86.78    |                 |                    |                     |\n    | MLPMixerH14 | 432.3M | 86.32    |                 |                    |                     |\n    | - input 448 | 432.3M | 87.94    |                 |                    |                     |\n\n    | Specification        | S/32  | S/16  | B/32  | B/16  | L/32  | L/16  | H/14  |\n    | -------------------- | ----- | ----- | ----- | ----- | ----- | ----- | ----- |\n    | Number of layers     | 8     | 8     | 12    | 12    | 24    | 24    | 32    |\n    | Patch resolution P×P | 32×32 | 16×16 | 32×32 | 16×16 | 32×32 | 16×16 | 14×14 |\n    | Hidden size C        | 512   | 512   | 768   | 768   | 1024  | 1024  | 1280  |\n    | Sequence length S    | 49    | 196   | 49    | 196   | 49    | 196   | 256   |\n    | MLP dimension DC     | 2048  | 2048  | 3072  | 3072  | 4096  | 4096  | 5120  |\n    | MLP dimension DS     | 256   | 256   | 384   | 384   | 512   | 512   | 640   |\n  - Parameter `pretrained` is added in value `[None, \"imagenet\", \"imagenet21k\", \"imagenet_sam\"]`. Default is `imagenet`.\n  - **Pre-training details**\n    - We pre-train all models using Adam with β1 = 0.9, β2 = 0.999, and batch size 4 096, using weight decay, and gradient clipping at global norm 1.\n    - We use a linear learning rate warmup of 10k steps and linear decay.\n    - We pre-train all models at resolution 224.\n    - For JFT-300M, we pre-process images by applying the cropping technique from Szegedy et al. [44] in addition to random horizontal flipping.\n    - For ImageNet and ImageNet-21k, we employ additional data augmentation and regularization techniques.\n    - In particular, we use RandAugment [12], mixup [56], dropout [42], and stochastic depth [19].\n    - This set of techniques was inspired by the timm library [52] and Touvron et al. [46].\n    - More details on these hyperparameters are provided in Supplementary B.\n## ResMLP\n  - [PDF 2105.03404 ResMLP: Feedforward networks for image classification with data-efficient training](https://arxiv.org/pdf/2105.03404.pdf)\n  - [Github facebookresearch/deit](https://github.com/facebookresearch/deit)\n  - **Models** reloaded `imagenet` weights are the `distilled` version from official.\n    | Model      | Params | Image resolution | Top1 Acc | ImageNet |\n    | ---------- | ------ | ---------------- | -------- | -------- |\n    | ResMLP12   | 15M    | 224              | 77.8     | [resmlp12_imagenet.h5](https://github.com/leondgarse/keras_mlp/releases/download/resmlp/resmlp12_imagenet.h5) |\n    | ResMLP24   | 30M    | 224              | 80.8     | [resmlp24_imagenet.h5](https://github.com/leondgarse/keras_mlp/releases/download/resmlp/resmlp24_imagenet.h5) |\n    | ResMLP36   | 116M   | 224              | 81.1     | [resmlp36_imagenet.h5](https://github.com/leondgarse/keras_mlp/releases/download/resmlp/resmlp36_imagenet.h5) |\n    | ResMLP_B24 | 129M   | 224              | 83.6     | [resmlp_b24_imagenet.h5](https://github.com/leondgarse/keras_mlp/releases/download/resmlp/resmlp_b24_imagenet.h5) |\n    | - imagenet22k | 129M   | 224              | 84.4     | [resmlp_b24_imagenet22k.h5](https://github.com/leondgarse/keras_mlp/releases/download/resmlp/resmlp_b24_imagenet22k.h5) |\n\n  - Parameter `pretrained` is added in value `[None, \"imagenet\", \"imagenet22k\"]`, where `imagenet22k` means pre-trained on `imagenet21k` and fine-tuned on `imagenet`. Default is `imagenet`.\n## GMLP\n  - [PDF 2105.08050 Pay Attention to MLPs](https://arxiv.org/pdf/2105.08050.pdf).\n  - Model weights reloaded from [Github timm/models/mlp_mixer](https://github.com/rwightman/pytorch-image-models/blob/master/timm/models/mlp_mixer.py).\n  - **Models**\n    | Model      | Params | Image resolution | Top1 Acc | ImageNet |\n    | ---------- | ------ | ---------------- | -------- | -------- |\n    | GMLPTiny16 | 6M     | 224              | 72.3     |          |\n    | GMLPS16    | 20M    | 224              | 79.6     | [gmlp_s16_imagenet.h5](https://github.com/leondgarse/keras_mlp/releases/download/gmlp/gmlp_s16_imagenet.h5) |\n    | GMLPB16    | 73M    | 224              | 81.6     |          |\n\n  - Parameter `pretrained` is added in value `[None, \"imagenet\"]`. Default is `imagenet`.\n***\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleondgarse%2Fkeras_mlp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleondgarse%2Fkeras_mlp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleondgarse%2Fkeras_mlp/lists"}