{"id":27883104,"url":"https://github.com/simulacrum6/sgumlp","last_synced_at":"2026-04-15T07:33:45.605Z","repository":{"id":288232704,"uuid":"914470731","full_name":"simulacrum6/sgumlp","owner":"simulacrum6","description":"Pytorch implementation of the SGU-MLP Architecture (mostly) as described in the paper \"Spatial Gated Multi-Layer Perceptron for Land Use and Land Cover Mapping\".","archived":false,"fork":false,"pushed_at":"2025-04-16T08:45:34.000Z","size":720,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-05T10:55:43.621Z","etag":null,"topics":["computer-vision","geospatial-analysis","image-processing","image-recognition","machine-learning-algorithms","neural-networks","python-package","pytorch","pytorch-implementation","pytorch-lightning","remote-sensing"],"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/simulacrum6.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-01-09T16:56:14.000Z","updated_at":"2025-04-16T08:45:37.000Z","dependencies_parsed_at":"2025-04-16T10:50:54.675Z","dependency_job_id":"b54e703b-aa4d-455f-9b8f-cebfdf7bfdab","html_url":"https://github.com/simulacrum6/sgumlp","commit_stats":null,"previous_names":["simulacrum6/sgumlp"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/simulacrum6/sgumlp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simulacrum6%2Fsgumlp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simulacrum6%2Fsgumlp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simulacrum6%2Fsgumlp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simulacrum6%2Fsgumlp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simulacrum6","download_url":"https://codeload.github.com/simulacrum6/sgumlp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simulacrum6%2Fsgumlp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31831842,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T07:17:56.427Z","status":"ssl_error","status_checked_at":"2026-04-15T07:17:30.007Z","response_time":63,"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":["computer-vision","geospatial-analysis","image-processing","image-recognition","machine-learning-algorithms","neural-networks","python-package","pytorch","pytorch-implementation","pytorch-lightning","remote-sensing"],"created_at":"2025-05-05T06:12:05.620Z","updated_at":"2026-04-15T07:33:45.551Z","avatar_url":"https://github.com/simulacrum6.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SGU-MLP: Pytorch Impelementation of the Spatial Gated Multilayer Perceptron\n[![DOI](https://zenodo.org/badge/914470731.svg)](https://doi.org/10.5281/zenodo.15227846)\n\nPytorch implementation of the SGU-MLP Architecture from the paper \"Spatial Gated Multi-Layer Perceptron for Land Use\". \nThe implementation follows the [implementation of the original authors](https://github.com/aj1365/SGUMLP/blob/main/SGUMLP.ipynb). It differs from the architecture described in the [paper published on GitHub](https://github.com/aj1365/SGUMLP/blob/main/Spatial_Gated_Multi-Layer_Perceptron_for_Land_Use_and_Land_Cover_Mapping.pdf) in the following aspects: \n\n- Input patches and DWC Block outputs are combined using a residual connection.\n- Patches are embedded using a Convolutional Layer (by default, the `embedding_kernel_size` is set to 1 to achieve per pixel projections).\n- Input patches can be overlapping (this is only relevant for data preprocessing, not for general model usage).\n\nAdditionally, this implementation makes the initial residual weights configurable and learnable. \n\nAn implementation of [MLP Mixer](https://arxiv.org/abs/2105.01601) with optional usage of [Spatial Gated Units](https://arxiv.org/abs/2105.08050) in the MLP Blocks is also included. See `src/sgu_mlp/models.py` for details. \n\n### Basic Usage\n\n````python\nfrom sgu_mlp import SGUMLPMixer\nimport torch\n\nheight = width = 64\nnum_patches = height * width\nchannels = 3\npatch_size = 11\n\ninput_dimensions = (patch_size, patch_size, channels)\npatches = torch.randn(num_patches, *input_dimensions)\n\n# feature extractor\nsgu = SGUMLPMixer(\n    input_dimensions=input_dimensions,\n    token_features=32,\n    mixer_features_channel=64,\n    mixer_features_sequence=96,\n)\nout = sgu(patches)\n\n# (num_patches, patch_size**2, channels)\nprint(out.shape) \n\n# classifier\nnum_classes = 8\nsgu_clf = SGUMLPMixer(\n    input_dimensions=input_dimensions,      \n    token_features=32,                      \n    mixer_features_channel=64,              \n    mixer_features_sequence=96,\n    num_classes=num_classes\n)\nout = sgu_clf(patches)\n\n# (num_patches, num_classes)\nprint(out.shape)\n````\n\n### Installation\n\nIf you just want to use SGU-MLP Architecture:\n````bash\npip install sgu-mlp\n````\n\n````bash\npip install git+https://github.com/simulacrum6/sgu-mlp.git\n````\n\n\nIf you want to run the experiments as well, add the `[experiments]` extras:\n````bash\npip install \"sgu-mlp[experiments]\"\n````\n\n````bash\npip install \"git+https://github.com/simulacrum6/sgu-mlp.git#egg=sgu-mlp[experiments]\"\n````\n\n### Running Experiments\n\nTo run the replication experiment, first download the benchmark datasets. \nYou can download them from [gDrive](https://drive.usercontent.google.com/download?id=1dLJJrNJpQoQeDHybs37iGxmrSU6aP2xv\u0026export=download) or run\n\n````bash\npython3 -m experiments.run download --out_dir='/path/to/data/dir'\n````\n\nTo run the replication experiment:\n````bash\npython3 -m experiments.run experiment replication\n````\nPer default, it is assumed, that you run the script from the root of this repository (``--root_dir='data/config')``.\n\nTo run a custom experiment:\n````bash\npython3 -m experiments.run run \u003cexperiment_type\u003e \u003ccfg_path\u003e\n````\n**Arguments**\n- `\u003cexperiment_type`: \"cv\" or \"ood\".\n- `\u003ccfg_path\u003e`: path to the config file for the experiment.\n\nSee `data/config` for examples. Of the config format.\n\n### References\n- _[Spatial Gated Multi-Layer Perceptron for Land Use and Land Cover Mapping](https://doi.org/10.1109/LGRS.2024.3354175)_ - Jamali et al. 2024\n- _[Pay Attention to MLPs](https://dl.acm.org/doi/10.5555/3540261.3540965)_ - Liu et al. 2021\n- _[MLP-Mixer: An all-MLP Architecture for Vision](https://dl.acm.org/doi/10.5555/3540261.3542118)_ - Tolstikhin et al. 2021\n\n### Citations\n\nWhen using this software for your research, please cite the orginial article as well as this version of the software.\n\n```bibtex\n@article{10399888,\n  author={Jamali, Ali and Roy, Swalpa Kumar and Hong, Danfeng and Atkinson, Peter M. and Ghamisi, Pedram},\n  journal={IEEE Geoscience and Remote Sensing Letters}, \n  title={Spatial-Gated Multilayer Perceptron for Land Use and Land Cover Mapping}, \n  year={2024},\n  volume={21},\n  number={},\n  pages={1-5},\n  keywords={Feature extraction;Classification algorithms;Hyperspectral imaging;Data models;Transformers;Biological system modeling;Training data;Attention mechanism;image classification;spatial gating unit (SGU);vision transformers (ViTs)},\n  doi={10.1109/LGRS.2024.3354175}}\n```\n\n````bibtex\n@software{hamacher2024sgumlp,\n  title = {SGU-MLP: Pytorch Implementation of the Spatial Gated Multi-Layer Perceptron},\n  author = {Hamacher, Marius},\n  year = {2025},\n  url = {https://github.com/simulacrum6/sgu-mlp},\n  version = {0.1.1},\n  note = {Pytorch Implementation of the SGU-MLP Architecture from the paper \"Spatial Gated Multi-Layer Perceptron for Land Use and Land Cover Mapping\"},\n  doi = {10.5281/zenodo.15227847}}\n````\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimulacrum6%2Fsgumlp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimulacrum6%2Fsgumlp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimulacrum6%2Fsgumlp/lists"}